Search in sources :

Example 1 with AstNodeCollection

use of com.strobel.decompiler.languages.java.ast.AstNodeCollection 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) Flags(com.strobel.assembler.metadata.Flags) 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) SwitchExpression(com.strobel.decompiler.languages.java.ast.SwitchExpression) NewLineNode(com.strobel.decompiler.languages.java.ast.NewLineNode) 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) SwitchExpression(com.strobel.decompiler.languages.java.ast.SwitchExpression) 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)

Aggregations

AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)1 ArrayAccess (com.google.devtools.j2objc.ast.ArrayAccess)1 ArrayCreation (com.google.devtools.j2objc.ast.ArrayCreation)1 ArrayInitializer (com.google.devtools.j2objc.ast.ArrayInitializer)1 ArrayType (com.google.devtools.j2objc.ast.ArrayType)1 Assignment (com.google.devtools.j2objc.ast.Assignment)1 Block (com.google.devtools.j2objc.ast.Block)1 BreakStatement (com.google.devtools.j2objc.ast.BreakStatement)1 ClassInstanceCreation (com.google.devtools.j2objc.ast.ClassInstanceCreation)1 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 ConstructorInvocation (com.google.devtools.j2objc.ast.ConstructorInvocation)1 ContinueStatement (com.google.devtools.j2objc.ast.ContinueStatement)1 DoStatement (com.google.devtools.j2objc.ast.DoStatement)1 EnhancedForStatement (com.google.devtools.j2objc.ast.EnhancedForStatement)1 Expression (com.google.devtools.j2objc.ast.Expression)1 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)1 FieldAccess (com.google.devtools.j2objc.ast.FieldAccess)1 ForStatement (com.google.devtools.j2objc.ast.ForStatement)1 IfStatement (com.google.devtools.j2objc.ast.IfStatement)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1