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$)");
}
Aggregations