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()));
}
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);
}
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);
}
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);
}
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);
}
Aggregations