Search in sources :

Example 1 with AstType

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

the class MethodTranslator method visitVariableDeclaration.

@Override
public TreeNode visitVariableDeclaration(com.strobel.decompiler.languages.java.ast.VariableDeclarationStatement node, Void data) {
    VariableDeclarationStatement varDecl = new VariableDeclarationStatement().setModifiers(ElementUtil.fromModifierSet(new HashSet<>(node.getModifiers())));
    AstType astType = node.getType();
    Type type = (Type) astType.acceptVisitor(this, null);
    for (VariableInitializer init : node.getVariables()) {
        Expression expr = (Expression) init.acceptVisitor(this, null);
        String varName = init.getName();
        GeneratedVariableElement elem = GeneratedVariableElement.newLocalVar(varName, type.getTypeMirror(), executableElement);
        elem.addModifiers(node.getModifiers());
        localVariableTable.put(varName, elem);
        varDecl.addFragment(new VariableDeclarationFragment(elem, expr));
    }
    return varDecl;
}
Also used : AstType(com.strobel.decompiler.languages.java.ast.AstType) 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) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) VariableDeclarationFragment(com.google.devtools.j2objc.ast.VariableDeclarationFragment) VariableDeclarationStatement(com.google.devtools.j2objc.ast.VariableDeclarationStatement) VariableInitializer(com.strobel.decompiler.languages.java.ast.VariableInitializer) HashSet(java.util.HashSet)

Example 2 with AstType

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

the class MethodTranslator method visitForEachStatement.

@Override
public TreeNode visitForEachStatement(ForEachStatement node, Void data) {
    EnhancedForStatement forStatement = new EnhancedForStatement();
    AstType astType = node.getVariableType();
    Type type = (Type) astType.acceptVisitor(this, null);
    String varName = node.getVariableName();
    GeneratedVariableElement elem = GeneratedVariableElement.newLocalVar(varName, type.getTypeMirror(), executableElement);
    elem.addModifiers(node.getVariableModifiers());
    localVariableTable.put(varName, elem);
    return forStatement.setParameter(new SingleVariableDeclaration(elem)).setExpression((Expression) node.getInExpression().acceptVisitor(this, null)).setBody((Statement) node.getEmbeddedStatement().acceptVisitor(this, null));
}
Also used : AstType(com.strobel.decompiler.languages.java.ast.AstType) 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) GeneratedVariableElement(com.google.devtools.j2objc.types.GeneratedVariableElement) 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) SingleVariableDeclaration(com.google.devtools.j2objc.ast.SingleVariableDeclaration) EnhancedForStatement(com.google.devtools.j2objc.ast.EnhancedForStatement)

Aggregations

ArrayType (com.google.devtools.j2objc.ast.ArrayType)2 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)2 Expression (com.google.devtools.j2objc.ast.Expression)2 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)2 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)2 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)2 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)2 SimpleType (com.google.devtools.j2objc.ast.SimpleType)2 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)2 Type (com.google.devtools.j2objc.ast.Type)2 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)2 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)2 AnonymousObjectCreationExpression (com.strobel.decompiler.languages.java.ast.AnonymousObjectCreationExpression)2 ArrayCreationExpression (com.strobel.decompiler.languages.java.ast.ArrayCreationExpression)2 ArrayInitializerExpression (com.strobel.decompiler.languages.java.ast.ArrayInitializerExpression)2 AssignmentExpression (com.strobel.decompiler.languages.java.ast.AssignmentExpression)2 AstType (com.strobel.decompiler.languages.java.ast.AstType)2 BinaryOperatorExpression (com.strobel.decompiler.languages.java.ast.BinaryOperatorExpression)2 ClassOfExpression (com.strobel.decompiler.languages.java.ast.ClassOfExpression)2 ComposedType (com.strobel.decompiler.languages.java.ast.ComposedType)2