|
15 | 15 | */ |
16 | 16 | package org.androidannotations.helper; |
17 | 17 |
|
18 | | -import static java.util.Arrays.asList; |
19 | | -import static org.androidannotations.helper.AndroidConstants.LOG_DEBUG; |
20 | | -import static org.androidannotations.helper.AndroidConstants.LOG_ERROR; |
21 | | -import static org.androidannotations.helper.AndroidConstants.LOG_INFO; |
22 | | -import static org.androidannotations.helper.AndroidConstants.LOG_VERBOSE; |
23 | | -import static org.androidannotations.helper.AndroidConstants.LOG_WARN; |
24 | | -import static org.androidannotations.helper.CanonicalNameConstants.CLIENT_HTTP_REQUEST_INTERCEPTOR; |
25 | | -import static org.androidannotations.helper.CanonicalNameConstants.HTTP_MESSAGE_CONVERTER; |
26 | | -import static org.androidannotations.helper.CanonicalNameConstants.INTERNET_PERMISSION; |
27 | | -import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX; |
28 | | -import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_COMPONENT_ANNOTATIONS; |
29 | | -import static org.androidannotations.helper.ModelConstants.VALID_ENHANCED_VIEW_SUPPORT_ANNOTATIONS; |
30 | | - |
31 | | -import java.lang.annotation.Annotation; |
32 | | -import java.util.ArrayList; |
33 | | -import java.util.Arrays; |
34 | | -import java.util.Collection; |
35 | | -import java.util.HashMap; |
36 | | -import java.util.List; |
37 | | -import java.util.Map; |
38 | | -import java.util.Set; |
39 | | -import java.util.TreeSet; |
40 | | - |
41 | | -import javax.lang.model.element.AnnotationMirror; |
42 | | -import javax.lang.model.element.Element; |
43 | | -import javax.lang.model.element.ElementKind; |
44 | | -import javax.lang.model.element.ExecutableElement; |
45 | | -import javax.lang.model.element.Modifier; |
46 | | -import javax.lang.model.element.TypeElement; |
47 | | -import javax.lang.model.element.VariableElement; |
48 | | -import javax.lang.model.type.ArrayType; |
49 | | -import javax.lang.model.type.DeclaredType; |
50 | | -import javax.lang.model.type.ErrorType; |
51 | | -import javax.lang.model.type.TypeKind; |
52 | | -import javax.lang.model.type.TypeMirror; |
53 | | -import javax.lang.model.util.ElementFilter; |
54 | | -import javax.lang.model.util.Elements; |
55 | | - |
56 | | -import org.androidannotations.annotations.EActivity; |
57 | | -import org.androidannotations.annotations.EBean; |
58 | | -import org.androidannotations.annotations.EFragment; |
59 | | -import org.androidannotations.annotations.EIntentService; |
60 | | -import org.androidannotations.annotations.EService; |
61 | | -import org.androidannotations.annotations.Receiver; |
62 | | -import org.androidannotations.annotations.Trace; |
63 | | -import org.androidannotations.annotations.ViewById; |
64 | | -import org.androidannotations.annotations.rest.Delete; |
65 | | -import org.androidannotations.annotations.rest.Get; |
66 | | -import org.androidannotations.annotations.rest.Head; |
67 | | -import org.androidannotations.annotations.rest.Options; |
68 | | -import org.androidannotations.annotations.rest.Post; |
69 | | -import org.androidannotations.annotations.rest.Put; |
70 | | -import org.androidannotations.annotations.rest.Rest; |
71 | | -import org.androidannotations.annotations.sharedpreferences.DefaultBoolean; |
72 | | -import org.androidannotations.annotations.sharedpreferences.DefaultFloat; |
73 | | -import org.androidannotations.annotations.sharedpreferences.DefaultInt; |
74 | | -import org.androidannotations.annotations.sharedpreferences.DefaultLong; |
75 | | -import org.androidannotations.annotations.sharedpreferences.DefaultString; |
76 | | -import org.androidannotations.annotations.sharedpreferences.SharedPref; |
| 18 | +import org.androidannotations.annotations.*; |
| 19 | +import org.androidannotations.annotations.rest.*; |
| 20 | +import org.androidannotations.annotations.sharedpreferences.*; |
77 | 21 | import org.androidannotations.api.rest.RestClientErrorHandling; |
78 | 22 | import org.androidannotations.api.rest.RestClientHeaders; |
79 | 23 | import org.androidannotations.api.rest.RestClientRootUrl; |
|
83 | 27 | import org.androidannotations.model.AnnotationElements; |
84 | 28 | import org.androidannotations.process.IsValid; |
85 | 29 |
|
| 30 | +import javax.lang.model.element.*; |
| 31 | +import javax.lang.model.type.*; |
| 32 | +import javax.lang.model.util.ElementFilter; |
| 33 | +import javax.lang.model.util.Elements; |
| 34 | +import java.lang.annotation.Annotation; |
| 35 | +import java.util.*; |
| 36 | + |
| 37 | +import static java.util.Arrays.asList; |
| 38 | +import static org.androidannotations.helper.AndroidConstants.*; |
| 39 | +import static org.androidannotations.helper.CanonicalNameConstants.*; |
| 40 | +import static org.androidannotations.helper.ModelConstants.*; |
| 41 | + |
86 | 42 | public class ValidatorHelper { |
87 | 43 |
|
88 | 44 | private static final List<String> VALID_REST_INTERFACES = asList(RestClientHeaders.class.getName(), RestClientErrorHandling.class.getName(), RestClientRootUrl.class.getName(), RestClientSupport.class.getName()); |
@@ -1161,6 +1117,40 @@ public void hasInternetPermission(Element element, AndroidManifest androidManife |
1161 | 1117 | } |
1162 | 1118 | } |
1163 | 1119 |
|
| 1120 | + public void validateRequestFactory(Element element, IsValid valid) { |
| 1121 | + TypeMirror clientHttpRequestFactoryType = annotationHelper.typeElementFromQualifiedName(CLIENT_HTTP_REQUEST_FACTORY).asType(); |
| 1122 | + DeclaredType requestFactory = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), "requestFactory"); |
| 1123 | + if (requestFactory != null) { |
| 1124 | + if (annotationHelper.isSubtype(requestFactory, clientHttpRequestFactoryType)) { |
| 1125 | + Element requestFactoryElement = requestFactory.asElement(); |
| 1126 | + if (requestFactoryElement.getKind().isClass()) { |
| 1127 | + if (!annotationHelper.isAbstract(requestFactoryElement)) { |
| 1128 | + if (requestFactoryElement.getAnnotation(EBean.class) != null) { |
| 1129 | + return; |
| 1130 | + } |
| 1131 | + List<ExecutableElement> constructors = ElementFilter.constructorsIn(requestFactoryElement.getEnclosedElements()); |
| 1132 | + for (ExecutableElement constructor : constructors) { |
| 1133 | + if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) { |
| 1134 | + return; |
| 1135 | + } |
| 1136 | + } |
| 1137 | + valid.invalidate(); |
| 1138 | + annotationHelper.printAnnotationError(element, "The requestFactory class must have a public no argument constructor or must be annotated with @EBean"); |
| 1139 | + } else { |
| 1140 | + valid.invalidate(); |
| 1141 | + annotationHelper.printAnnotationError(element, "The requestFactory class must not be abstract"); |
| 1142 | + } |
| 1143 | + } else { |
| 1144 | + valid.invalidate(); |
| 1145 | + annotationHelper.printAnnotationError(element, "The requestFactory class must be a class"); |
| 1146 | + } |
| 1147 | + } else { |
| 1148 | + valid.invalidate(); |
| 1149 | + annotationHelper.printAnnotationError(element, "The requestFactory class must be a subtype of " + CLIENT_HTTP_REQUEST_FACTORY); |
| 1150 | + } |
| 1151 | + } |
| 1152 | + } |
| 1153 | + |
1164 | 1154 | public void hasBeforeTextChangedMethodParameters(ExecutableElement executableElement, IsValid valid) { |
1165 | 1155 | List<? extends VariableElement> parameters = executableElement.getParameters(); |
1166 | 1156 | boolean charSequenceParameterFound = false; |
|
0 commit comments