use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class MoreElements method isRuntimeRetention.
public static boolean isRuntimeRetention(AnnotationMirror annotation) {
DeclaredType annotationType = annotation.getAnnotationType();
TypeElement annotationTypeElement = (TypeElement) annotationType.asElement();
AnnotationMirror retentionAnnotation = findAnnotation("java.lang.annotation.Retention", annotationTypeElement);
if (retentionAnnotation == null) {
return false;
}
VariableElement retentionPolicy = (VariableElement) Preconditions.checkNotNull(findAnnotationValue(retentionAnnotation, "value"));
return retentionPolicy.getSimpleName().contentEquals("RUNTIME");
}
use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class StandaloneDeclaredTypeTest method testToStringNoGenerics.
@Test
public void testToStringNoGenerics() throws IOException {
compile(Joiner.on('\n').join("package com.facebook.foo;", "class Foo { }"));
DeclaredType fooType = (DeclaredType) elements.getTypeElement("com.facebook.foo.Foo").asType();
assertEquals("com.facebook.foo.Foo", fooType.toString());
}
use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class TreeBackedTypeElementTest method testGetSuperclassObjectSuperclassIsObject.
@Test
public void testGetSuperclassObjectSuperclassIsObject() throws IOException {
compile("class Foo extends java.lang.Object { }");
TypeElement fooElement = elements.getTypeElement("Foo");
DeclaredType superclass = (DeclaredType) fooElement.getSuperclass();
TypeElement objectElement = elements.getTypeElement("java.lang.Object");
assertSame(objectElement, superclass.asElement());
}
use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class TreeBackedTypeElementTest method testAsType.
@Test
public void testAsType() throws IOException {
compile("class Foo { }");
TypeElement fooElement = elements.getTypeElement("Foo");
TypeMirror fooTypeMirror = fooElement.asType();
assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
DeclaredType fooDeclaredType = (DeclaredType) fooTypeMirror;
assertSame(fooElement, fooDeclaredType.asElement());
assertEquals(0, fooDeclaredType.getTypeArguments().size());
TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
assertEquals(TypeKind.NONE, enclosingType.getKind());
assertTrue(enclosingType instanceof NoType);
}
use of javax.lang.model.type.DeclaredType in project buck by facebook.
the class TypeResolverTest method testPrimitiveArrayTypeResolves.
@Test
public void testPrimitiveArrayTypeResolves() throws IOException {
compile("abstract class Foo extends java.util.ArrayList<int[]> { }");
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeMirror intType = types.getPrimitiveType(TypeKind.INT);
ArrayType intArrayType = types.getArrayType(intType);
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, intArrayType);
assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
Aggregations