Search in sources :

Example 1 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testToString.

@Test
public void testToString() throws IOException {
    compile("class Foo<T extends java.lang.Runnable> { }");
    TypeParameterElement typeParam = elements.getTypeElement("Foo").getTypeParameters().get(0);
    assertEquals("T", typeParam.toString());
}
Also used : TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 2 with TypeParameterElement

use of javax.lang.model.element.TypeParameterElement 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 3 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testGetSimpleName.

@Test
public void testGetSimpleName() throws IOException {
    compile("class Foo<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    final List<? extends TypeParameterElement> typeParameters = fooElement.getTypeParameters();
    assertSame(1, typeParameters.size());
    TypeParameterElement typeParam = typeParameters.get(0);
    assertNameEquals("T", typeParam.getSimpleName());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 4 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testGetEnclosingElement.

@Test
public void testGetEnclosingElement() throws IOException {
    compile("class Foo<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    final List<? extends TypeParameterElement> typeParameters = fooElement.getTypeParameters();
    assertSame(1, typeParameters.size());
    TypeParameterElement typeParam = typeParameters.get(0);
    assertSame(fooElement, typeParam.getGenericElement());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 5 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testAccept.

@Test
public void testAccept() throws IOException {
    compile("class Foo<T> { }");
    TypeParameterElement expectedTypeParameter = elements.getTypeElement("Foo").getTypeParameters().get(0);
    Object expectedResult = new Object();
    Object actualResult = expectedTypeParameter.accept(new SimpleElementVisitor8<Object, Object>() {

        @Override
        protected Object defaultAction(Element e, Object o) {
            return null;
        }

        @Override
        public Object visitTypeParameter(TypeParameterElement actualTypeParameter, Object o) {
            assertSame(expectedTypeParameter, actualTypeParameter);
            return o;
        }
    }, expectedResult);
    assertSame(expectedResult, actualResult);
}
Also used : Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Aggregations

TypeParameterElement (javax.lang.model.element.TypeParameterElement)66 TypeElement (javax.lang.model.element.TypeElement)30 TypeMirror (javax.lang.model.type.TypeMirror)26 Test (org.junit.Test)18 ExecutableElement (javax.lang.model.element.ExecutableElement)13 TypeVariable (javax.lang.model.type.TypeVariable)13 Element (javax.lang.model.element.Element)10 VariableElement (javax.lang.model.element.VariableElement)9 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 List (java.util.List)7 DeclaredType (javax.lang.model.type.DeclaredType)7 MethodSpec (com.squareup.javapoet.MethodSpec)6 Map (java.util.Map)6 FieldSpec (com.squareup.javapoet.FieldSpec)5 HashSet (java.util.HashSet)4 Modifier (javax.lang.model.element.Modifier)4 ArrayType (javax.lang.model.type.ArrayType)4 Types (javax.lang.model.util.Types)4 MoreElements (com.google.auto.common.MoreElements)3