private void handleAnnotationMethods() { for (ExecutableElement method : ElementFilter.methodsIn(baseAnnotation.getEnclosedElements())) { elements.add(MoreElements.isAnnotationPresent(method, StringRes.class) ? modelFactory.fromStringResourceAnnotationMethod(method) : modelFactory.fromAnnotationMethod(method)); } }
@Override public boolean apply(VariableElement parameter) { return isAnnotationPresent(parameter, Provided.class); } }));
private static boolean annotatedWithAutoFactory(Element e) { return isAnnotationPresent(e, AutoFactory.class); } }
private boolean isElementSecured(Element element) { return !isAnnotationPresent(element, NoXsrfHeader.class); }
@Override public boolean apply(AnnotationMirror input) { return isAnnotationPresent(input.getAnnotationType().asElement(), annotationType); } })
private void validate(Element annotatedType, String errorMessage) { Element container = annotatedType.getEnclosingElement(); if (!MoreElements.isAnnotationPresent(container, RetroFacebook.class)) { processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, errorMessage, annotatedType); } } }
private void validate(Element annotatedType, String errorMessage) { Element container = annotatedType.getEnclosingElement(); if (!MoreElements.isAnnotationPresent(container, RetroFacebook.class)) { processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, errorMessage, annotatedType); } } }
private void validate(Element annotatedType, String errorMessage) { Element container = annotatedType.getEnclosingElement(); if (!MoreElements.isAnnotationPresent(container, AutoJson.class)) { processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, errorMessage, annotatedType); } } }
private void validate(Element annotatedType, String errorMessage) { Element container = annotatedType.getEnclosingElement(); if (!MoreElements.isAnnotationPresent(container, RetroWeibo.class)) { processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, errorMessage, annotatedType); } } }
public boolean isPresent(VariableElement element) { return isAnnotationPresent(element, getAssociatedClass()); }
public static boolean isPresent(ExecutableElement element) { for (HttpVerb annotation : HttpVerb.values()) { if (isAnnotationPresent(element, annotation.getAnnotationClass())) { return true; } } return false; }
void checkProvidedParameter(Element element) { checkArgument(isAnnotationPresent(element, Provided.class), "%s not annoated with @Provided", element); element.accept(new ElementKindVisitor6<Void, Void>() { @Override protected Void defaultAction(Element e, Void p) { throw new AssertionError("Provided can only be applied to parameters"); } @Override public Void visitVariableAsParameter(final VariableElement providedParameter, Void p) { providedParameter.getEnclosingElement().accept(new ElementKindVisitor6<Void, Void>() { @Override protected Void defaultAction(Element e, Void p) { raiseError(providedParameter, "@%s may only be applied to constructor parameters"); return null; } @Override public Void visitExecutableAsConstructor(ExecutableElement constructor, Void p) { if (!(annotatedWithAutoFactory(constructor) || annotatedWithAutoFactory(constructor.getEnclosingElement()))) { raiseError(providedParameter, "@%s may only be applied to constructors requesting an auto-factory"); } return null; } }, p); return null; } }, null); }
AndroidInjectKeyFinder(Elements elements, Messager messager) { this.elements = elements; this.messager = messager; // collect all dagger supported types Stream.of( elements.getPackageElement("dagger.android"), elements.getPackageElement("dagger.android.support")) .filter(packageElement -> packageElement != null) .flatMap(packageElement -> typesIn(packageElement.getEnclosedElements()).stream()) .filter(type -> isAnnotationPresent(type, MapKey.class)) .filter(mapKey -> mapKey.getAnnotation(MapKey.class).unwrapValue()) .flatMap(AndroidInjectKeyFinder::classForAnnotationElement) .map(key -> elements.getTypeElement(key.getCanonicalName()).asType()) .forEach(typeMirror -> daggerSupportedTypes.put(typeMirror, mapKeyValue(typeMirror, elements))); annotationsAndTypes.putAll(daggerSupportedTypes); }
public static Set<ContentType> resolveProduces(Element element, Set<ContentType> fallback) { if (isAnnotationPresent(element, Produces.class)) { Produces produces = element.getAnnotation(Produces.class); if (produces.value().length > 0) { return resolveContentTypes(produces.value(), fallback); } } return fallback; }
public static Set<ContentType> resolveConsumes(Element element, Set<ContentType> fallback) { if (isAnnotationPresent(element, Consumes.class)) { Consumes consumes = element.getAnnotation(Consumes.class); if (consumes.value().length > 0) { return resolveContentTypes(consumes.value(), fallback); } } return fallback; }
private void warnIfMultipleAnnotations() { int count = 0; for (Class<? extends Annotation> classy : SUPPORTED_ANNOTATIONS) { if (isAnnotationPresent(element, classy)) { ++count; } } if (count > 1) { logger.warning().context(element) .log("Multiple proxy annotation detected. Review and make sure only one is present."); } }
if (isAnnotationPresent(annotatedType, RetroFacebook.Builder.class)) { validate( annotatedType, if (isAnnotationPresent(annotatedMethod, RetroFacebook.Validate.class)) { validate( annotatedMethod,
@Override public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) { for (Map.Entry<Class<? extends Annotation>, Element> entry : elementsByAnnotation.entries()) { AnnotationMirror annotation = getAnnotationMirror(entry.getValue(), AndroidInjectorKeyRegistry.class).get(); for (TypeMirror mapKey : getAnnotationValue(annotation, "keys").accept(new Util.AllTypesVisitor(), null)) { if (daggerSupportedTypes.containsKey(mapKey)) { messager.printMessage(Diagnostic.Kind.ERROR, String.format("%s is automatically supported", mapKey)); } if (isAnnotationPresent(MoreTypes.asElement(mapKey), MapKey.class)) { TypeMirror mapKeyValue = mapKeyValue(mapKey, elements); annotationsAndTypes.put(mapKey, mapKeyValue); } else { messager.printMessage(Diagnostic.Kind.ERROR, String.format("%s is not a @MapKey", mapKey), entry.getValue()); } } } return ImmutableSet.of(); }
public HttpVerb resolve(ExecutableElement element) { int annotationsCount = 0; HttpVerb verb = null; for (HttpVerb annotation : HttpVerb.values()) { if (isAnnotationPresent(element, annotation.getAnnotationClass())) { annotationsCount += 1; verb = annotation; } } logPotentialErrors(element, annotationsCount); return verb; }
public Optional<String> resolve(VariableElement element) { Optional<String> dateFormat = Optional.absent(); if (isAnnotationPresent(element, DateFormat.class)) { if (element.asType().accept(DATE_TYPE_VALIDATION_VISITOR, null)) { dateFormat = Optional.of(element.getAnnotation(DateFormat.class).value()); } else { logger.warning().context(element) .log(DATE_FORMAT_NOT_DATE, parentName(element), element.getSimpleName()); } } return dateFormat; } }