|
15 | 15 | */ |
16 | 16 | package org.androidannotations.holder; |
17 | 17 |
|
| 18 | +import static com.sun.codemodel.JExpr._new; |
18 | 19 | import static com.sun.codemodel.JExpr._this; |
19 | 20 | import static com.sun.codemodel.JExpr.lit; |
20 | | -import static com.sun.codemodel.JExpr.ref; |
21 | | -import static com.sun.codemodel.JExpr._new; |
22 | 21 | import static com.sun.codemodel.JMod.FINAL; |
23 | 22 | import static com.sun.codemodel.JMod.PUBLIC; |
24 | 23 | import static org.androidannotations.helper.CanonicalNameConstants.REST_TEMPLATE; |
|
30 | 29 | import javax.lang.model.element.TypeElement; |
31 | 30 | import javax.lang.model.type.TypeKind; |
32 | 31 |
|
| 32 | +import org.androidannotations.api.rest.RestErrorHandler; |
| 33 | +import org.androidannotations.helper.APTCodeModelHelper; |
| 34 | +import org.androidannotations.helper.CanonicalNameConstants; |
| 35 | +import org.androidannotations.helper.ModelConstants; |
| 36 | +import org.androidannotations.process.ProcessHolder; |
| 37 | + |
33 | 38 | import com.sun.codemodel.ClassType; |
34 | 39 | import com.sun.codemodel.JBlock; |
35 | 40 | import com.sun.codemodel.JClass; |
36 | 41 | import com.sun.codemodel.JDefinedClass; |
37 | 42 | import com.sun.codemodel.JExpr; |
| 43 | +import com.sun.codemodel.JExpression; |
38 | 44 | import com.sun.codemodel.JFieldVar; |
39 | 45 | import com.sun.codemodel.JInvocation; |
40 | 46 | import com.sun.codemodel.JMethod; |
41 | 47 | import com.sun.codemodel.JMod; |
42 | | -import org.androidannotations.api.rest.RestErrorHandler; |
43 | | -import org.androidannotations.helper.APTCodeModelHelper; |
44 | | -import org.androidannotations.helper.CanonicalNameConstants; |
45 | | -import org.androidannotations.helper.ModelConstants; |
46 | | -import org.androidannotations.process.ProcessHolder; |
| 48 | +import com.sun.codemodel.JVar; |
47 | 49 |
|
48 | 50 | public class RestHolder extends BaseGeneratedClassHolder { |
49 | 51 |
|
@@ -141,23 +143,22 @@ private void implementSetBasicAuth(List<ExecutableElement> methods) { |
141 | 143 | } |
142 | 144 |
|
143 | 145 | private void implementSetBearerAuth(List<ExecutableElement> methods) { |
144 | | - JMethod setBearerMethod = codeModelHelper.implementMethod(this, methods, "setBearerAuth", TypeKind.VOID.toString(), STRING); |
| 146 | + JMethod setBearerMethod = codeModelHelper.implementMethod(this, methods, "setBearerAuth", TypeKind.VOID.toString(), true, STRING); |
145 | 147 |
|
146 | 148 | if (setBearerMethod != null) { |
147 | | - JClass authClass = classes().HTTP_AUTHENTICATION; |
148 | | - JDefinedClass anonymousHttpAuthClass = codeModel().anonymousClass(authClass); |
149 | | - |
150 | | - JMethod getHeaderValueMethod = anonymousHttpAuthClass.method(JMod.PUBLIC, String.class, "getHeaderValue"); |
151 | | - getHeaderValueMethod.annotate(Override.class); |
152 | | - JBlock getHeaderValueMethodBody = getHeaderValueMethod.body(); |
| 149 | + JVar tokenParamVar = setBearerMethod.params().get(0); |
| 150 | + JExpression tokenExpr = lit("Bearer ").plus(tokenParamVar); |
153 | 151 |
|
154 | | - JBlock setBearerBody = setBearerMethod.body(); |
155 | | - |
156 | | - setBearerBody.decl(FINAL, refClass(String.class), "bearerHeader", lit("Bearer ").plus(setBearerMethod.params().get(0))); |
| 152 | + JClass authClass = classes().HTTP_AUTHENTICATION; |
| 153 | + JDefinedClass anonymousHttpAuthClass = codeModel().anonymousClass(authClass); |
157 | 154 |
|
158 | | - getHeaderValueMethodBody._return(ref("bearerHeader")); |
| 155 | + JMethod getHeaderValueMethod = anonymousHttpAuthClass.method(JMod.PUBLIC, String.class, "getHeaderValue"); |
| 156 | + getHeaderValueMethod.annotate(Override.class); |
| 157 | + JBlock getHeaderValueMethodBody = getHeaderValueMethod.body(); |
| 158 | + getHeaderValueMethodBody._return(tokenExpr); |
159 | 159 |
|
160 | | - setBearerBody.assign(_this().ref(getAuthenticationField()), _new(anonymousHttpAuthClass)); |
| 160 | + JBlock setBearerBody = setBearerMethod.body(); |
| 161 | + setBearerBody.assign(_this().ref(getAuthenticationField()), _new(anonymousHttpAuthClass)); |
161 | 162 | } |
162 | 163 | } |
163 | 164 |
|
|
0 commit comments