122122import org .eclipse .jdt .core .dom .WhileStatement ;
123123import org .eclipse .jdt .core .dom .WildcardType ;
124124
125+ // BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
125126// BH 1/5/2018 -- @j2sKeep removed; refactored into one class
126127
127128// BH 12/31/2017 -- competely rewritten for no run-time ambiguities
@@ -252,7 +253,7 @@ private void setInnerGlobals(Java2ScriptVisitor parent, ASTNode node, String vis
252253 global_includes = parent .global_includes ;
253254 global_j2sFlag_isDebugging = parent .global_j2sFlag_isDebugging ;
254255 global_mapBlockJavadoc = parent .global_mapBlockJavadoc ;
255- parentClassName = parent .getQualifiedClassName ();
256+ this$0Name = parent .getQualifiedClassName ();
256257
257258 innerTypeNode = node ;
258259 setClassName (visitorClassName );
@@ -1076,7 +1077,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
10761077 // definition in the static buffer and return
10771078 String className ;
10781079 if (parent instanceof TypeDeclarationStatement ) {
1079- String anonClassName = assureQualifiedNameAllowP$ (binding . isAnonymous () || binding .isLocal ()
1080+ String anonClassName = assureQualifiedNameAllowP$ (isAnonymous || binding .isLocal ()
10801081 ? binding .getBinaryName () : binding .getQualifiedName ());
10811082 className = anonClassName .substring (anonClassName .lastIndexOf ('.' ) + 1 );
10821083 } else {
@@ -1089,6 +1090,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
10891090 tempVisitor = new Java2ScriptVisitor (); // Default visitor
10901091 }
10911092 tempVisitor .setInnerGlobals (this , node , className );
1093+
10921094 node .accept (tempVisitor );
10931095 trailingBuffer .append (tempVisitor .buffer .toString ());
10941096 return false ;
@@ -1130,11 +1132,14 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11301132
11311133 String oldClassName = null ;
11321134 String fullClassName , defaultPackageName ;
1133-
1135+ String this$0Name0 = this$0Name ;
11341136 if (isAnonymous ) {
11351137 oldClassName = typeAdapter .getClassName ();
11361138 fullClassName = getAnonymousName (binding ); // P$.Test_Enum$Planet$1
11371139 defaultPackageName = "null" ;
1140+ // anonymous classes reference their package, not their outer class in Clazz.newClass,
1141+ // so clazz.$this$0 is not assigned.
1142+ this$0Name = null ;
11381143 } else {
11391144 fullClassName = getQualifiedClassName (); // test.Test_Enum.Planet
11401145 defaultPackageName = global_PackageName ;
@@ -1468,6 +1473,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
14681473 if (isAnonymous ) {
14691474 buffer .append (")" );
14701475 typeAdapter .setClassName (oldClassName );
1476+ this$0Name = this$0Name0 ;
14711477 }
14721478 return false ;
14731479 }
@@ -1838,7 +1844,7 @@ private static final String getPrimitiveTYPE(String name) {
18381844 private int blockLevel = 0 ;
18391845 private int currentBlockForVisit = -1 ;
18401846
1841- public String parentClassName ;
1847+ public String this$0Name ;
18421848
18431849
18441850 /**
@@ -3542,7 +3548,7 @@ private void appendShortenedQualifiedName(String packageName, String name, boole
35423548 }
35433549
35443550 private String getSyntheticReference (String className ) {
3545- b$name = (className .equals (parentClassName ) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$ (null , className ) + "']" );
3551+ b$name = (className .equals (this$0Name ) ? ".this$0" : ".b$['" + assureQualifiedNameNoC$ (null , className ) + "']" );
35463552 return "this" + b$name ;
35473553 }
35483554
0 commit comments