public static AnnotationSpec get(Annotation annotation) { return get(annotation, false); }
@Override public Builder visitAnnotation(AnnotationMirror a, String name) { return builder.addMember(name, "$L", get(a)); }
protected static List<ParameterSpec> buildParamSpecs(List<? extends VariableElement> params) { List<ParameterSpec> result = new ArrayList<>(); for (VariableElement param : params) { Builder builder = ParameterSpec.builder(TypeName.get(param.asType()), param.getSimpleName().toString()); for (AnnotationMirror annotation : param.getAnnotationMirrors()) { builder.addAnnotation(AnnotationSpec.get(annotation)); } result.add(builder.build()); } return result; }
public static ImmutableList<AnnotationSpec> extractValidAnnotations(TypeElement element) { final List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { if (isValidAnnotation(annotationMirror)) { annotations.add(AnnotationSpec.get(annotationMirror)); } } return ImmutableList.copyOf(annotations); }
public static AnnotationSpec get(Annotation annotation, boolean includeDefaultValues) { Builder builder = builder(annotation.annotationType()); try { Method[] methods = annotation.annotationType().getDeclaredMethods(); Arrays.sort(methods, Comparator.comparing(Method::getName)); for (Method method : methods) { Object value = method.invoke(annotation); if (!includeDefaultValues) { if (Objects.deepEquals(value, method.getDefaultValue())) { continue; } } if (value.getClass().isArray()) { for (int i = 0; i < Array.getLength(value); i++) { builder.addMemberForValue(method.getName(), Array.get(value, i)); } continue; } if (value instanceof Annotation) { builder.addMember(method.getName(), "$L", get((Annotation) value)); continue; } builder.addMemberForValue(method.getName(), value); } } catch (Exception e) { throw new RuntimeException("Reflecting " + annotation + " failed!", e); } return builder.build(); }
public static AnnotationSpec get(Annotation annotation) { return get(annotation, false); }
public static AnnotationSpec get(Annotation annotation) { return get(annotation, false); }
private AnnotationSpec pathAnnotation(Path path) { AnnotationSpec pathAnnotation = AnnotationSpec.get(path); if (requestsServiceRoot.isEmpty()) return pathAnnotation; return makeNewPath(path, pathAnnotation); }
public ArgModel(Element element, Provider provider, boolean requireAll, ClassName serializer, String keyValue) { super(element, provider, Arg.class, serializer, keyValue); this.element = element; this.requireAll = requireAll; supportAnnotations = new ArrayList<>(); for(AnnotationMirror annotationMirror: element.getAnnotationMirrors()) { if(Utils.isSupportAnnotation(annotationMirror)) { supportAnnotations.add(AnnotationSpec.get(annotationMirror)); } } required = element.getAnnotation(Required.class); }
@Override public Builder visitAnnotation(AnnotationMirror a, String name) { return builder.addMember(name, "$L", get(a)); }
@Override public Builder visitAnnotation(AnnotationMirror a, String name) { return builder.addMember(name, "$L", get(a)); }
private static TypeName applyAnnotations(TypeName typeName, VariableElement param) { List<? extends AnnotationMirror> annotationMirrors = param.getAnnotationMirrors(); if (annotationMirrors.size() > 0) { List<AnnotationSpec> annotationSpecs = new ArrayList<>(annotationMirrors.size()); for (AnnotationMirror annotationMirror : annotationMirrors) { annotationSpecs.add(AnnotationSpec.get(annotationMirror)); } typeName = typeName.annotated(annotationSpecs); } return typeName; }
static List<AnnotationSpec> generateFirebaseValueClassAnnotations(TypeElement type) { List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotation : type.getAnnotationMirrors()) { AnnotationSpec annotationSpec = AnnotationSpec.get(annotation); TypeName annotationType = AnnotationSpec.get(annotation).type; if (IGNORE_EXTRA_PROPERTIES.equals(annotationType)) { annotations.add(annotationSpec); } else if (THROW_ON_EXTRA_PROPERTIES.equals(annotationType)) { annotations.add(annotationSpec); } } return annotations; }
static List<AnnotationSpec> generateFirebaseValueMethodAnnotations(ExecutableElement property) { List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotation : property.getAnnotationMirrors()) { AnnotationSpec annotationSpec = AnnotationSpec.get(annotation); TypeName annotationType = AnnotationSpec.get(annotation).type; if (EXCLUDE.equals(annotationType)) { annotations.add(annotationSpec); } else if (PROPERTY_NAME.equals(annotationType)) { annotations.add(annotationSpec); } } return annotations; }
public FieldSpec buildField() { FieldSpec.Builder fieldSpec = FieldSpec.builder(TypeName.get(mAnnotatedField.type), mAnnotatedField.name); if (mAnnotatedField.annotationMirrors != null) { for (AnnotationMirror annotationMirror : mAnnotatedField.annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (annotationElement.getQualifiedName().contentEquals(Override.class.getName())) { // Don't copy @Override if present, since we will be adding our own @Override in the // implementation. continue; } fieldSpec.addAnnotation(AnnotationSpec.get(annotationMirror)); } } return fieldSpec.build(); }
private static AnnotationMirror getAnnotationMirror(ClassName annotation, ExecutableElement element) { for (AnnotationMirror elementAnnotation : element.getAnnotationMirrors()) { TypeName annotationType = AnnotationSpec.get(elementAnnotation).type; if (annotation.equals(annotationType)) { return elementAnnotation; } } return null; }
public FieldSpec buildField() { FieldSpec.Builder fieldSpec = FieldSpec.builder(TypeName.get(mAnnotatedField.type), mAnnotatedField.name); if (mAnnotatedField.annotationMirrors != null) { for (AnnotationMirror annotationMirror : mAnnotatedField.annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (annotationElement.getQualifiedName().contentEquals(Override.class.getName())) { // Don't copy @Override if present, since we will be adding our own @Override in the // implementation. continue; } fieldSpec.addAnnotation(AnnotationSpec.get(annotationMirror)); } } return fieldSpec.build(); }
@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; }
protected Iterable<ParameterSpec> addExtraParameters(AnnotatedPresenter ap) { final List<ParameterSpec> list = new ArrayList<>(ap.getArgs().size()); for (Arg arg : ap.getArgs()) { final ParameterSpec.Builder paramBuilder = ParameterSpec.builder(TypeName.get(arg.getType()), arg.getName()); for (AnnotationMirror annotationMirror : arg.getAnnotations()) { paramBuilder.addAnnotation(AnnotationSpec.get(annotationMirror)); } list.add(paramBuilder.build()); } return list; } }
/** * {@link ParameterSpec}s to match {@code parameters}. Note that the type of the {@link * ParameterSpec}s match {@link Parameter#type()} and not {@link Key#type()}. */ private static Iterable<ParameterSpec> parameters(Iterable<Parameter> parameters) { ImmutableList.Builder<ParameterSpec> builder = ImmutableList.builder(); for (Parameter parameter : parameters) { ParameterSpec.Builder parameterBuilder = ParameterSpec.builder(TypeName.get(parameter.type()), parameter.name()); for (AnnotationMirror annotation : Iterables.concat(parameter.nullable().asSet(), parameter.key().qualifier().asSet())) { parameterBuilder.addAnnotation(AnnotationSpec.get(annotation)); } builder.add(parameterBuilder.build()); } return builder.build(); }