Search in sources :

Example 16 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 17 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)

Example 18 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testSuperclassBoundedTypeParameter.

@Test
public void testSuperclassBoundedTypeParameter() throws IOException {
    compile("class Foo<T extends java.lang.CharSequence> { }");
    TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
    TypeElement fooElement = elements.getTypeElement("Foo");
    List<? extends TypeParameterElement> typeParameters = fooElement.getTypeParameters();
    assertSame(1, typeParameters.size());
    TypeParameterElement typeParam = typeParameters.get(0);
    List<? extends TypeMirror> bounds = typeParam.getBounds();
    assertSame(1, bounds.size());
    assertSameType(charSequenceType, bounds.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 19 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testGetGenericElement.

@Test
public void testGetGenericElement() 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 20 with TypeParameterElement

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

the class CompilerTreeApiTest method getTypeParameterUpperBound.

protected TypeMirror getTypeParameterUpperBound(String typeName, int typeParameterIndex) {
    TypeParameterElement typeParameter = elements.getTypeElement(typeName).getTypeParameters().get(typeParameterIndex);
    TypeVariable typeVariable = (TypeVariable) typeParameter.asType();
    return typeVariable.getUpperBound();
}
Also used : TypeVariable(javax.lang.model.type.TypeVariable) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Aggregations

TypeParameterElement (javax.lang.model.element.TypeParameterElement)40 TypeElement (javax.lang.model.element.TypeElement)20 TypeMirror (javax.lang.model.type.TypeMirror)17 Test (org.junit.Test)17 TypeVariable (javax.lang.model.type.TypeVariable)6 ArrayList (java.util.ArrayList)5 ExecutableElement (javax.lang.model.element.ExecutableElement)5 DeclaredType (javax.lang.model.type.DeclaredType)5 Element (javax.lang.model.element.Element)4 VariableElement (javax.lang.model.element.VariableElement)4 AbstractJClass (com.helger.jcodemodel.AbstractJClass)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ArrayType (javax.lang.model.type.ArrayType)2 PrimitiveType (javax.lang.model.type.PrimitiveType)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 JsonMapper (com.bluelinelabs.logansquare.JsonMapper)1 LoganSquare (com.bluelinelabs.logansquare.LoganSquare)1 ParameterizedType (com.bluelinelabs.logansquare.ParameterizedType)1