use of javax.lang.model.element.AnnotationValue in project auto by google.
the class AnnotationValuesTest method getTypeMirrors.
@Test
public void getTypeMirrors() {
TypeMirror insideClassA = getTypeElement(InsideClassA.class).asType();
TypeMirror insideClassB = getTypeElement(InsideClassB.class).asType();
AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "classValues");
ImmutableList<DeclaredType> valueElements = AnnotationValues.getTypeMirrors(value);
assertThat(valueElements).comparingElementsUsing(Correspondence.from(types::isSameType, "has Same Type")).containsExactly(insideClassA, insideClassB).inOrder();
}
use of javax.lang.model.element.AnnotationValue in project auto by google.
the class AnnotationValuesTest method getShorts.
@Test
public void getShorts() {
AnnotationValue value = AnnotationMirrors.getAnnotationValue(annotationMirror, "shortValues");
assertThat(AnnotationValues.getShorts(value)).containsExactly((short) 11, (short) 12).inOrder();
}
use of javax.lang.model.element.AnnotationValue in project auto by google.
the class SimpleTypeAnnotationValueTest method primitiveClass.
@Test
public void primitiveClass() {
AnnotationValue annotationValue = SimpleTypeAnnotationValue.of(primitiveType);
assertThat(annotationValue.getValue()).isEqualTo(primitiveType);
}
use of javax.lang.model.element.AnnotationValue in project auto by google.
the class SimpleAnnotationMirrorTest method multipleValues.
@Test
public void multipleValues() {
TypeElement multipleValues = getTypeElement(MultipleValues.class);
Map<String, AnnotationValue> values = new HashMap<>();
values.put("value1", intValue(1));
values.put("value2", intValue(2));
assertThat(SimpleAnnotationMirror.of(multipleValues, values).getElementValues()).hasSize(2);
}
use of javax.lang.model.element.AnnotationValue in project auto by google.
the class AutoValueishProcessor method warnAboutPrimitiveArrays.
private void warnAboutPrimitiveArrays(TypeElement autoValueClass, ExecutableElement getter) {
boolean suppressed = false;
Optional<AnnotationMirror> maybeAnnotation = getAnnotationMirror(getter, "java.lang.SuppressWarnings");
if (maybeAnnotation.isPresent()) {
AnnotationValue listValue = getAnnotationValue(maybeAnnotation.get(), "value");
suppressed = listValue.accept(new ContainsMutableVisitor(), null);
}
if (!suppressed) {
// If the primitive-array property method is defined directly inside the @AutoValue class,
// then our error message should point directly to it. But if it is inherited, we don't
// want to try to make the error message point to the inherited definition, since that would
// be confusing (there is nothing wrong with the definition itself), and won't work if the
// inherited class is not being recompiled. Instead, in this case we point to the @AutoValue
// class itself, and we include extra text in the error message that shows the full name of
// the inherited method.
boolean sameClass = getter.getEnclosingElement().equals(autoValueClass);
Element element = sameClass ? getter : autoValueClass;
String context = sameClass ? "" : (" Method: " + getter.getEnclosingElement() + "." + getter);
errorReporter.reportWarning(element, "[AutoValueMutable] An @%s property that is a primitive array returns the original" + " array, which can therefore be modified by the caller. If this is OK, you can" + " suppress this warning with @SuppressWarnings(\"mutable\"). Otherwise, you should" + " replace the property with an immutable type, perhaps a simple wrapper around the" + " original array.%s", simpleAnnotationName, context);
}
}
Aggregations