use of javax.lang.model.element.ExecutableElement in project buck by facebook.
the class TreeBackedExecutableElementTest method testGetThrownTypes.
@Test
public void testGetThrownTypes() throws IOException {
compile(Joiner.on('\n').join("abstract class Foo {", " public abstract void foo() throws Exception, RuntimeException;", "}"));
ExecutableElement method = findMethod("foo", elements.getTypeElement("Foo"));
assertThat(method.getThrownTypes().stream().map(TypeMirror::toString).collect(Collectors.toList()), Matchers.contains(elements.getTypeElement("java.lang.Exception").asType().toString(), elements.getTypeElement("java.lang.RuntimeException").asType().toString()));
}
use of javax.lang.model.element.ExecutableElement in project buck by facebook.
the class TreeBackedExecutableElementTest method testGetReturnType.
@Test
public void testGetReturnType() throws IOException {
compile(Joiner.on('\n').join("abstract class Foo {", " public abstract String foo();", "}"));
ExecutableElement element = findMethod("foo", elements.getTypeElement("Foo"));
TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
assertSameType(stringType, element.getReturnType());
}
use of javax.lang.model.element.ExecutableElement in project RoboBinding by RoboBinding.
the class WrappedTypeElement method looseSetters.
public List<SetterElement> looseSetters(SetterElementFilter filter) {
List<ExecutableElement> methods = ElementFilter.methodsIn(element.getEnclosedElements());
List<SetterElement> result = Lists.newArrayList();
for (ExecutableElement method : methods) {
MethodElement methodElement = wrapper.wrap(method);
if (!methodElement.isLooseSetter()) {
continue;
}
SetterElement looseSetter = methodElement.asLooseSetter();
if (filter.include(looseSetter)) {
result.add(looseSetter);
}
}
return result;
}
use of javax.lang.model.element.ExecutableElement in project RoboBinding by RoboBinding.
the class WrappedTypeElement method methodsRecursively.
private List<MethodElement> methodsRecursively(MethodElementFilter filter, WrappedTypeElement fromTypeElement) {
if (fromTypeElement.isOfType(Object.class)) {
return Collections.emptyList();
}
List<ExecutableElement> methods = ElementFilter.methodsIn(fromTypeElement.element.getEnclosedElements());
List<MethodElement> result = Lists.newArrayList();
for (ExecutableElement method : methods) {
MethodElement methodElement = wrapper.wrap(method);
if (filter.include(methodElement)) {
result.add(methodElement);
}
}
result.addAll(methodsRecursively(filter, fromTypeElement.superclass()));
return result;
}
use of javax.lang.model.element.ExecutableElement in project RoboBinding by RoboBinding.
the class ElementWrapperTest method supportedElements.
@DataPoints("supportedElements")
public static ElementToWrapped[] supportedElements() {
Elements elements = compilation.getElements();
TypeElement typeElement = elements.getTypeElement(MethodsAndFields.class.getName());
ExecutableElement methodElement = ElementFilter.methodsIn(typeElement.getEnclosedElements()).get(0);
return new ElementToWrapped[] { a(typeElement).itsWrapped(WrappedTypeElement.class), a(methodElement).itsWrapped(MethodElement.class) };
}
Aggregations