Search in sources :

Example 6 with PostfixExpression

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

the class OuterReferenceResolverTest method testOuterVarAccess.

public void testOuterVarAccess() {
    resolveSource("Test", "class Test { int i; class Inner { void test() { i++; } } }");
    TypeDeclaration innerNode = (TypeDeclaration) nodesByType.get(Kind.TYPE_DECLARATION).get(1);
    assertTrue(captureInfo.needsOuterReference(innerNode.getTypeElement()));
    PostfixExpression increment = (PostfixExpression) nodesByType.get(Kind.POSTFIX_EXPRESSION).get(0);
    Expression iNode = increment.getOperand();
    assertTrue(iNode instanceof QualifiedName);
    VariableElement outerVar = TreeUtil.getVariableElement(((QualifiedName) iNode).getQualifier());
    assertNotNull(outerVar);
    assertEquals("Test", outerVar.asType().toString());
}
Also used : PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) Expression(com.google.devtools.j2objc.ast.Expression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) VariableElement(javax.lang.model.element.VariableElement) TypeDeclaration(com.google.devtools.j2objc.ast.TypeDeclaration)

Aggregations

PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)6 Expression (com.google.devtools.j2objc.ast.Expression)3 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)3 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)3 VariableElement (javax.lang.model.element.VariableElement)3 Assignment (com.google.devtools.j2objc.ast.Assignment)2 Block (com.google.devtools.j2objc.ast.Block)2 CommaExpression (com.google.devtools.j2objc.ast.CommaExpression)2 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)2 SimpleName (com.google.devtools.j2objc.ast.SimpleName)2 Statement (com.google.devtools.j2objc.ast.Statement)2 TreeNode (com.google.devtools.j2objc.ast.TreeNode)2 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)2 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)2 TypeMirror (javax.lang.model.type.TypeMirror)2 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 EnhancedForStatement (com.google.devtools.j2objc.ast.EnhancedForStatement)1 EnumConstantDeclaration (com.google.devtools.j2objc.ast.EnumConstantDeclaration)1 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)1 FieldAccess (com.google.devtools.j2objc.ast.FieldAccess)1