@Override public boolean applicable(Context context) { return context.autoValueClass().getAnnotation(WithBeanGetter.class) != null; }
public static void warning(Context context, String message, Element element) { context.processingEnvironment().getMessager().printMessage(WARNING, message, element); } }
@Override public boolean applicable(Context context) { for (ExecutableElement element : context.abstractMethods()) { if (element.getSimpleName().toString().equals("toMap")) { return true; } } return false; }
/** * Creates a new {@link TypeSpec.Builder} for the class that is generated by the extension. It * will add a final or abstract modifier, the superclass and a constructor that calls super. The * returned TypeSpec will also include all TypeVariables if the AutoValue class is generic. */ public static TypeSpec.Builder newTypeSpecBuilder( Context context, String className, String classToExtend, boolean isFinal) { TypeVariableName[] typeVariables = getTypeVariables(context.autoValueClass()); return TypeSpec.classBuilder(className) .addModifiers(isFinal ? FINAL : ABSTRACT) .addTypeVariables(Arrays.asList(typeVariables)) .superclass(getSuperClass(context.packageName(), classToExtend, typeVariables)) .addMethod(newConstructor(context.properties())); }
@Override public boolean applicable(Context context) { Map<String, ExecutableElement> properties = context.properties(); for (ExecutableElement element : properties.values()) { if (getAnnotations(element).contains("Redacted")) { return true; } } return false; }
/** * Returns the {@link ClassName} of the last class in the chain of generated implementations, * which is final. This can be used for creating new instances. */ public static ClassName getFinalClassClassName(Context context) { return ClassName.get(context.packageName(), getFinalClassSimpleName(context)); }
private static String getFinalClassSimpleName(Context context) { TypeElement autoValueClass = context.autoValueClass(); String name = autoValueClass.getSimpleName().toString(); Element enclosingElement = autoValueClass.getEnclosingElement(); while (enclosingElement instanceof TypeElement) { name = enclosingElement.getSimpleName().toString() + "_" + name; enclosingElement = enclosingElement.getEnclosingElement(); } return "AutoValue_" + name; }
/** * Builds a List of {@link Property} for the given {@link AutoValueExtension.Context}. */ public static ImmutableList<Property> buildProperties(AutoValueExtension.Context context) { ImmutableList.Builder<Property> values = ImmutableList.builder(); for (Map.Entry<String, ExecutableElement> entry : context.properties().entrySet()) { values.add(new Property(entry.getKey(), entry.getValue())); } return values.build(); }
private static ClassName getFinalClassClassName(Context context) { return ClassName.get(context.packageName(), getFinalClassSimpleName(context)); }
public static void error(Context context, String message, Element element) { context.processingEnvironment().getMessager().printMessage(ERROR, message, element); }
@Override public boolean applicable(Context context) { return getMatchingAbstractMethod(context.abstractMethods(), CONTENT_VALUES).isPresent(); }
private static String getFinalClassSimpleName(Context context) { TypeElement autoValueClass = context.autoValueClass(); StringBuilder name = new StringBuilder(autoValueClass.getSimpleName().toString()); Element enclosingElement = autoValueClass.getEnclosingElement(); while (enclosingElement instanceof TypeElement) { name.insert(0, enclosingElement.getSimpleName().toString() + "_"); enclosingElement = enclosingElement.getEnclosingElement(); } return "AutoValue_" + name; }
public static ImmutableList<ColumnProperty> from(AutoValueExtension.Context context) { ImmutableList.Builder<ColumnProperty> values = ImmutableList.builder(); for (Map.Entry<String, ExecutableElement> entry : context.properties().entrySet()) { values.add(new ColumnProperty(entry.getKey(), entry.getValue())); } return values.build(); }
@Override public String generateClass( Context context, String className, String classToExtend, boolean isFinal) { TypeSpec subclass = newTypeSpecBuilder(context, className, classToExtend, isFinal) .addMethods(generateWithMethods(context)) .build(); return JavaFile.builder(context.packageName(), subclass).build().toString(); }
/** * Will call {@link Messager#printMessage(Diagnostic.Kind, CharSequence, Element)} with * {@link Diagnostic.Kind#ERROR} and the given {@code message} for {@code property}. This will * ultimately fail the build, but will not abort it right now. */ public static void error(Context context, Property property, String message) { context.processingEnvironment() .getMessager() .printMessage(ERROR, message, property.element()); }
@Override public Set<ExecutableElement> consumeMethods(Context context) { Set<ExecutableElement> set = new HashSet<>(); for (ExecutableElement element : context.abstractMethods()) { switch (element.getSimpleName().toString()) { case "toMap": set.add(element); break; } } return set; }
@Override public boolean applicable(Context context) { TypeElement valueClass = context.autoValueClass(); return getMatchingStaticMethod(valueClass, ClassName.get(valueClass), CURSOR).isPresent() || getMatchingStaticField(valueClass, getFunc1TypeName(context)).isPresent() || getMatchingStaticField(valueClass, getFunctionTypeName(context)).isPresent(); }
@Override public boolean applicable(Context context) { Map<String, ExecutableElement> properties = context.properties(); for (ExecutableElement element : properties.values()) { Set<String> annotations = getAnnotations(element); annotationType = AnnotationType.from(annotations); if (annotationType == AnnotationType.ERROR) { throw new RuntimeException("Annotations are mutually exclusive, " + "only one annotation type can be included at the same time."); } if (annotationType != AnnotationType.NOT_PRESENT) { return true; } } return false; }
@Override public Set<ExecutableElement> consumeMethods(Context context) { Optional<ExecutableElement> method = getMatchingAbstractMethod(context.abstractMethods(), CONTENT_VALUES); if (method.isPresent()) { return Collections.singleton(method.get()); } return Collections.emptySet(); }
@Override public boolean applicable(Context context) { for (AnnotationMirror annotation : context.autoValueClass().getAnnotationMirrors()) { if (FIREBASE_VALUE_ANNOTATION.equals(AnnotationSpec.get(annotation).type)) { return true; } } return false; }