Search in sources :

Example 36 with AbstractTypeDeclaration

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

the class InnerClassExtractorTest method testMultipleThisReferencesWithPreviousReference.

/**
 * This test differs from the last one only in the addition of another
 * 'this' reference before the anonymous class creation.
 */
public void testMultipleThisReferencesWithPreviousReference() throws IOException {
    String source = "class A { private int x = 0; " + "  interface Foo { void doSomething(); } " + "  class Inner { private int x = 1; " + "    public void blah() { " + "      A.this.x = 2; " + "      new Foo() { public void doSomething() { " + "      Inner.this.x = 3; A.this.x = 4; }}; }}}";
    CompilationUnit unit = translateType("A", source);
    List<AbstractTypeDeclaration> types = unit.getTypes();
    assertEquals(4, types.size());
    String translation = translateSourceFile(source, "A", "A.m");
    // Anonymous class constructor in Inner.blah()
    assertTranslation(translation, "create_A_Inner_1_initWithA_Inner_(self)");
    // A.x referred to in A.Inner.
    assertTranslation(translation, "this$0_->x_ = 2");
    // A.Inner.x referred to in anonymous Foo.
    assertTranslation(translation, "this$0_->x_ = 3");
    // A.x referred to in anonymous Foo
    assertTranslation(translation, "this$0_->this$0_->x_ = 4");
    // A.Inner init in anonymous Foo's constructor
    assertTranslation(translation, "JreStrongAssign(&self->this$0_, outer$)");
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Aggregations

AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)36 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)25 TypeElement (javax.lang.model.element.TypeElement)9 BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)4 VariableDeclarationFragment (com.google.devtools.j2objc.ast.VariableDeclarationFragment)4 TypeMirror (javax.lang.model.type.TypeMirror)4 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)3 TreeNode (com.google.devtools.j2objc.ast.TreeNode)3 TypeDeclaration (com.google.devtools.j2objc.ast.TypeDeclaration)3 NameTable (com.google.devtools.j2objc.util.NameTable)3 Annotation (com.google.devtools.j2objc.ast.Annotation)2 AnnotationTypeDeclaration (com.google.devtools.j2objc.ast.AnnotationTypeDeclaration)2 Block (com.google.devtools.j2objc.ast.Block)2 Comment (com.google.devtools.j2objc.ast.Comment)2 FieldDeclaration (com.google.devtools.j2objc.ast.FieldDeclaration)2 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)2 TypeDeclarationStatement (com.google.devtools.j2objc.ast.TypeDeclarationStatement)2 GeneratedTypeElement (com.google.devtools.j2objc.types.GeneratedTypeElement)2 StatementTree (com.sun.source.tree.StatementTree)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2