Search in sources :

Example 1 with ExecutableElement

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()));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Test(org.junit.Test)

Example 2 with ExecutableElement

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());
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Test(org.junit.Test)

Example 3 with ExecutableElement

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;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 4 with ExecutableElement

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;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 5 with ExecutableElement

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) };
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Elements(javax.lang.model.util.Elements) FromDataPoints(org.junit.experimental.theories.FromDataPoints) DataPoints(org.junit.experimental.theories.DataPoints)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)341 TypeElement (javax.lang.model.element.TypeElement)154 TypeMirror (javax.lang.model.type.TypeMirror)96 VariableElement (javax.lang.model.element.VariableElement)85 Element (javax.lang.model.element.Element)69 Test (org.junit.Test)41 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)32 DeclaredType (javax.lang.model.type.DeclaredType)30 ArrayList (java.util.ArrayList)26 JBlock (com.helger.jcodemodel.JBlock)25 JInvocation (com.helger.jcodemodel.JInvocation)20 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)18 JVar (com.helger.jcodemodel.JVar)18 Map (java.util.Map)18 IJExpression (com.helger.jcodemodel.IJExpression)16 HashSet (java.util.HashSet)16 ElementValidation (org.androidannotations.ElementValidation)15 Block (com.google.devtools.j2objc.ast.Block)13 JMethod (com.helger.jcodemodel.JMethod)13 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)11