Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;

import org.androidannotations.annotations.rest.Get;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.processing.EBeanHolder;

import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JExpression;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JVar;

public class GetProcessor extends GetPostProcessor {

Expand All @@ -39,4 +49,30 @@ public String retrieveUrlSuffix(Element element) {
return getAnnotation.value();
}

@Override
protected JVar generateHttpEntityVar(MethodProcessorHolder methodHolder) {
ExecutableElement executableElement = (ExecutableElement) methodHolder.getElement();
EBeanHolder holder = methodHolder.getHolder();
JClass httpEntity = holder.refClass(CanonicalNameConstants.HTTP_ENTITY);
JExpression httpEntityValue;

JBlock body = methodHolder.getBody();
JVar httpHeadersVar = generateHttpHeadersVar(holder, body, executableElement);

boolean hasHeaders = httpHeadersVar != null;

if (hasHeaders) {
JInvocation newHttpEntityVarCall = JExpr._new(httpEntity.narrow(Object.class));
newHttpEntityVarCall.arg(httpHeadersVar);
httpEntityValue = newHttpEntityVarCall;
} else {
httpEntityValue = httpEntity.staticRef("EMPTY");
}

JVar httpEntityVar;
String httpEntityVarName = "requestEntity";
httpEntityVar = body.decl(httpEntity.narrow(Object.class), httpEntityVarName, httpEntityValue);

return httpEntityVar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ protected void generateRestTemplateCallBlock(MethodProcessorHolder methodHolder)
method = holder.restImplementationClass.method(JMod.PUBLIC, methodHolder.getMethodReturnClass(), methodName);
}
method.annotate(Override.class);
if (expectedClass != methodReturnClass && !methodReturnClass.fullName().startsWith(CanonicalNameConstants.RESPONSE_ENTITY)) {
method.annotate(SuppressWarnings.class).param("value", "unchecked");
}

// Keep a reference on method's body
JBlock body = method.body();
Expand Down