Search in sources :

Example 1 with ArrayCreation

use of com.google.devtools.j2objc.ast.ArrayCreation 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 2 with ArrayCreation

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

the class TreeConverter method convertNewArray.

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

Example 3 with ArrayCreation

use of com.google.devtools.j2objc.ast.ArrayCreation 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 4 with ArrayCreation

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

the class MethodTranslator method visitArrayCreationExpression.

@Override
public TreeNode visitArrayCreationExpression(ArrayCreationExpression node, Void data) {
    Type baseType = (Type) node.getType().acceptVisitor(this, null);
    AstNodeCollection<com.strobel.decompiler.languages.java.ast.Expression> dimexprs = node.getDimensions();
    ArrayInitializerExpression init = node.getInitializer();
    ArrayType arrayType = new ArrayType(typeUtil.getArrayType(baseType.getTypeMirror(), dimexprs.size() + node.getAdditionalArraySpecifiers().size()));
    if (init.isNull()) {
        List<Expression> dimensions = dimexprs.stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
        return new ArrayCreation().setType(arrayType).setDimensions(dimensions);
    } else {
        ArrayInitializer arrayInit = (ArrayInitializer) init.acceptVisitor(this, null);
        return new ArrayCreation().setType(arrayType).setInitializer(arrayInit.setTypeMirror(arrayType.getTypeMirror()));
    }
}
Also used : ArrayType(com.google.devtools.j2objc.ast.ArrayType) ComposedType(com.strobel.decompiler.languages.java.ast.ComposedType) TranslationUtil(com.google.devtools.j2objc.util.TranslationUtil) SuperReferenceExpression(com.strobel.decompiler.languages.java.ast.SuperReferenceExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) TypeElement(javax.lang.model.element.TypeElement) AnonymousObjectCreationExpression(com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression) AstType(com.strobel.decompiler.languages.java.ast.AstType) Expression(com.google.devtools.j2objc.ast.Expression) ExpressionStatement(com.google.devtools.j2objc.ast.ExpressionStatement) ForStatement(com.google.devtools.j2objc.ast.ForStatement) Assignment(com.google.devtools.j2objc.ast.Assignment) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement) BlockStatement(com.strobel.decompiler.languages.java.ast.BlockStatement) Map(java.util.Map) ElementUtil(com.google.devtools.j2objc.util.ElementUtil) BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) ClassInstanceCreation(com.google.devtools.j2objc.ast.ClassInstanceCreation) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TranslationEnvironment(com.google.devtools.j2objc.util.TranslationEnvironment) TryCatchStatement(com.strobel.decompiler.languages.java.ast.TryCatchStatement) Element(javax.lang.model.element.Element) TypeReferenceExpression(com.strobel.decompiler.languages.java.ast.TypeReferenceExpression) ContinueStatement(com.google.devtools.j2objc.ast.ContinueStatement) IfElseStatement(com.strobel.decompiler.languages.java.ast.IfElseStatement) UnaryOperatorExpression(com.strobel.decompiler.languages.java.ast.UnaryOperatorExpression) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) CaseLabel(com.strobel.decompiler.languages.java.ast.CaseLabel) ImportDeclaration(com.strobel.decompiler.languages.java.ast.ImportDeclaration) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) Type(com.google.devtools.j2objc.ast.Type) BinaryOperatorExpression(com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression) TreeUtil(com.google.devtools.j2objc.ast.TreeUtil) TreeNode(com.google.devtools.j2objc.ast.TreeNode) ConstructorInvocation(com.google.devtools.j2objc.ast.ConstructorInvocation) VariableElement(javax.lang.model.element.VariableElement) VariableDeclarationFragment(com.google.devtools.j2objc.ast.VariableDeclarationFragment) IAstVisitor(com.strobel.decompiler.languages.java.ast.IAstVisitor) ArrayList(java.util.ArrayList) SimpleType(com.google.devtools.j2objc.ast.SimpleType) DoStatement(com.google.devtools.j2objc.ast.DoStatement) InstanceInitializer(com.strobel.decompiler.languages.java.ast.InstanceInitializer) FieldAccess(com.google.devtools.j2objc.ast.FieldAccess) DeclaredType(javax.lang.model.type.DeclaredType) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) WhileStatement(com.google.devtools.j2objc.ast.WhileStatement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) ClassOfExpression(com.strobel.decompiler.languages.java.ast.ClassOfExpression) VariableInitializer(com.strobel.decompiler.languages.java.ast.VariableInitializer) TypeReference(com.strobel.assembler.metadata.TypeReference) ArrayAccess(com.google.devtools.j2objc.ast.ArrayAccess) Block(com.google.devtools.j2objc.ast.Block) Statement(com.google.devtools.j2objc.ast.Statement) ThisReferenceExpression(com.strobel.decompiler.languages.java.ast.ThisReferenceExpression) AssignmentExpression(com.strobel.decompiler.languages.java.ast.AssignmentExpression) Pattern(com.strobel.decompiler.patterns.Pattern) ArrayType(com.google.devtools.j2objc.ast.ArrayType) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) GotoStatement(com.strobel.decompiler.languages.java.ast.GotoStatement) ParameterDeclaration(com.strobel.decompiler.languages.java.ast.ParameterDeclaration) PrimitiveExpression(com.strobel.decompiler.languages.java.ast.PrimitiveExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) MemberReferenceExpression(com.strobel.decompiler.languages.java.ast.MemberReferenceExpression) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ObjectCreationExpression(com.strobel.decompiler.languages.java.ast.ObjectCreationExpression) InvocationExpression(com.strobel.decompiler.languages.java.ast.InvocationExpression) DoWhileStatement(com.strobel.decompiler.languages.java.ast.DoWhileStatement) AstNodeCollection(com.strobel.decompiler.languages.java.ast.AstNodeCollection) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) ArrayCreationExpression(com.strobel.decompiler.languages.java.ast.ArrayCreationExpression) Collectors(java.util.stream.Collectors) List(java.util.List) MethodGroupExpression(com.strobel.decompiler.languages.java.ast.MethodGroupExpression) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer) IdentifierExpression(com.strobel.decompiler.languages.java.ast.IdentifierExpression) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration) ErrorUtil(com.google.devtools.j2objc.util.ErrorUtil) AstNode(com.strobel.decompiler.languages.java.ast.AstNode) EnumValueDeclaration(com.strobel.decompiler.languages.java.ast.EnumValueDeclaration) NewLineNode(com.strobel.decompiler.languages.java.ast.NewLineNode) HashSet(java.util.HashSet) IndexerExpression(com.strobel.decompiler.languages.java.ast.IndexerExpression) WildcardType(com.strobel.decompiler.languages.java.ast.WildcardType) TextNode(com.strobel.decompiler.languages.java.ast.TextNode) StringUtilities(com.strobel.core.StringUtilities) Keys(com.strobel.decompiler.languages.java.ast.Keys) IfStatement(com.google.devtools.j2objc.ast.IfStatement) NullLiteral(com.google.devtools.j2objc.ast.NullLiteral) ElementKind(javax.lang.model.element.ElementKind) ExecutableType(javax.lang.model.type.ExecutableType) ArraySpecifier(com.strobel.decompiler.languages.java.ast.ArraySpecifier) SwitchSection(com.strobel.decompiler.languages.java.ast.SwitchSection) TypeParameterDeclaration(com.strobel.decompiler.languages.java.ast.TypeParameterDeclaration) NullReferenceExpression(com.strobel.decompiler.languages.java.ast.NullReferenceExpression) ExecutableElement(javax.lang.model.element.ExecutableElement) ConstructorDeclaration(com.strobel.decompiler.languages.java.ast.ConstructorDeclaration) ArrayInitializerExpression(com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression) JavaTokenNode(com.strobel.decompiler.languages.java.ast.JavaTokenNode) Consumer(java.util.function.Consumer) ReturnStatement(com.google.devtools.j2objc.ast.ReturnStatement) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) MethodReference(com.strobel.assembler.metadata.MethodReference) TypeMirror(javax.lang.model.type.TypeMirror) SourcePosition(com.google.devtools.j2objc.ast.SourcePosition) ArrayCreation(com.google.devtools.j2objc.ast.ArrayCreation) TypeUtil(com.google.devtools.j2objc.util.TypeUtil) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) ForEachStatement(com.strobel.decompiler.languages.java.ast.ForEachStatement) ComposedType(com.strobel.decompiler.languages.java.ast.ComposedType) AstType(com.strobel.decompiler.languages.java.ast.AstType) Type(com.google.devtools.j2objc.ast.Type) SimpleType(com.google.devtools.j2objc.ast.SimpleType) DeclaredType(javax.lang.model.type.DeclaredType) ArrayType(com.google.devtools.j2objc.ast.ArrayType) WildcardType(com.strobel.decompiler.languages.java.ast.WildcardType) ExecutableType(javax.lang.model.type.ExecutableType) SuperReferenceExpression(com.strobel.decompiler.languages.java.ast.SuperReferenceExpression) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) AnonymousObjectCreationExpression(com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression) Expression(com.google.devtools.j2objc.ast.Expression) TypeReferenceExpression(com.strobel.decompiler.languages.java.ast.TypeReferenceExpression) UnaryOperatorExpression(com.strobel.decompiler.languages.java.ast.UnaryOperatorExpression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) BinaryOperatorExpression(com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression) ClassOfExpression(com.strobel.decompiler.languages.java.ast.ClassOfExpression) ThisReferenceExpression(com.strobel.decompiler.languages.java.ast.ThisReferenceExpression) AssignmentExpression(com.strobel.decompiler.languages.java.ast.AssignmentExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) PrimitiveExpression(com.strobel.decompiler.languages.java.ast.PrimitiveExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) MemberReferenceExpression(com.strobel.decompiler.languages.java.ast.MemberReferenceExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ObjectCreationExpression(com.strobel.decompiler.languages.java.ast.ObjectCreationExpression) InvocationExpression(com.strobel.decompiler.languages.java.ast.InvocationExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) ArrayCreationExpression(com.strobel.decompiler.languages.java.ast.ArrayCreationExpression) MethodGroupExpression(com.strobel.decompiler.languages.java.ast.MethodGroupExpression) IdentifierExpression(com.strobel.decompiler.languages.java.ast.IdentifierExpression) IndexerExpression(com.strobel.decompiler.languages.java.ast.IndexerExpression) NullReferenceExpression(com.strobel.decompiler.languages.java.ast.NullReferenceExpression) ArrayInitializerExpression(com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) ArrayCreation(com.google.devtools.j2objc.ast.ArrayCreation) ArrayInitializerExpression(com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Example 5 with ArrayCreation

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

the class VarargsRewriter method rewriteVarargs.

private void rewriteVarargs(ExecutableElement method, TypeMirror varargsType, List<Expression> args) {
    if (varargsType == null) {
        return;
    }
    varargsType = typeUtil.erasure(varargsType);
    int numRegularParams = method.getParameters().size() - 1;
    List<Expression> varargs = args.subList(numRegularParams, args.size());
    List<Expression> varargsCopy = Lists.newArrayList(varargs);
    varargs.clear();
    if (varargsCopy.isEmpty()) {
        args.add(new ArrayCreation(typeUtil.getArrayType(varargsType), typeUtil, 0));
    } else {
        ArrayInitializer newInit = new ArrayInitializer(typeUtil.getArrayType(varargsType));
        newInit.getExpressions().addAll(varargsCopy);
        args.add(new ArrayCreation(newInit));
    }
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) ArrayCreation(com.google.devtools.j2objc.ast.ArrayCreation) ArrayInitializer(com.google.devtools.j2objc.ast.ArrayInitializer)

Aggregations

ArrayCreation (com.google.devtools.j2objc.ast.ArrayCreation)7 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)5 Expression (com.google.devtools.j2objc.ast.Expression)5 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)4 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)4 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)4 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)4 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)4 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)4 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)4 ArrayList (java.util.ArrayList)4 ArrayType (com.google.devtools.j2objc.ast.ArrayType)3 CastExpression (com.google.devtools.j2objc.ast.CastExpression)3 FunctionalExpression (com.google.devtools.j2objc.ast.FunctionalExpression)3 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)3 LambdaExpression (com.google.devtools.j2objc.ast.LambdaExpression)3 AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)1 ArrayAccess (com.google.devtools.j2objc.ast.ArrayAccess)1 Assignment (com.google.devtools.j2objc.ast.Assignment)1 Block (com.google.devtools.j2objc.ast.Block)1