Search in sources :

Example 1 with Expression

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

the class TreeConverter method convertAssignOp.

private TreeNode convertAssignOp(JCTree.JCAssignOp node) {
    Assignment newNode = new Assignment();
    String operatorName = node.getOperator().getSimpleName().toString() + "=";
    return newNode.setOperator(Assignment.Operator.fromJdtOperatorName(operatorName)).setLeftHandSide((Expression) convert(node.getVariable())).setRightHandSide((Expression) convert(node.getExpression()));
}
Also used : Assignment(com.google.devtools.j2objc.ast.Assignment) 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)

Example 2 with Expression

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

the class TreeConverter method convertAnnotation.

private TreeNode convertAnnotation(JCTree.JCAnnotation node) {
    List<JCTree.JCExpression> args = node.getArguments();
    String annotationName = node.getAnnotationType().toString();
    boolean isPropertyAnnotation = annotationName.equals(Property.class.getSimpleName()) || annotationName.equals(Property.class.getName());
    Annotation newNode;
    if (isPropertyAnnotation) {
        newNode = new PropertyAnnotation().setAnnotationMirror(node.attribute);
        if (!args.isEmpty()) {
            for (String attr : ElementUtil.parsePropertyAttribute(node.attribute)) {
                ((PropertyAnnotation) newNode).addAttribute(attr);
            }
        }
    } else if (args.isEmpty()) {
        newNode = new MarkerAnnotation().setAnnotationMirror(node.attribute);
    } else if (args.size() == 1) {
        JCTree.JCAssign assign = (JCTree.JCAssign) args.get(0);
        newNode = new SingleMemberAnnotation().setValue((Expression) convert(assign.rhs));
    } else {
        NormalAnnotation normalAnn = new NormalAnnotation();
        for (JCTree.JCExpression obj : node.getArguments()) {
            JCTree.JCAssign assign = (JCTree.JCAssign) obj;
            Symbol sym = ((JCTree.JCIdent) assign.lhs).sym;
            MemberValuePair memberPair = new MemberValuePair().setName(convertSimpleName(sym, sym.asType(), getPosition(assign.lhs))).setValue((Expression) convert(assign.rhs));
            normalAnn.addValue(memberPair);
        }
        newNode = normalAnn;
    }
    return newNode.setAnnotationMirror(node.attribute).setTypeName((Name) convert(node.getAnnotationType()));
}
Also used : JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) SingleMemberAnnotation(com.google.devtools.j2objc.ast.SingleMemberAnnotation) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) JCTree(com.sun.tools.javac.tree.JCTree) NormalAnnotation(com.google.devtools.j2objc.ast.NormalAnnotation) PropertyAnnotation(com.google.devtools.j2objc.ast.PropertyAnnotation) Annotation(com.google.devtools.j2objc.ast.Annotation) SingleMemberAnnotation(com.google.devtools.j2objc.ast.SingleMemberAnnotation) MarkerAnnotation(com.google.devtools.j2objc.ast.MarkerAnnotation) PropertyAnnotation(com.google.devtools.j2objc.ast.PropertyAnnotation) MarkerAnnotation(com.google.devtools.j2objc.ast.MarkerAnnotation) MemberValuePair(com.google.devtools.j2objc.ast.MemberValuePair) 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) NormalAnnotation(com.google.devtools.j2objc.ast.NormalAnnotation)

Example 3 with Expression

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

the class TreeConverter method convertNewArray.

private TreeNode convertNewArray(JCTree.JCNewArray node) {
    ArrayCreation newNode = new ArrayCreation();
    List<Expression> dimensions = new ArrayList<>();
    for (JCTree.JCExpression dimension : node.getDimensions()) {
        dimensions.add((Expression) convert(dimension));
    }
    javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) node.type;
    if (node.getInitializers() != null) {
        ArrayInitializer initializers = new ArrayInitializer(type);
        for (JCTree.JCExpression initializer : node.getInitializers()) {
            initializers.addExpression((Expression) convert(initializer));
        }
        newNode.setInitializer(initializers);
    }
    return newNode.setType((ArrayType) new ArrayType(type).setPosition(getPosition(node))).setDimensions(dimensions);
}
Also used : ArrayList(java.util.ArrayList) JCTree(com.sun.tools.javac.tree.JCTree) ArrayType(com.google.devtools.j2objc.ast.ArrayType) 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) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 4 with Expression

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

the class TranslationUtil method createAnnotationValue.

public Expression createAnnotationValue(TypeMirror type, AnnotationValue aValue) {
    Object value = aValue.getValue();
    if (value == null) {
        return new NullLiteral(typeUtil.getNull());
    } else if (value instanceof VariableElement) {
        return new SimpleName((VariableElement) value);
    } else if (TypeUtil.isArray(type)) {
        assert value instanceof List;
        ArrayType arrayType = (ArrayType) type;
        @SuppressWarnings("unchecked") List<? extends AnnotationValue> list = (List<? extends AnnotationValue>) value;
        List<Expression> generatedValues = new ArrayList<>();
        for (AnnotationValue elem : list) {
            generatedValues.add(createAnnotationValue(arrayType.getComponentType(), elem));
        }
        return createObjectArray(generatedValues, arrayType);
    } else if (TypeUtil.isAnnotation(type)) {
        assert value instanceof AnnotationMirror;
        return createAnnotation((AnnotationMirror) value);
    } else if (value instanceof TypeMirror) {
        return new TypeLiteral((TypeMirror) value, typeUtil);
    } else {
        // Boolean, Character, Number, String
        return TreeUtil.newLiteral(value, typeUtil);
    }
}
Also used : SimpleName(com.google.devtools.j2objc.ast.SimpleName) ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement) ArrayType(javax.lang.model.type.ArrayType) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) 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) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) NullLiteral(com.google.devtools.j2objc.ast.NullLiteral)

Example 5 with Expression

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

the class TreeConverter method convertExpressionMethodReference.

private static TreeNode convertExpressionMethodReference(org.eclipse.jdt.core.dom.ExpressionMethodReference node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    ExpressionMethodReference newNode = new ExpressionMethodReference();
    Expression expression = (Expression) convert(node.getExpression());
    boolean consumesFirstParam = !BindingUtil.isStatic(methodBinding) && expression instanceof Name && !ElementUtil.isVariable(((Name) expression).getElement());
    convertMethodReference(node, newNode, methodBinding, consumesFirstParam);
    return newNode.setName((SimpleName) TreeConverter.convert(node.getName())).setExpression(expression);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExpressionMethodReference(com.google.devtools.j2objc.ast.ExpressionMethodReference) 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) SimpleName(com.google.devtools.j2objc.ast.SimpleName) SimpleName(com.google.devtools.j2objc.ast.SimpleName) Name(com.google.devtools.j2objc.ast.Name) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName)

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