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