use of java.lang.annotation.Target in project auto by google.
the class FactoryWriter method isTypeUseAnnotation.
private static boolean isTypeUseAnnotation(AnnotationMirror mirror) {
Element annotationElement = mirror.getAnnotationType().asElement();
// This is basically equivalent to:
// Target target = annotationElement.getAnnotation(Target.class);
// return target != null
// && Arrays.asList(annotationElement.getAnnotation(Target.class)).contains(TYPE_USE);
// but that might blow up if the annotation is being compiled at the same time and has an
// undefined identifier in its @Target values. The rigmarole below avoids that problem.
Optional<AnnotationMirror> maybeTargetMirror = Mirrors.getAnnotationMirror(annotationElement, Target.class);
return maybeTargetMirror.map(targetMirror -> AnnotationValues.getEnums(AnnotationMirrors.getAnnotationValue(targetMirror, "value")).stream().map(VariableElement::getSimpleName).anyMatch(name -> name.contentEquals("TYPE_USE"))).orElse(false);
}
use of java.lang.annotation.Target in project querydsl by querydsl.
the class ScalaWriterTest method Annotation_With_ArrayMethod.
@Test
public void Annotation_With_ArrayMethod() throws IOException {
Target annotation = new Target() {
@Override
public ElementType[] value() {
return new ElementType[] { ElementType.FIELD, ElementType.METHOD };
}
@Override
public Class<? extends Annotation> annotationType() {
return Target.class;
}
};
writer.imports(Target.class.getPackage());
writer.annotation(annotation);
assertTrue(w.toString().contains("@Target(Array(FIELD, METHOD))"));
}
use of java.lang.annotation.Target in project querydsl by querydsl.
the class JavaWriterTest method Annotation_With_ArrayMethod.
@Test
public void Annotation_With_ArrayMethod() throws IOException {
Target annotation = new Target() {
@Override
public ElementType[] value() {
return new ElementType[] { ElementType.FIELD, ElementType.METHOD };
}
@Override
public Class<? extends Annotation> annotationType() {
return Target.class;
}
};
writer.imports(Target.class.getPackage());
writer.annotation(annotation);
assertTrue(w.toString().contains("@Target({FIELD, METHOD})"));
}
use of java.lang.annotation.Target in project wire by square.
the class JavaGenerator method generateOptionType.
// Example:
//
// @Retention(RetentionPolicy.RUNTIME)
// @Target(ElementType.FIELD)
// public @interface MyFieldOption {
// String value();
// }
@Nullable
public TypeSpec generateOptionType(Extend extend, Field field) {
checkArgument(extend.getFields().contains(field));
if (!emitDeclaredOptions)
return null;
ElementType elementType = annotationTargetType(extend);
if (elementType == null)
return null;
if (!eligibleAsAnnotationMember(schema, field))
return null;
TypeName returnType = typeName(field.getType());
ClassName javaType = generatedTypeName(field);
TypeSpec.Builder builder = TypeSpec.annotationBuilder(javaType.simpleName()).addModifiers(PUBLIC).addAnnotation(AnnotationSpec.builder(Retention.class).addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.RUNTIME).build()).addAnnotation(AnnotationSpec.builder(Target.class).addMember("value", "$T.$L", ElementType.class, elementType).build());
if (!field.getDocumentation().isEmpty()) {
builder.addJavadoc("$L\n", field.getDocumentation());
}
builder.addMethod(MethodSpec.methodBuilder("value").returns(returnType).addModifiers(PUBLIC, ABSTRACT).build());
return builder.build();
}
Aggregations