|
22 | 22 | import java.lang.reflect.InvocationTargetException; |
23 | 23 | import java.lang.reflect.Method; |
24 | 24 | import java.util.ArrayList; |
25 | | -import java.util.Collection; |
26 | | -import java.util.HashMap; |
27 | | -import java.util.HashSet; |
28 | | -import java.util.LinkedHashMap; |
29 | | -import java.util.LinkedHashSet; |
30 | | -import java.util.LinkedList; |
31 | 25 | import java.util.List; |
32 | 26 | import java.util.Map; |
33 | | -import java.util.Set; |
34 | | -import java.util.SortedMap; |
35 | | -import java.util.SortedSet; |
36 | | -import java.util.TreeMap; |
37 | | -import java.util.TreeSet; |
38 | 27 |
|
39 | 28 | import javax.annotation.processing.ProcessingEnvironment; |
40 | 29 | import javax.lang.model.element.AnnotationMirror; |
@@ -66,40 +55,6 @@ public class AnnotationHelper { |
66 | 55 |
|
67 | 56 | public static final String DEFAULT_FIELD_NAME_VALUE = "value"; |
68 | 57 | public static final String DEFAULT_FIELD_NAME_RESNAME = "resName"; |
69 | | - private static final String PARCEL_ANNOTATION = "org.parceler.Parcel"; |
70 | | - private static final Map<String, Integer> SUPPORTED_PARCEL_TYPES = new HashMap<>(); |
71 | | - |
72 | | - static { |
73 | | - SUPPORTED_PARCEL_TYPES.put(Collection.class.getName(), 1); |
74 | | - SUPPORTED_PARCEL_TYPES.put(List.class.getName(), 1); |
75 | | - SUPPORTED_PARCEL_TYPES.put(ArrayList.class.getName(), 1); |
76 | | - SUPPORTED_PARCEL_TYPES.put(Set.class.getName(), 1); |
77 | | - SUPPORTED_PARCEL_TYPES.put(HashSet.class.getName(), 2); |
78 | | - SUPPORTED_PARCEL_TYPES.put(TreeSet.class.getName(), 2); |
79 | | - SUPPORTED_PARCEL_TYPES.put(CanonicalNameConstants.SPARSE_ARRAY, 1); |
80 | | - SUPPORTED_PARCEL_TYPES.put(Map.class.getName(), 2); |
81 | | - SUPPORTED_PARCEL_TYPES.put(HashMap.class.getName(), 2); |
82 | | - SUPPORTED_PARCEL_TYPES.put(TreeMap.class.getName(), 2); |
83 | | - SUPPORTED_PARCEL_TYPES.put(Integer.class.getName(), 0); |
84 | | - SUPPORTED_PARCEL_TYPES.put(Long.class.getName(), 0); |
85 | | - SUPPORTED_PARCEL_TYPES.put(Double.class.getName(), 0); |
86 | | - SUPPORTED_PARCEL_TYPES.put(Float.class.getName(), 0); |
87 | | - SUPPORTED_PARCEL_TYPES.put(Byte.class.getName(), 0); |
88 | | - SUPPORTED_PARCEL_TYPES.put(String.class.getName(), 0); |
89 | | - SUPPORTED_PARCEL_TYPES.put(Character.class.getName(), 0); |
90 | | - SUPPORTED_PARCEL_TYPES.put(Boolean.class.getName(), 0); |
91 | | - SUPPORTED_PARCEL_TYPES.put(byte[].class.getName(), 0); |
92 | | - SUPPORTED_PARCEL_TYPES.put(char[].class.getName(), 0); |
93 | | - SUPPORTED_PARCEL_TYPES.put(boolean[].class.getName(), 0); |
94 | | - SUPPORTED_PARCEL_TYPES.put(CanonicalNameConstants.IBINDER, 0); |
95 | | - SUPPORTED_PARCEL_TYPES.put(CanonicalNameConstants.BUNDLE, 0); |
96 | | - SUPPORTED_PARCEL_TYPES.put(CanonicalNameConstants.SPARSE_BOOLEAN_ARRAY, 0); |
97 | | - SUPPORTED_PARCEL_TYPES.put(LinkedList.class.getName(), 1); |
98 | | - SUPPORTED_PARCEL_TYPES.put(LinkedHashMap.class.getName(), 2); |
99 | | - SUPPORTED_PARCEL_TYPES.put(SortedMap.class.getName(), 2); |
100 | | - SUPPORTED_PARCEL_TYPES.put(SortedSet.class.getName(), 1); |
101 | | - SUPPORTED_PARCEL_TYPES.put(LinkedHashSet.class.getName(), 1); |
102 | | - }; |
103 | 58 |
|
104 | 59 | private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationHelper.class); |
105 | 60 |
|
@@ -140,39 +95,7 @@ public TypeElement typeElementFromQualifiedName(String qualifiedName) { |
140 | 95 | return getElementUtils().getTypeElement(qualifiedName); |
141 | 96 | } |
142 | 97 |
|
143 | | - public boolean isParcelType(TypeMirror typeMirror) { |
144 | | - return isParcelType(typeMirror, true); |
145 | | - } |
146 | | - |
147 | | - public boolean isParcelType(TypeMirror typeMirror, boolean root) { |
148 | | - if (typeMirror instanceof DeclaredType && getElementUtils().getTypeElement(PARCEL_ANNOTATION) != null) { |
149 | | - DeclaredType declaredType = (DeclaredType) typeMirror; |
150 | | - TypeElement element = (TypeElement) declaredType.asElement(); |
151 | | - |
152 | | - String name = element.getQualifiedName().toString(); |
153 | | - |
154 | | - if (isAnnotatedWith(element, PARCEL_ANNOTATION)) { |
155 | | - return true; |
156 | | - } |
157 | | - |
158 | | - if (SUPPORTED_PARCEL_TYPES.containsKey(name)) { |
159 | | - boolean genericsMatch = true; |
160 | | - |
161 | | - Integer genericsSize = SUPPORTED_PARCEL_TYPES.get(name); |
162 | | - if (genericsSize == declaredType.getTypeArguments().size() |
163 | | - && (!root || genericsSize > 0)) { |
164 | | - for (int i = 0; i < genericsSize; i++) { |
165 | | - genericsMatch &= isParcelType(declaredType.getTypeArguments().get(i), false); |
166 | | - } |
167 | | - |
168 | | - return genericsMatch; |
169 | | - } |
170 | | - } |
171 | | - } |
172 | | - return false; |
173 | | - } |
174 | | - |
175 | | - private boolean isAnnotatedWith(Element element, String qualifiedName) { |
| 98 | + public boolean isAnnotatedWith(Element element, String qualifiedName) { |
176 | 99 | for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { |
177 | 100 | if (annotationMirror.getAnnotationType().toString().equals(qualifiedName)) { |
178 | 101 | return true; |
|
0 commit comments