Search in sources :

Example 1 with ObjectCreationExpression

use of com.strobel.decompiler.languages.java.ast.ObjectCreationExpression in project j2objc by google.

the class MethodTranslator method visitObjectCreationExpression.

@Override
public TreeNode visitObjectCreationExpression(ObjectCreationExpression node, Void data) {
    Type type = (Type) node.getType().acceptVisitor(this, null);
    TypeElement typeElement = (TypeElement) ((DeclaredType) type.getTypeMirror()).asElement();
    ClassInstanceCreation newNode = new ClassInstanceCreation();
    List<String> paramTypes = new ArrayList<>();
    for (com.strobel.decompiler.languages.java.ast.Expression arg : node.getArguments()) {
        Expression expr = (Expression) arg.acceptVisitor(this, null);
        newNode.addArgument(expr);
        paramTypes.add(expr.getTypeMirror().toString());
    }
    ExecutableElement constructor = ElementUtil.findConstructor(typeElement, paramTypes.toArray(new String[0]));
    return newNode.setExecutablePair(new ExecutablePair(constructor)).setType(type);
}
Also used : ClassInstanceCreation(com.google.devtools.j2objc.ast.ClassInstanceCreation) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) 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)

Aggregations

ArrayType (com.google.devtools.j2objc.ast.ArrayType)1 ClassInstanceCreation (com.google.devtools.j2objc.ast.ClassInstanceCreation)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 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)1 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 SimpleType (com.google.devtools.j2objc.ast.SimpleType)1 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)1 Type (com.google.devtools.j2objc.ast.Type)1 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)1 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)1 AnonymousObjectCreationExpression (com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression)1 ArrayCreationExpression (com.strobel.decompiler.languages.java.ast.ArrayCreationExpression)1 ArrayInitializerExpression (com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression)1 AssignmentExpression (com.strobel.decompiler.languages.java.ast.AssignmentExpression)1 AstType (com.strobel.decompiler.languages.java.ast.AstType)1 BinaryOperatorExpression (com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression)1 ClassOfExpression (com.strobel.decompiler.languages.java.ast.ClassOfExpression)1