|
16 | 16 |
|
17 | 17 | package dagger.hilt.processor.internal.root;
|
18 | 18 |
|
| 19 | +import androidx.room.compiler.processing.XAnnotation; |
19 | 20 | import androidx.room.compiler.processing.XElement;
|
20 | 21 | import androidx.room.compiler.processing.XProcessingEnv;
|
21 | 22 | import androidx.room.compiler.processing.XTypeElement;
|
|
25 | 26 | import dagger.hilt.processor.internal.ProcessorErrors;
|
26 | 27 | import dagger.hilt.processor.internal.Processors;
|
27 | 28 | import dagger.internal.codegen.xprocessing.XElements;
|
| 29 | +import java.util.Optional; |
| 30 | +import java.util.Set; |
28 | 31 | import javax.lang.model.element.TypeElement;
|
29 | 32 |
|
30 | 33 | /** Metadata class for {@code InternalTestRoot} annotated classes. */
|
@@ -57,6 +60,28 @@ ClassName testInjectorName() {
|
57 | 60 | return Processors.append(Processors.getEnclosedClassName(testName()), "_GeneratedInjector");
|
58 | 61 | }
|
59 | 62 |
|
| 63 | + /** |
| 64 | + * Returns either the SkipTestInjection annotation or the first annotation that was annotated |
| 65 | + * with SkipTestInjection, if present. |
| 66 | + */ |
| 67 | + Optional<XAnnotation> skipTestInjectionAnnotation() { |
| 68 | + XAnnotation skipTestAnnotation = testElement().getAnnotation(ClassNames.SKIP_TEST_INJECTION); |
| 69 | + if (skipTestAnnotation != null) { |
| 70 | + return Optional.of(skipTestAnnotation); |
| 71 | + } |
| 72 | + |
| 73 | + Set<XAnnotation> annotatedAnnotations = testElement().getAnnotationsAnnotatedWith( |
| 74 | + ClassNames.SKIP_TEST_INJECTION); |
| 75 | + if (!annotatedAnnotations.isEmpty()) { |
| 76 | + // Just return the first annotation that skips test injection if there are multiple since |
| 77 | + // at this point it doesn't really matter and the specific annotation is only really useful |
| 78 | + // for communicating back to the user. |
| 79 | + return Optional.of(annotatedAnnotations.iterator().next()); |
| 80 | + } |
| 81 | + |
| 82 | + return Optional.empty(); |
| 83 | + } |
| 84 | + |
60 | 85 | static TestRootMetadata of(XProcessingEnv env, XElement element) {
|
61 | 86 |
|
62 | 87 | XTypeElement testElement = XElements.asTypeElement(element);
|
|
0 commit comments