/** * Returns all of the {@link MapKey} annotations that annotate {@code bindingElement}. */ static ImmutableSet<? extends AnnotationMirror> getMapKeys(Element bindingElement) { return getAnnotatedAnnotations(bindingElement, MapKey.class); }
static ImmutableSet<? extends AnnotationMirror> getQualifiers(Element element) { return AnnotationMirrors.getAnnotatedAnnotations(element, Qualifier.class); }
private Optional<AnnotationMirror> mapKey(Binding binding) { return binding .bindingElement() .map(bindingElement -> getAnnotatedAnnotations(bindingElement, MapKey.class)) .flatMap( annotations -> annotations.isEmpty() ? Optional.empty() : Optional.of(getOnlyElement(annotations))); }
private void validateNoScopeAnnotationsOnModuleElement( TypeElement module, ModuleKind moduleKind, ValidationReport.Builder<TypeElement> report) { for (AnnotationMirror scope : getAnnotatedAnnotations(module, Scope.class)) { report.addError( String.format( "@%ss cannot be scoped. Did you mean to scope a method instead?", moduleKind.annotation().getSimpleName()), module, scope); } }
/** Returns all of the associated scopes for a source code element. */ static ImmutableSet<Scope> scopesOf(Element element) { return AnnotationMirrors.getAnnotatedAnnotations(element, javax.inject.Scope.class) .stream() .map(Scope::scope) .collect(toImmutableSet()); } }
private void validateMethod(Class<? extends Annotation> annotation, ExecutableElement method) { if (!getAnnotatedAnnotations(method, Qualifier.class).isEmpty()) { return; if (!getAnnotatedAnnotations(method, Scope.class).isEmpty()) { SuppressWarnings suppressedWarnings = method.getAnnotation(SuppressWarnings.class); if (suppressedWarnings == null .contains("dagger.android.ScopedInjectorFactory")) { AnnotationMirror mapKeyAnnotation = getOnlyElement(getAnnotatedAnnotations(method, MapKey.class)); TypeElement mapKeyValueElement = elements.getTypeElement(injectedTypeFromMapKey(mapKeyAnnotation).get());
for (AnnotationMirror scope : getAnnotatedAnnotations(method, Scope.class)) { builder.scopesBuilder().add(AnnotationSpec.get(scope)); for (AnnotationMirror qualifier : getAnnotatedAnnotations(method, Qualifier.class)) { reporter.reportError( "@ContributesAndroidInjector methods cannot have qualifiers", qualifier);