use of javax.lang.model.element.TypeElement in project buck by facebook.
the class DescriptorAndSignatureFactoryTestBase method findErrors.
private void findErrors(TypeElement typeElement, Function<FieldNode, String> fieldNodeExpectedValueGetter, Function<MethodNode, String> methodNodeExpectedValueGetter, Function<ClassNode, String> classNodeExpectedValueGetter, Function<Element, String> elementActualValueGetter) throws IOException {
ClassNode typeNode = getClassNode(elements.getBinaryName(typeElement).toString());
for (Element enclosedElement : typeElement.getEnclosedElements()) {
Name elementName = enclosedElement.getSimpleName();
String actual = elementActualValueGetter.apply(enclosedElement);
switch(enclosedElement.getKind()) {
case FIELD:
checkValue("Field", elementName, fieldNodeExpectedValueGetter.apply(getFieldNode(typeNode, elementName)), actual);
break;
case CONSTRUCTOR:
case METHOD:
checkValue("Method", elementName, methodNodeExpectedValueGetter.apply(getMethodNode(typeNode, elementName)), actual);
break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
ClassNode innerTypeNode = getClassNode(elements.getBinaryName((TypeElement) enclosedElement).toString());
checkValue("Class", elementName, classNodeExpectedValueGetter.apply(innerTypeNode), actual);
findErrors((TypeElement) enclosedElement, fieldNodeExpectedValueGetter, methodNodeExpectedValueGetter, classNodeExpectedValueGetter, elementActualValueGetter);
break;
// $CASES-OMITTED$
default:
fail(String.format("Didn't implement testing for element kind %s", enclosedElement.getKind()));
continue;
}
}
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedPackageElementTest method testCanExtendPackageFromDependencies.
@Test
public void testCanExtendPackageFromDependencies() throws IOException {
compile(Joiner.on('\n').join("package java.util;", "class Foo { }"));
PackageElement javaUtilPackage = elements.getPackageElement("java.util");
TypeElement listType = elements.getTypeElement("java.util.List");
TypeElement fooType = elements.getTypeElement("java.util.Foo");
assertPackageContains(javaUtilPackage, listType);
assertPackageContains(javaUtilPackage, fooType);
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTreesTest method testGetTreeGetPathRoundtripTypeElement.
@Test
public void testGetTreeGetPathRoundtripTypeElement() throws IOException {
compile("class Foo<T, U> { }");
TypeElement fooElement = elements.getTypeElement("Foo");
Tree fooTree = trees.getTree(fooElement);
TreePath fooPath = trees.getPath(fooElement);
assertSame(fooPath.getLeaf(), fooTree);
assertSame(fooElement, trees.getElement(fooPath));
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class StandaloneDeclaredTypeTest method testToStringWithGenerics.
@Test
public void testToStringWithGenerics() throws IOException {
initCompiler();
TypeElement mapElement = elements.getTypeElement("java.util.Map");
TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
TypeMirror integerType = elements.getTypeElement("java.lang.Integer").asType();
DeclaredType mapStringIntType = types.getDeclaredType(mapElement, stringType, integerType);
assertEquals("java.util.Map<java.lang.String,java.lang.Integer>", mapStringIntType.toString());
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TypeResolverTest method testMultiDimArrayTypeResolves.
@Test
public void testMultiDimArrayTypeResolves() throws IOException {
compile("abstract class Foo extends java.util.ArrayList<java.lang.String[][]> { }");
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
ArrayType stringArrayType = types.getArrayType(stringType);
ArrayType stringArrayArrayType = types.getArrayType(stringArrayType);
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringArrayArrayType);
assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
Aggregations