|
21 | 21 | import static org.androidannotations.helper.AndroidConstants.LOG_INFO; |
22 | 22 | import static org.androidannotations.helper.AndroidConstants.LOG_VERBOSE; |
23 | 23 | import static org.androidannotations.helper.AndroidConstants.LOG_WARN; |
| 24 | +import static org.androidannotations.helper.CanonicalNameConstants.CLIENT_HTTP_REQUEST_INTERCEPTOR; |
24 | 25 | import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER; |
25 | 26 | import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION; |
26 | 27 | import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX; |
@@ -1175,4 +1176,41 @@ public void hasInternetPermission(Element element, AndroidManifest androidManife |
1175 | 1176 | annotationHelper.printAnnotationError(element, "Your application must require the INTERNET permission."); |
1176 | 1177 | } |
1177 | 1178 | } |
| 1179 | + |
| 1180 | + public void validateInterceptors(Element element, IsValid valid) { |
| 1181 | + TypeMirror clientHttpRequestInterceptorType = annotationHelper.typeElementFromQualifiedName(CLIENT_HTTP_REQUEST_INTERCEPTOR).asType(); |
| 1182 | + TypeMirror clientHttpRequestInterceptorTypeErased = annotationHelper.getTypeUtils().erasure(clientHttpRequestInterceptorType); |
| 1183 | + List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, annotationHelper.getTarget(), "interceptors"); |
| 1184 | + if(interceptors == null) { |
| 1185 | + return; |
| 1186 | + } |
| 1187 | + for (DeclaredType interceptorType : interceptors) { |
| 1188 | + TypeMirror erasedInterceptorType = annotationHelper.getTypeUtils().erasure(interceptorType); |
| 1189 | + if (annotationHelper.isSubtype(erasedInterceptorType, clientHttpRequestInterceptorTypeErased)) { |
| 1190 | + Element interceptorElement = interceptorType.asElement(); |
| 1191 | + if (interceptorElement.getKind().isClass()) { |
| 1192 | + if (!annotationHelper.isAbstract(interceptorElement)) { |
| 1193 | + List<ExecutableElement> constructors = ElementFilter.constructorsIn(interceptorElement.getEnclosedElements()); |
| 1194 | + for (ExecutableElement constructor : constructors) { |
| 1195 | + if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) { |
| 1196 | + return; |
| 1197 | + } |
| 1198 | + } |
| 1199 | + valid.invalidate(); |
| 1200 | + annotationHelper.printAnnotationError(element, "The interceptor class must have a public no argument constructor"); |
| 1201 | + } else { |
| 1202 | + valid.invalidate(); |
| 1203 | + annotationHelper.printAnnotationError(element, "The interceptor class must not be abstract"); |
| 1204 | + } |
| 1205 | + } else { |
| 1206 | + valid.invalidate(); |
| 1207 | + annotationHelper.printAnnotationError(element, "The interceptor class must be a class"); |
| 1208 | + } |
| 1209 | + } else { |
| 1210 | + valid.invalidate(); |
| 1211 | + annotationHelper.printAnnotationError(element, "The interceptor class must be a subtype of " + CLIENT_HTTP_REQUEST_INTERCEPTOR); |
| 1212 | + } |
| 1213 | + } |
| 1214 | + } |
| 1215 | + |
1178 | 1216 | } |
0 commit comments