Search in sources :

Example 86 with DeclaredType

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");
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 87 with DeclaredType

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());
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 88 with DeclaredType

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());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 89 with DeclaredType

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);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) NoType(javax.lang.model.type.NoType) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 90 with DeclaredType

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());
}
Also used : ArrayType(javax.lang.model.type.ArrayType) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Aggregations

DeclaredType (javax.lang.model.type.DeclaredType)138 TypeElement (javax.lang.model.element.TypeElement)82 TypeMirror (javax.lang.model.type.TypeMirror)75 ExecutableElement (javax.lang.model.element.ExecutableElement)38 Element (javax.lang.model.element.Element)28 VariableElement (javax.lang.model.element.VariableElement)26 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Test (org.junit.Test)19 ArrayType (javax.lang.model.type.ArrayType)15 ArrayList (java.util.ArrayList)14 List (java.util.List)10 Map (java.util.Map)9 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 HashSet (java.util.HashSet)8 AnnotationValue (javax.lang.model.element.AnnotationValue)8 HashMap (java.util.HashMap)6 TypeParameterElement (javax.lang.model.element.TypeParameterElement)6 Types (javax.lang.model.util.Types)6 Name (javax.lang.model.element.Name)5 PackageElement (javax.lang.model.element.PackageElement)5