Search in sources :

Example 26 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testMultipleBoundedTypeParameter.

@Test
public void testMultipleBoundedTypeParameter() throws IOException {
    compile("class Foo<T extends java.lang.CharSequence & java.lang.Runnable & java.io.Closeable> { }");
    TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
    TypeMirror runnableType = elements.getTypeElement("java.lang.Runnable").asType();
    TypeMirror closeableType = elements.getTypeElement("java.io.Closeable").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(3, bounds.size());
    assertSameType(charSequenceType, bounds.get(0));
    assertSameType(runnableType, bounds.get(1));
    assertSameType(closeableType, bounds.get(2));
}
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 27 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testMultipleTypeParameters.

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

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

the class TreeBackedTypeParameterElementTest method testEnclosingElementDoesNotEnclose.

@Test
public void testEnclosingElementDoesNotEnclose() throws IOException {
    compile("class Foo<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeParameterElement tElement = fooElement.getTypeParameters().get(0);
    assertSame(fooElement, tElement.getEnclosingElement());
    assertFalse(fooElement.getEnclosedElements().contains(tElement));
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 29 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testUnboundedTypeParameter.

@Test
public void testUnboundedTypeParameter() throws IOException {
    compile("class Foo<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeMirror objectType = elements.getTypeElement("java.lang.Object").asType();
    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(objectType, 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 30 with TypeParameterElement

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

the class TreeBackedTypeParameterElementTest method testForwardReferenceTypeParameterBoundedTypeParameter.

@Test
public void testForwardReferenceTypeParameterBoundedTypeParameter() throws IOException {
    compile("class Foo<T extends U, U> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeParameterElement tElement = fooElement.getTypeParameters().get(0);
    TypeMirror uType = fooElement.getTypeParameters().get(1).asType();
    assertSameType(uType, tElement.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)

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