Search in sources :

Example 1 with MethodDeclaration

use of com.google.devtools.j2objc.ast.MethodDeclaration in project j2objc by google.

the class TreeConverter method convertMethodDeclaration.

private TreeNode convertMethodDeclaration(JCTree.JCMethodDecl node) {
    MethodDeclaration newNode = new MethodDeclaration();
    convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
    for (JCTree.JCVariableDecl param : node.getParameters()) {
        newNode.addParameter((SingleVariableDeclaration) convert(param));
    }
    return newNode.setIsConstructor(ElementUtil.isConstructor(node.sym)).setExecutableElement(node.sym).setBody((Block) convert(node.getBody()));
}
Also used : MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) JCTree(com.sun.tools.javac.tree.JCTree)

Example 2 with MethodDeclaration

use of com.google.devtools.j2objc.ast.MethodDeclaration in project j2objc by google.

the class ElementReferenceMapper method endVisit.

@Override
public void endVisit(ConstructorInvocation invocation) {
    ExecutableElement childMethodElement = invocation.getExecutableElement();
    handleChildMethod(childMethodElement);
    MethodDeclaration parentMethodDeclaration = TreeUtil.getEnclosingMethod(invocation);
    if (parentMethodDeclaration == null) {
        staticSet.add(stitchMethodIdentifier(childMethodElement));
        return;
    }
    ExecutableElement parentMethodElement = parentMethodDeclaration.getExecutableElement();
    handleParentMethod(parentMethodElement, childMethodElement);
}
Also used : MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 3 with MethodDeclaration

use of com.google.devtools.j2objc.ast.MethodDeclaration in project j2objc by google.

the class ElementReferenceMapper method endVisit.

@Override
public void endVisit(MethodInvocation method) {
    ExecutableElement childMethodElement = method.getExecutableElement();
    handleChildMethod(childMethodElement);
    MethodDeclaration parentMethodDeclaration = TreeUtil.getEnclosingMethod(method);
    if (parentMethodDeclaration == null) {
        staticSet.add(stitchMethodIdentifier(childMethodElement));
        return;
    }
    ExecutableElement parentMethodElement = parentMethodDeclaration.getExecutableElement();
    handleParentMethod(parentMethodElement, childMethodElement);
}
Also used : MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 4 with MethodDeclaration

use of com.google.devtools.j2objc.ast.MethodDeclaration in project j2objc by google.

the class Functionizer method determineFunctionizableMethods.

/**
   * Determines the set of methods to functionize. In addition to a method being
   * final we must also find an invocation for that method. Static methods, though,
   * are always functionized since there are no dynamic dispatch issues.
   */
private Set<ExecutableElement> determineFunctionizableMethods(final CompilationUnit unit) {
    final Set<ExecutableElement> functionizableDeclarations = Sets.newHashSet();
    final Set<ExecutableElement> invocations = Sets.newHashSet();
    unit.accept(new TreeVisitor() {

        @Override
        public void endVisit(MethodDeclaration node) {
            if (canFunctionize(node)) {
                functionizableDeclarations.add(node.getExecutableElement());
            }
        }

        @Override
        public void endVisit(MethodInvocation node) {
            invocations.add(node.getExecutableElement());
        }
    });
    return Sets.intersection(functionizableDeclarations, invocations);
}
Also used : TreeVisitor(com.google.devtools.j2objc.ast.TreeVisitor) UnitTreeVisitor(com.google.devtools.j2objc.ast.UnitTreeVisitor) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 5 with MethodDeclaration

use of com.google.devtools.j2objc.ast.MethodDeclaration in project j2objc by google.

the class JavaToIOSMethodTranslator method addCopyWithZoneMethod.

private void addCopyWithZoneMethod(TypeDeclaration node) {
    // Create copyWithZone: method.
    GeneratedExecutableElement copyElement = GeneratedExecutableElement.newMethodWithSelector("copyWithZone:", TypeUtil.ID_TYPE, node.getTypeElement());
    MethodDeclaration copyDecl = new MethodDeclaration(copyElement);
    copyDecl.setHasDeclaration(false);
    // Add NSZone *zone parameter.
    VariableElement zoneParam = GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
    copyElement.addParameter(zoneParam);
    copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
    Block block = new Block();
    copyDecl.setBody(block);
    ExecutableElement cloneElement = ElementUtil.findMethod(typeUtil.getJavaObject(), "clone");
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(cloneElement), null);
    if (options.useReferenceCounting()) {
        invocation = new MethodInvocation(new ExecutablePair(RETAIN_METHOD), invocation);
    }
    block.addStatement(new ReturnStatement(invocation));
    node.addBodyDeclaration(copyDecl);
}
Also used : GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) MethodDeclaration(com.google.devtools.j2objc.ast.MethodDeclaration) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) Block(com.google.devtools.j2objc.ast.Block) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Aggregations

MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)41 ExecutableElement (javax.lang.model.element.ExecutableElement)23 Block (com.google.devtools.j2objc.ast.Block)20 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)19 TypeElement (javax.lang.model.element.TypeElement)12 SingleVariableDeclaration (com.google.devtools.j2objc.ast.SingleVariableDeclaration)11 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)10 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)9 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)8 NativeStatement (com.google.devtools.j2objc.ast.NativeStatement)8 VariableElement (javax.lang.model.element.VariableElement)8 TypeMirror (javax.lang.model.type.TypeMirror)7 BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)6 TreeVisitor (com.google.devtools.j2objc.ast.TreeVisitor)5 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)5 AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)4 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)4 SimpleName (com.google.devtools.j2objc.ast.SimpleName)4 Statement (com.google.devtools.j2objc.ast.Statement)4 GeneratedTypeElement (com.google.devtools.j2objc.types.GeneratedTypeElement)4