|
19 | 19 | import static dagger.internal.codegen.MapKeyGenerator.MapKeyCreatorSpecification.unwrappedMapKeyWithAnnotationValue;
|
20 | 20 | import static dagger.internal.codegen.MapKeyGenerator.MapKeyCreatorSpecification.wrappedMapKey;
|
21 | 21 | import static dagger.internal.codegen.MapKeys.getUnwrappedMapKeyType;
|
| 22 | +import static javax.lang.model.element.ElementKind.ANNOTATION_TYPE; |
| 23 | +import static javax.lang.model.util.ElementFilter.typesIn; |
22 | 24 |
|
23 | 25 | import com.google.auto.common.BasicAnnotationProcessor;
|
24 |
| -import com.google.auto.common.MoreElements; |
25 | 26 | import com.google.auto.common.MoreTypes;
|
26 | 27 | import com.google.common.collect.ImmutableSet;
|
27 | 28 | import com.google.common.collect.SetMultimap;
|
28 | 29 | import dagger.MapKey;
|
29 |
| -import dagger.internal.codegen.MapKeyGenerator.MapKeyCreatorSpecification; |
30 | 30 | import java.lang.annotation.Annotation;
|
31 | 31 | import java.util.Set;
|
32 | 32 | import javax.annotation.processing.Messager;
|
33 | 33 | import javax.lang.model.element.Element;
|
34 |
| -import javax.lang.model.element.ElementKind; |
| 34 | +import javax.lang.model.element.TypeElement; |
35 | 35 | import javax.lang.model.type.DeclaredType;
|
36 | 36 | import javax.lang.model.util.Types;
|
37 | 37 |
|
@@ -67,33 +67,26 @@ public Set<Class<? extends Annotation>> annotations() {
|
67 | 67 | @Override
|
68 | 68 | public Set<Element> process(
|
69 | 69 | SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
|
70 |
| - for (Element element : elementsByAnnotation.get(MapKey.class)) { |
71 |
| - ValidationReport<Element> mapKeyReport = mapKeyValidator.validate(element); |
| 70 | + for (TypeElement mapKeyAnnotation : typesIn(elementsByAnnotation.get(MapKey.class))) { |
| 71 | + ValidationReport<Element> mapKeyReport = mapKeyValidator.validate(mapKeyAnnotation); |
72 | 72 | mapKeyReport.printMessagesTo(messager);
|
73 | 73 |
|
74 | 74 | if (mapKeyReport.isClean()) {
|
75 |
| - MapKey mapkey = element.getAnnotation(MapKey.class); |
| 75 | + MapKey mapkey = mapKeyAnnotation.getAnnotation(MapKey.class); |
76 | 76 | if (mapkey.unwrapValue()) {
|
77 | 77 | DeclaredType keyType =
|
78 |
| - getUnwrappedMapKeyType(MoreTypes.asDeclared(element.asType()), types); |
79 |
| - if (keyType.asElement().getKind() == ElementKind.ANNOTATION_TYPE) { |
80 |
| - writeCreatorClass( |
| 78 | + getUnwrappedMapKeyType(MoreTypes.asDeclared(mapKeyAnnotation.asType()), types); |
| 79 | + if (keyType.asElement().getKind().equals(ANNOTATION_TYPE)) { |
| 80 | + mapKeyGenerator.generate( |
81 | 81 | unwrappedMapKeyWithAnnotationValue(
|
82 |
| - MoreElements.asType(element), MoreTypes.asTypeElement(keyType))); |
| 82 | + mapKeyAnnotation, MoreTypes.asTypeElement(keyType)), |
| 83 | + messager); |
83 | 84 | }
|
84 | 85 | } else {
|
85 |
| - writeCreatorClass(wrappedMapKey(MoreElements.asType(element))); |
| 86 | + mapKeyGenerator.generate(wrappedMapKey(mapKeyAnnotation), messager); |
86 | 87 | }
|
87 | 88 | }
|
88 | 89 | }
|
89 | 90 | return ImmutableSet.of();
|
90 | 91 | }
|
91 |
| - |
92 |
| - private void writeCreatorClass(MapKeyCreatorSpecification mapKeyCreatorType) { |
93 |
| - try { |
94 |
| - mapKeyGenerator.generate(mapKeyCreatorType); |
95 |
| - } catch (SourceFileGenerationException e) { |
96 |
| - e.printMessageTo(messager); |
97 |
| - } |
98 |
| - } |
99 | 92 | }
|
0 commit comments