Skip to content

Commit 97b0d47

Browse files
Fixed bad use of HttpEntity on Get method generation
1 parent 7ea746e commit 97b0d47

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

  • AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/rest

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/rest/GetProcessor.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@
1919

2020
import javax.annotation.processing.ProcessingEnvironment;
2121
import javax.lang.model.element.Element;
22+
import javax.lang.model.element.ExecutableElement;
2223

2324
import org.androidannotations.annotations.rest.Get;
25+
import org.androidannotations.helper.CanonicalNameConstants;
26+
import org.androidannotations.processing.EBeanHolder;
27+
28+
import com.sun.codemodel.JBlock;
29+
import com.sun.codemodel.JClass;
30+
import com.sun.codemodel.JExpr;
31+
import com.sun.codemodel.JExpression;
32+
import com.sun.codemodel.JInvocation;
33+
import com.sun.codemodel.JVar;
2434

2535
public class GetProcessor extends GetPostProcessor {
2636

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

52+
@Override
53+
protected JVar generateHttpEntityVar(MethodProcessorHolder methodHolder) {
54+
ExecutableElement executableElement = (ExecutableElement) methodHolder.getElement();
55+
EBeanHolder holder = methodHolder.getHolder();
56+
JClass httpEntity = holder.refClass(CanonicalNameConstants.HTTP_ENTITY);
57+
JExpression httpEntityValue;
58+
59+
JBlock body = methodHolder.getBody();
60+
JVar httpHeadersVar = generateHttpHeadersVar(holder, body, executableElement);
61+
62+
boolean hasHeaders = httpHeadersVar != null;
63+
64+
if (hasHeaders) {
65+
JInvocation newHttpEntityVarCall = JExpr._new(httpEntity.narrow(Object.class));
66+
newHttpEntityVarCall.arg(httpHeadersVar);
67+
httpEntityValue = newHttpEntityVarCall;
68+
} else {
69+
httpEntityValue = httpEntity.staticRef("EMPTY");
70+
}
71+
72+
JVar httpEntityVar;
73+
String httpEntityVarName = "requestEntity";
74+
httpEntityVar = body.decl(httpEntity.narrow(Object.class), httpEntityVarName, httpEntityValue);
75+
76+
return httpEntityVar;
77+
}
4278
}

0 commit comments

Comments
 (0)