Search in sources :

Example 66 with Expression

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

the class TreeConverter method convertMethodInvocation.

private static TreeNode convertMethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation node) {
    MethodInvocation newNode = new MethodInvocation();
    convertExpression(node, newNode);
    for (Object argument : node.arguments()) {
        newNode.addArgument((Expression) TreeConverter.convert(argument));
    }
    IMethodBinding methodBinding = node.resolveMethodBinding();
    return newNode.setExecutablePair(new ExecutablePair(BindingConverter.getExecutableElement(methodBinding), BindingConverter.getType(methodBinding))).setTypeMirror(BindingConverter.getType(node.resolveTypeBinding())).setName((SimpleName) TreeConverter.convert(node.getName())).setExpression((Expression) TreeConverter.convert(node.getExpression())).setVarargsType(getVarargsType(methodBinding, node.arguments()));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation)

Example 67 with Expression

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

the class TreeConverter method convertClassInstanceCreation.

private static TreeNode convertClassInstanceCreation(org.eclipse.jdt.core.dom.ClassInstanceCreation node) {
    ClassInstanceCreation newNode = new ClassInstanceCreation();
    convertExpression(node, newNode);
    for (Object argument : node.arguments()) {
        newNode.addArgument((Expression) TreeConverter.convert(argument));
    }
    IMethodBinding binding = node.resolveConstructorBinding();
    JdtExecutableElement element = (JdtExecutableElement) BindingConverter.getExecutableElement(binding);
    JdtExecutableType type = BindingConverter.getType(binding);
    newNode.setExecutablePair(new ExecutablePair(element, type)).setVarargsType(getVarargsType(binding, node.arguments())).setType((Type) TreeConverter.convert(node.getType()));
    Expression expression = (Expression) TreeConverter.convert(node.getExpression());
    org.eclipse.jdt.core.dom.AnonymousClassDeclaration anonymousClassDecl = node.getAnonymousClassDeclaration();
    if (anonymousClassDecl != null && expression != null) {
        VariableElement superOuterParam = GeneratedVariableElement.newParameter("superOuter$", expression.getTypeMirror(), element);
        element.setSuperOuterParam(superOuterParam);
        type.setSuperOuterParamType(superOuterParam.asType());
        newNode.addArgument(0, expression);
    } else {
        newNode.setExpression(expression);
    }
    if (anonymousClassDecl != null) {
        newNode.setAnonymousClassDeclaration(convertAnonymousClassDeclaration(anonymousClassDecl, element, binding));
    }
    return newNode;
}
Also used : ClassInstanceCreation(com.google.devtools.j2objc.ast.ClassInstanceCreation) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) VariableElement(javax.lang.model.element.VariableElement) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement)

Example 68 with Expression

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

the class TreeConverter method convertArrayCreation.

private static TreeNode convertArrayCreation(org.eclipse.jdt.core.dom.ArrayCreation node) {
    ArrayCreation newNode = new ArrayCreation();
    convertExpression(node, newNode);
    List<Expression> dimensions = new ArrayList<>();
    for (Object dimension : node.dimensions()) {
        dimensions.add((Expression) convert(dimension));
    }
    return newNode.setType((ArrayType) convert(node.getType())).setDimensions(dimensions).setInitializer((ArrayInitializer) convert(node.getInitializer()));
}
Also used : PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) ArrayCreation(com.google.devtools.j2objc.ast.ArrayCreation) ArrayList(java.util.ArrayList)

Example 69 with Expression

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

the class TreeConverter method convertArrayInitializer.

private static TreeNode convertArrayInitializer(org.eclipse.jdt.core.dom.ArrayInitializer node) {
    List<Expression> expressions = new ArrayList<>();
    for (Object expression : node.expressions()) {
        expressions.add((Expression) convert(expression));
    }
    ArrayInitializer newNode = new ArrayInitializer();
    convertExpression(node, newNode);
    return newNode.setTypeMirror((JdtArrayType) BindingConverter.getType(node.resolveTypeBinding())).setExpressions(expressions);
}
Also used : PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) ArrayList(java.util.ArrayList) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 70 with Expression

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

the class Functionizer method endVisit.

@Override
public void endVisit(MethodInvocation node) {
    ExecutableElement element = node.getExecutableElement();
    if (!ElementUtil.isStatic(element) && !functionizableMethods.contains(element)) {
        return;
    }
    FunctionInvocation functionInvocation = new FunctionInvocation(newFunctionElement(element), node.getTypeMirror());
    List<Expression> args = functionInvocation.getArguments();
    TreeUtil.moveList(node.getArguments(), args);
    if (!ElementUtil.isStatic(element)) {
        Expression expr = node.getExpression();
        if (expr == null) {
            expr = new ThisExpression(TreeUtil.getEnclosingTypeElement(node).asType());
        }
        args.add(0, TreeUtil.remove(expr));
    }
    node.replaceWith(functionInvocation);
}
Also used : ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionInvocation(com.google.devtools.j2objc.ast.FunctionInvocation) Expression(com.google.devtools.j2objc.ast.Expression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) GeneratedExecutableElement(com.google.devtools.j2objc.types.GeneratedExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Aggregations

Expression (com.google.devtools.j2objc.ast.Expression)139 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)103 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)95 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)89 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)78 CastExpression (com.google.devtools.j2objc.ast.CastExpression)70 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)70 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)64 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)58 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)45 TypeMirror (javax.lang.model.type.TypeMirror)41 VariableElement (javax.lang.model.element.VariableElement)40 LambdaExpression (com.google.devtools.j2objc.ast.LambdaExpression)36 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)34 SimpleName (com.google.devtools.j2objc.ast.SimpleName)29 FunctionalExpression (com.google.devtools.j2objc.ast.FunctionalExpression)24 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)22 NativeExpression (com.google.devtools.j2objc.ast.NativeExpression)22 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)22 TypeElement (javax.lang.model.element.TypeElement)21