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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations