use of com.google.devtools.j2objc.ast.MethodInvocation in project j2objc by google.
the class CastResolver method createCastCheck.
private FunctionInvocation createCastCheck(TypeMirror type, Expression expr) {
type = typeUtil.erasure(type);
TypeMirror idType = TypeUtil.ID_TYPE;
if (TypeUtil.isInterface(type) || isObjectArray(type)) {
// Interfaces and object arrays requre a isInstance call.
FunctionElement element = new FunctionElement("cast_check", idType, null).addParameters(idType, TypeUtil.IOS_CLASS.asType());
FunctionInvocation invocation = new FunctionInvocation(element, idType);
invocation.addArgument(TreeUtil.remove(expr));
invocation.addArgument(new TypeLiteral(type, typeUtil));
return invocation;
} else if (TypeUtil.isArray(type) || TypeUtil.isDeclaredType(type)) {
// Primitive array and non-interface type casts are checked using Objective-C's
// isKindOfClass:.
TypeElement objcClass = typeUtil.getObjcClass(type);
FunctionElement checkFunction = new FunctionElement("cast_chk", idType, null).addParameters(idType, idType);
FunctionInvocation invocation = new FunctionInvocation(checkFunction, idType);
invocation.addArgument(TreeUtil.remove(expr));
ExecutableElement classElement = GeneratedExecutableElement.newMethodWithSelector("class", idType, objcClass).addModifiers(Modifier.STATIC);
MethodInvocation classInvocation = new MethodInvocation(new ExecutablePair(classElement), new SimpleName(objcClass));
invocation.addArgument(classInvocation);
return invocation;
}
return null;
}
use of com.google.devtools.j2objc.ast.MethodInvocation in project j2objc by google.
the class TreeConverter method convertMethodInvocation.
private TreeNode convertMethodInvocation(JCTree.JCMethodInvocation node) {
JCTree.JCExpression method = node.getMethodSelect();
String methodName = getMemberName(method);
ExecutableType type = (ExecutableType) method.type;
Symbol.MethodSymbol sym = (Symbol.MethodSymbol) getMemberSymbol(method);
JCTree.JCExpression target = method.getKind() == Kind.MEMBER_SELECT ? ((JCTree.JCFieldAccess) method).selected : null;
if ("this".equals(methodName)) {
ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
if ("super".equals(methodName)) {
SuperConstructorInvocation newNode = new SuperConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setVarargsType(node.varargsElement);
if (target != null) {
newNode.setExpression((Expression) convert(target));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
if (target != null && "super".equals(getMemberName(target))) {
SuperMethodInvocation newNode = new SuperMethodInvocation().setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement).setName(convertSimpleName(sym, type, getPosition(node)));
if (target.getKind() == Kind.MEMBER_SELECT) {
// foo.bar.MyClass.super.print(...):
// target: foo.bar.MyClass.super
// target.selected: foo.bar.MyClass
newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) target).selected));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode;
}
MethodInvocation newNode = new MethodInvocation();
newNode.setName(convertSimpleName(sym, type, getPosition(method)));
if (target != null) {
newNode.setExpression((Expression) convert(target));
}
for (JCTree.JCExpression arg : node.getArguments()) {
newNode.addArgument((Expression) convert(arg));
}
return newNode.setTypeMirror(node.type).setExecutablePair(new ExecutablePair(sym, type)).setVarargsType(node.varargsElement);
}
Aggregations