Search in sources :

Example 1 with ParenthesizedExpression

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

the class TreeConverter method convertParenthesizedExpression.

private static TreeNode convertParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression node) {
    ParenthesizedExpression newNode = new ParenthesizedExpression();
    convertExpression(node, newNode);
    return newNode.setExpression((Expression) TreeConverter.convert(node.getExpression()));
}
Also used : ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression)

Example 2 with ParenthesizedExpression

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

the class Autoboxer method endVisit.

@Override
public void endVisit(CastExpression node) {
    TypeMirror castType = node.getTypeMirror();
    Expression expr = node.getExpression();
    TypeMirror exprType = expr.getTypeMirror();
    if (castType.getKind().isPrimitive() && !exprType.getKind().isPrimitive()) {
        if (typeUtil.isAssignable(exprType, typeUtil.getJavaNumber().asType())) {
            // Casting a Number object to a primitive, convert to value method.
            unbox(expr, (PrimitiveType) castType);
        } else {
            // Casting an object to a primitive. Convert the cast type to the wrapper
            // so that we do a proper cast check, as Java would.
            castType = typeUtil.boxedClass((PrimitiveType) castType).asType();
            node.setType(Type.newType(castType));
            boxOrUnboxExpression(expr, castType);
        }
    } else {
        boxOrUnboxExpression(expr, castType);
    }
    Expression newExpr = node.getExpression();
    if (newExpr != expr) {
        TreeNode parent = node.getParent();
        if (parent instanceof ParenthesizedExpression) {
            parent.replaceWith(TreeUtil.remove(newExpr));
        } else {
            node.replaceWith(TreeUtil.remove(newExpr));
        }
    }
}
Also used : ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) TypeMirror(javax.lang.model.type.TypeMirror) CastExpression(com.google.devtools.j2objc.ast.CastExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) Expression(com.google.devtools.j2objc.ast.Expression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) TreeNode(com.google.devtools.j2objc.ast.TreeNode)

Aggregations

ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)2 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 Expression (com.google.devtools.j2objc.ast.Expression)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 TreeNode (com.google.devtools.j2objc.ast.TreeNode)1 TypeMirror (javax.lang.model.type.TypeMirror)1