Search in sources :

Example 1 with ThisReferenceExpression

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

the class MethodTranslator method visitInvocationExpression.

@Override
public TreeNode visitInvocationExpression(InvocationExpression node, Void data) {
    MethodReference methodDef = (MethodReference) node.getUserData(Keys.MEMBER_REFERENCE);
    com.strobel.decompiler.languages.java.ast.Expression target = node.getTarget();
    if (target instanceof SuperReferenceExpression) {
        return target.acceptVisitor(this, null);
    }
    if (target instanceof ThisReferenceExpression) {
        ThisExpression cons = (ThisExpression) target.acceptVisitor(this, null);
        TypeElement type = (TypeElement) ((DeclaredType) cons.getTypeMirror()).asElement();
        List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
        ExecutableElement sym = findConstructor(type, methodDef);
        ConstructorInvocation newNode = new ConstructorInvocation().setExecutablePair(new ExecutablePair(sym)).setArguments(args);
        return newNode;
    }
    if (target instanceof MemberReferenceExpression) {
        TypeMirror type = resolve(methodDef.getDeclaringType());
        List<Expression> args = node.getArguments().stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
        ExecutableElement sym = findMethod(methodDef.getName(), type, methodDef);
        Expression expr = (Expression) target.getFirstChild().acceptVisitor(this, null);
        MethodInvocation newNode = new MethodInvocation().setExecutablePair(new ExecutablePair(sym)).setTypeMirror(sym.getReturnType()).setArguments(args).setExpression(expr);
        return newNode;
    }
    throw new AssertionError("not implemented");
}
Also used : 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) ThisReferenceExpression(com.strobel.decompiler.languages.java.ast.ThisReferenceExpression) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) MemberReferenceExpression(com.strobel.decompiler.languages.java.ast.MemberReferenceExpression) ConstructorInvocation(com.google.devtools.j2objc.ast.ConstructorInvocation) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) 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) TypeMirror(javax.lang.model.type.TypeMirror) MethodReference(com.strobel.assembler.metadata.MethodReference) SuperReferenceExpression(com.strobel.decompiler.languages.java.ast.SuperReferenceExpression)

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