|
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.ModelConstants.GENERATION_SUFFIX; |
26 | 27 |
|
@@ -1157,4 +1158,41 @@ public void validateConverters(Element element, IsValid valid) { |
1157 | 1158 | } |
1158 | 1159 |
|
1159 | 1160 | } |
| 1161 | + |
| 1162 | + public void validateInterceptors(Element element, IsValid valid) { |
| 1163 | + TypeMirror clientHttpRequestInterceptorType = annotationHelper.typeElementFromQualifiedName(CLIENT_HTTP_REQUEST_INTERCEPTOR).asType(); |
| 1164 | + TypeMirror clientHttpRequestInterceptorTypeErased = annotationHelper.getTypeUtils().erasure(clientHttpRequestInterceptorType); |
| 1165 | + List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, annotationHelper.getTarget(), "interceptors"); |
| 1166 | + if(interceptors == null) { |
| 1167 | + return; |
| 1168 | + } |
| 1169 | + for (DeclaredType interceptorType : interceptors) { |
| 1170 | + TypeMirror erasedInterceptorType = annotationHelper.getTypeUtils().erasure(interceptorType); |
| 1171 | + if (annotationHelper.isSubtype(erasedInterceptorType, clientHttpRequestInterceptorTypeErased)) { |
| 1172 | + Element interceptorElement = interceptorType.asElement(); |
| 1173 | + if (interceptorElement.getKind().isClass()) { |
| 1174 | + if (!annotationHelper.isAbstract(interceptorElement)) { |
| 1175 | + List<ExecutableElement> constructors = ElementFilter.constructorsIn(interceptorElement.getEnclosedElements()); |
| 1176 | + for (ExecutableElement constructor : constructors) { |
| 1177 | + if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) { |
| 1178 | + return; |
| 1179 | + } |
| 1180 | + } |
| 1181 | + valid.invalidate(); |
| 1182 | + annotationHelper.printAnnotationError(element, "The interceptor class must have a public no argument constructor"); |
| 1183 | + } else { |
| 1184 | + valid.invalidate(); |
| 1185 | + annotationHelper.printAnnotationError(element, "The interceptor class must not be abstract"); |
| 1186 | + } |
| 1187 | + } else { |
| 1188 | + valid.invalidate(); |
| 1189 | + annotationHelper.printAnnotationError(element, "The interceptor class must be a class"); |
| 1190 | + } |
| 1191 | + } else { |
| 1192 | + valid.invalidate(); |
| 1193 | + annotationHelper.printAnnotationError(element, "The interceptor class must be a subtype of " + CLIENT_HTTP_REQUEST_INTERCEPTOR); |
| 1194 | + } |
| 1195 | + } |
| 1196 | + |
| 1197 | + } |
1160 | 1198 | } |
0 commit comments