Search in sources :

Example 31 with TypeElement

use of javax.lang.model.element.TypeElement in project buck by facebook.

the class TreeBackedTypeElementTest method testGetSuperclassOfInterfaceIsNoneType.

@Test
public void testGetSuperclassOfInterfaceIsNoneType() throws IOException {
    compile("interface Foo extends java.lang.Runnable { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    assertSame(TypeKind.NONE, fooElement.getSuperclass().getKind());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 32 with TypeElement

use of javax.lang.model.element.TypeElement in project buck by facebook.

the class TreeBackedTypeElementTest method testGetSuperclassNoSuperclassIsObject.

@Test
public void testGetSuperclassNoSuperclassIsObject() throws IOException {
    compile("class Foo { }");
    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 33 with TypeElement

use of javax.lang.model.element.TypeElement in project buck by facebook.

the class TreeBackedTypeElementTest method testGetQualifiedNameUnnamedPackage.

@Test
public void testGetQualifiedNameUnnamedPackage() throws IOException {
    compile("public class Foo {}");
    TypeElement element = elements.getTypeElement("Foo");
    assertNameEquals("Foo", element.getQualifiedName());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 34 with TypeElement

use of javax.lang.model.element.TypeElement in project buck by facebook.

the class TreeBackedTypeElementTest method testToString.

@Test
public void testToString() throws IOException {
    compile(Joiner.on('\n').join("package com.facebook.buck;", "public class Foo<T> {}"));
    TypeElement element = elements.getTypeElement("com.facebook.buck.Foo");
    assertEquals("com.facebook.buck.Foo", element.toString());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 35 with TypeElement

use of javax.lang.model.element.TypeElement in project buck by facebook.

the class TreeBackedTypeElementTest method testGetEnclosingElementForBuiltInTopLevelClasses.

@Ignore("TODO(jkeljo): Need to wrap elements coming out of javac to ensure callers always get" + "our PackageElement impl instead of javac's.")
@Test
public void testGetEnclosingElementForBuiltInTopLevelClasses() throws IOException {
    initCompiler();
    TypeElement stringElement = elements.getTypeElement("java.lang.String");
    PackageElement javaLangElement = elements.getPackageElement("java.lang");
    assertSame(javaLangElement, stringElement.getEnclosingElement());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TypeElement (javax.lang.model.element.TypeElement)1564 ExecutableElement (javax.lang.model.element.ExecutableElement)517 Element (javax.lang.model.element.Element)504 TypeMirror (javax.lang.model.type.TypeMirror)421 VariableElement (javax.lang.model.element.VariableElement)333 DeclaredType (javax.lang.model.type.DeclaredType)202 ArrayList (java.util.ArrayList)177 PackageElement (javax.lang.model.element.PackageElement)159 AnnotationMirror (javax.lang.model.element.AnnotationMirror)151 Test (org.junit.Test)136 HashMap (java.util.HashMap)118 HashSet (java.util.HashSet)109 Elements (javax.lang.model.util.Elements)101 Map (java.util.Map)98 IOException (java.io.IOException)97 List (java.util.List)97 ClassName (com.squareup.javapoet.ClassName)88 Test (org.junit.jupiter.api.Test)80 MethodSpec (com.squareup.javapoet.MethodSpec)72 TypeSpec (com.squareup.javapoet.TypeSpec)63