use of com.strobel.assembler.metadata.MethodReference in project j2objc by google.
the class MethodTranslator method visitInvocationExpression.
@Override
public TreeNode visitInvocationExpression(InvocationExpression node, Void data) {
MethodReference methodDef = (MethodReference) node.getUserData(Keys.MEMBER_REFERENCE);
com.strobel.decompiler.languages.java.ast.Expression target = node.getTarget();
if (target instanceof SuperReferenceExpression) {
return target.acceptVisitor(this, null);
}
if (target instanceof ThisReferenceExpression) {
ThisExpression cons = (ThisExpression) target.acceptVisitor(this, null);
TypeElement type = (TypeElement) ((DeclaredType) cons.getTypeMirror()).asElement();
List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
ExecutableElement sym = findConstructor(type, methodDef);
ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setArguments(args);
return newNode;
}
if (target instanceof MemberReferenceExpression) {
TypeMirror type = resolve(methodDef.getDeclaringType());
List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
ExecutableElement sym = findMethod(methodDef.getName(), type, methodDef);
Expression expr = (Expression) target.getFirstChild().acceptVisitor(this, null);
MethodInvocation newNode = new MethodInvocation().setExecutablePair(new ExecutablePair(sym)).setTypeMirror(sym.getReturnType()).setArguments(args).setExpression(expr);
return newNode;
}
throw new AssertionError("not implemented");
}
Aggregations