use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TypeResolverTest method testParameterizedTypeResolves.
@Test
public void testParameterizedTypeResolves() throws IOException {
compile(Joiner.on('\n').join("abstract class Foo extends java.util.ArrayList<java.lang.String> { }", "abstract class Bar extends java.util.ArrayList<java.lang.String> { }"));
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeElement stringElement = elements.getTypeElement("java.lang.String");
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringElement.asType());
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement barElement = elements.getTypeElement("Bar");
DeclaredType fooSuperclass = (DeclaredType) fooElement.getSuperclass();
DeclaredType barSuperclass = (DeclaredType) barElement.getSuperclass();
assertNotSame(expectedSuperclass, fooSuperclass);
assertSameType(expectedSuperclass, fooSuperclass);
assertSameType(fooSuperclass, barSuperclass);
}
use of javax.lang.model.element.TypeElement 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());
}
use of javax.lang.model.element.TypeElement 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());
}
use of javax.lang.model.element.TypeElement 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));
}
use of javax.lang.model.element.TypeElement 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());
}
Aggregations