Search in sources :

Example 11 with TypeParameterElement

use of javax.lang.model.element.TypeParameterElement in project robolectric by robolectric.

the class RobolectricModel method appendParameterList.

public void appendParameterList(StringBuilder message, List<? extends TypeParameterElement> tpeList) {
    boolean first = true;
    for (TypeParameterElement tpe : tpeList) {
        if (first) {
            first = false;
        } else {
            message.append(',');
        }
        message.append(tpe.toString());
        boolean iFirst = true;
        for (TypeMirror bound : getExplicitBounds(tpe)) {
            if (iFirst) {
                message.append(" extends ");
                iFirst = false;
            } else {
                message.append(',');
            }
            message.append(bound);
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Example 12 with TypeParameterElement

use of javax.lang.model.element.TypeParameterElement in project immutables by immutables.

the class TypeExtractor method initParameters.

private Type.Parameters initParameters(Parameterizable context) {
    Type.Parameters parameters = factory.parameters();
    for (TypeParameterElement p : context.getTypeParameters()) {
        String name = p.getSimpleName().toString();
        List<Type.Defined> bounds = getBounds(parameters, p);
        parameters = parameters.introduce(name, bounds);
    }
    return parameters;
}
Also used : ArrayType(javax.lang.model.type.ArrayType) ErrorType(javax.lang.model.type.ErrorType) ExecutableType(javax.lang.model.type.ExecutableType) NoType(javax.lang.model.type.NoType) NullType(javax.lang.model.type.NullType) UnionType(javax.lang.model.type.UnionType) DeclaredType(javax.lang.model.type.DeclaredType) PrimitiveType(javax.lang.model.type.PrimitiveType) WildcardType(javax.lang.model.type.WildcardType) TypeParameterElement(javax.lang.model.element.TypeParameterElement)

Example 13 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 14 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 15 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)

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