use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTreesTest method testNoTreeOrPathForPrecompiledCode.
@Test
public void testNoTreeOrPathForPrecompiledCode() throws IOException {
compile("class Foo { }");
TypeElement stringElement = elements.getTypeElement("java.lang.String");
assertNull(trees.getTree(stringElement));
assertNull(trees.getPath(stringElement));
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTypeElementTest method testGetQualifiedNameInnerClass.
@Test
public void testGetQualifiedNameInnerClass() throws IOException {
compile(Joiner.on('\n').join("package com.facebook.buck;", "public class Foo {", " public class Bar { }", "}"));
TypeElement element = elements.getTypeElement("com.facebook.buck.Foo.Bar");
assertNameEquals("com.facebook.buck.Foo.Bar", element.getQualifiedName());
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTypeElementTest method testGetEnclosingElementForTopLevelClasses.
@Test
public void testGetEnclosingElementForTopLevelClasses() throws IOException {
compile("class Foo { }");
TypeElement fooElement = elements.getTypeElement("Foo");
PackageElement unnamedPackage = elements.getPackageElement("");
assertSame(unnamedPackage, fooElement.getEnclosingElement());
assertTrue(unnamedPackage.getEnclosedElements().contains(fooElement));
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTypeElementTest method testEnclosedClasses.
@Test
public void testEnclosedClasses() throws IOException {
compile(Joiner.on('\n').join("class Foo {", " class Bar { }", "}"));
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement barElement = elements.getTypeElement("Foo.Bar");
List<Element> enclosedElements = new ArrayList<>(fooElement.getEnclosedElements());
assertThat(enclosedElements, Matchers.hasItems(barElement));
assertSame(fooElement, barElement.getEnclosingElement());
}
use of javax.lang.model.element.TypeElement in project buck by facebook.
the class TreeBackedTypeElementTest method testGetSuperclassOtherSuperclass.
@Test
public void testGetSuperclassOtherSuperclass() throws IOException {
compile(ImmutableMap.of("Foo.java", Joiner.on('\n').join("package com.facebook.foo;", "public class Foo extends com.facebook.bar.Bar { }"), "Bar.java", Joiner.on('\n').join("package com.facebook.bar;", "public class Bar { }")));
TypeElement fooElement = elements.getTypeElement("com.facebook.foo.Foo");
TypeElement barElement = elements.getTypeElement("com.facebook.bar.Bar");
DeclaredType superclass = (DeclaredType) fooElement.getSuperclass();
assertSame(barElement, superclass.asElement());
}
Aggregations