/** * Returns the value named {@code name} from {@code annotation}. * * @throws IllegalArgumentException unless that member represents a single type */ static TypeMirror getTypeValue(AnnotationMirror annotation, String name) { return MoreAnnotationValues.asType(getAnnotationValue(annotation, name)); }
/** * If {@code mapKey} is {@link AndroidInjectionKey}, returns the string value for the map key. If * it's {@link dagger.multibindings.ClassKey}, returns the fully-qualified class name of the * annotation value. Otherwise returns {@link Optional#empty()}. */ static Optional<String> injectedTypeFromMapKey(AnnotationMirror mapKey) { Object mapKeyClass = getAnnotationValue(mapKey, "value").getValue(); if (mapKeyClass instanceof String) { return Optional.of((String) mapKeyClass); } else if (mapKeyClass instanceof TypeMirror) { TypeElement type = MoreTypes.asTypeElement((TypeMirror) mapKeyClass); return Optional.of(type.getQualifiedName().toString()); } else { return Optional.empty(); } } }
/** * Returns the list of types that is the value named {@code name} from {@code annotationMirror}. * * @throws IllegalArgumentException unless that member represents an array of types */ static ImmutableList<TypeMirror> getTypeListValue( AnnotationMirror annotationMirror, String name) { return asAnnotationValues(getAnnotationValue(annotationMirror, name)) .stream() .map(MoreAnnotationValues::asType) .collect(toImmutableList()); } }
/** * Returns the annotation values for the modules directly installed into a component or included * in a module. * * @param annotatedType the component or module type * @param annotation the component or module annotation */ static ImmutableList<AnnotationValue> getModules( TypeElement annotatedType, AnnotationMirror annotation) { if (ComponentKind.forAnnotatedElement(annotatedType) .filter(kind -> !kind.isForModuleValidation()) .isPresent()) { return asAnnotationValues(getAnnotationValue(annotation, MODULES_ATTRIBUTE)); } if (ModuleKind.forAnnotatedElement(annotatedType).isPresent()) { return asAnnotationValues(getAnnotationValue(annotation, INCLUDES_ATTRIBUTE)); } throw new IllegalArgumentException(String.format("unsupported annotation: %s", annotation)); }
private void validateSelfCycles( TypeElement module, ValidationReport.Builder<TypeElement> builder) { AnnotationMirror moduleAnnotation = getModuleAnnotation(module).get(); getAnnotationValue(moduleAnnotation, "includes") .accept( new SimpleAnnotationValueVisitor8<Void, AnnotationValue>() { @Override public Void visitType(TypeMirror includedModule, AnnotationValue value) { if (MoreTypes.equivalence().equivalent(module.asType(), includedModule)) { Name moduleKind = moduleAnnotation.getAnnotationType().asElement().getSimpleName(); builder.addError( String.format("@%s cannot include themselves.", moduleKind), module, moduleAnnotation, value); } return null; } @Override public Void visitArray(List<? extends AnnotationValue> values, AnnotationValue p) { values.stream().forEach(value -> value.accept(this, value)); return null; } }, null); }
getAnnotationMirror(method, ContributesAndroidInjector.class).get(); for (TypeMirror module : getAnnotationValue(annotation, "modules").accept(new AllTypesVisitor(), null)) { if (isAnnotationPresent(MoreTypes.asElement(module), Module.class)) { builder.modulesBuilder().add((ClassName) TypeName.get(module));