Search in sources :

Example 36 with TypeElement

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

the class TreeBackedTypeElementTest method testGetQualifiedNameNamedPackage.

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

Example 37 with TypeElement

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

the class TreeBackedTypeElementTest method testGetSimpleName.

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

Example 38 with TypeElement

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

the class TreeBackedTypeParameterElementTest method testTypeParameterBoundedTypeParameter.

@Test
public void testTypeParameterBoundedTypeParameter() throws IOException {
    compile("class Foo<T, U extends T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeParameterElement uElement = fooElement.getTypeParameters().get(1);
    TypeMirror tType = fooElement.getTypeParameters().get(0).asType();
    assertSameType(tType, uElement.getBounds().get(0));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 39 with TypeElement

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

the class TreeBackedTypesTest method testIsNotSameTypeParameterizedType.

@Test
public void testIsNotSameTypeParameterizedType() throws IOException {
    initCompiler();
    TypeElement listElement = elements.getTypeElement("java.util.List");
    TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
    TypeMirror integerType = elements.getTypeElement("java.lang.Integer").asType();
    TypeMirror listStringType = types.getDeclaredType(listElement, stringType);
    TypeMirror listIntType = types.getDeclaredType(listElement, integerType);
    assertNotSameType(listStringType, listIntType);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 40 with TypeElement

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

the class TreeBackedTypesTest method testIsSameTypeUnboundedTypeVariable.

@Test
public void testIsSameTypeUnboundedTypeVariable() throws IOException {
    compile("class Foo<T> extends java.util.ArrayList<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeMirror t1 = fooElement.getTypeParameters().get(0).asType();
    TypeMirror t2 = ((DeclaredType) fooElement.getSuperclass()).getTypeArguments().get(0);
    assertSameType(t1, t2);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) 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