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 require an 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) && needsCastChk(expr, 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 SwitchRewriter method fixEnumValue.
private void fixEnumValue(SwitchStatement node) {
Expression expr = node.getExpression();
TypeMirror type = expr.getTypeMirror();
if (!TypeUtil.isEnum(type)) {
return;
}
DeclaredType enumType = typeUtil.getSuperclass(type);
ExecutablePair ordinalMethod = typeUtil.findMethod(enumType, "ordinal");
MethodInvocation invocation = new MethodInvocation(ordinalMethod, TreeUtil.remove(expr));
node.setExpression(invocation);
}
Aggregations