private static boolean hasAnyOfAnnotation(ExecutableElement input, List<String> annotations) { return input.getAnnotationMirrors().stream() .map(annotationMirror -> asType(annotationMirror.getAnnotationType().asElement())) .anyMatch(type -> typeInAnnotations(type, annotations)); }
@Override public boolean process(@Nullable Set<? extends TypeElement> annotations, @NonNull RoundEnvironment roundEnv) { try { final ArrayList<? extends Element> annotatedElements = new ArrayList<>(roundEnv.getElementsAnnotatedWith(Configuration.class)); if (!annotatedElements.isEmpty()) { for (final Element e : annotatedElements) { if (e.getKind() == ElementKind.ANNOTATION_TYPE) { new ClassCreator(MoreElements.asType(e), e.getAnnotation(Configuration.class), processingEnv).createClasses(); } else { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("%s is only supported on %s", Configuration.class.getName(), ElementKind.ANNOTATION_TYPE.name()), e); } } } } catch (Exception e) { e.printStackTrace(); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to generate acra classes"); } return true; }
roundEnv.getElementsAnnotatedWith(MoreElements.asType(customAnnotation)));
private TypeElement superclass(TypeElement type) { TypeMirror sup = type.getSuperclass(); if (sup.getKind() == TypeKind.DECLARED) { return MoreElements.asType(typeUtils.asElement(sup)); } else { return null; } }
public static String qualifiedMethodName(ExecutableElement element) { Name className = asType(element.getEnclosingElement()).getQualifiedName(); Name methodName = element.getSimpleName(); return className + "#" + methodName; }
@Override public Boolean visitDeclared(DeclaredType type, Void v) { return asType(type.asElement()).getQualifiedName().contentEquals(Date.class.getCanonicalName()); } };
@Override public Boolean visitDeclared(DeclaredType type, Void ignored) { TypeElement typeElement; try { typeElement = MoreElements.asType(type.asElement()); } catch (IllegalArgumentException iae) { throw new IllegalArgumentException(type + " does not represent a class or interface."); } return typeElement.getQualifiedName().contentEquals(clazz.getCanonicalName()); } }
private ImmutableList<TypeElement> superinterfaces(TypeElement type) { ImmutableList.Builder<TypeElement> types = ImmutableList.builder(); for (TypeMirror sup : type.getInterfaces()) { types.add(MoreElements.asType(typeUtils.asElement(sup))); } return types.build(); }
private static boolean isNullable(AnnotationMirror annotation) { TypeElement annotationType = MoreElements.asType(annotation.getAnnotationType().asElement()); return annotationType.getSimpleName().contentEquals("Nullable") || annotationType .getQualifiedName() .toString() // For NullableDecl and NullableType compatibility annotations .startsWith("org.checkerframework.checker.nullness.compatqual.Nullable"); }
private TypeElement asTypeElement(TypeMirror typeMirror) { DeclaredType declaredType = MoreTypes.asDeclared(typeMirror); Element element = declaredType.asElement(); return MoreElements.asType(element); } }
@Override public Void visitDeclared(DeclaredType t, ImmutableSet.Builder<TypeElement> p) { p.add(MoreElements.asType(t.asElement())); for (TypeMirror typeArgument : t.getTypeArguments()) { typeArgument.accept(this, p); } return null; }
public static TypeElement asTypeElement(TypeMirror mirror) { return MoreElements.asType(asElement(mirror)); }
private int indexInParent() { TypeElement parentTypeElement = asType(element.getEnclosingElement()); List<ExecutableElement> methods = methodsIn(utils.getElements().getAllMembers(parentTypeElement)); return methods.indexOf(element); }
private void writeBundlesToMetaInf(Set<? extends Element> bundles) { for (Element bundle : bundles) { String bundleName = bundle.getAnnotation(ProviderBundle.class).value(); String type = asType(bundle).getQualifiedName().toString(); metaInfWriter.addBundle(bundleName, type); } } }
private static boolean hasAnyOfAnnotation(ExecutableElement input, List<String> annotations) { return input.getAnnotationMirrors().stream() .map(annotationMirror -> asType(annotationMirror.getAnnotationType().asElement())) .anyMatch(type -> typeInAnnotations(type, annotations)); }
private void addModulesToMetaInf(Set<? extends Element> moduleElements) { logger.debug("Processing GWTP modules meta data."); for (Element moduleElement : moduleElements) { String moduleType = asType(moduleElement).getQualifiedName().toString(); ginModulesMetaData.writeLine(moduleType); } } }
@Override public boolean apply(TypeMirror input) { return input.getKind().equals(TypeKind.DECLARED) && (MoreElements.asType(MoreTypes.asDeclared(input).asElement())) .getKind() .equals(ElementKind.CLASS) && !types.isSameType(objectType, input); } }),
private void addBundlesToCollection(Set<? extends Element> bundles) { for (Element bundle : bundles) { String name = bundle.getAnnotation(ProviderBundle.class).value(); Type type = new Type(asType(bundle)); collection.addBundle(name, type); } }
@Override public Type getType() { if (type == null) { String packageName = new Type(asType(element)).getPackageName(); String presenterName = getPresenterType().getSimpleName(); String proxyName = element.getSimpleName().toString(); type = new Type(packageName, String.format("%s$$%s", presenterName, proxyName)); } return type; }
public TypeElement asResourceTypeElement(Element element) { if (element.getKind() == ElementKind.INTERFACE) { return asType(element); } logger.mandatoryWarning().context(element).log("Element annotated with @Path must be an interface."); throw new UnableToProcessException(); }