@@ -454,7 +454,7 @@ public Node visit(ClassExpression nd, Void v) {
454454
455455 @ Override
456456 public Node visit (ClassBody nd , Void v ) {
457- for (MemberDefinition <?> m : nd .getBody ()) {
457+ for (Node m : nd .getBody ()) {
458458 if (m instanceof MethodDefinition ) {
459459 Node first = m .accept (this , v );
460460 if (first != null ) return first ;
@@ -1163,10 +1163,14 @@ public Void visit(ClassExpression nd, SuccessorInfo i) {
11631163 private Map <Expression , AClass > constructor2Class = new LinkedHashMap <>();
11641164
11651165 private Void visit (Node nd , AClass ac , SuccessorInfo i ) {
1166- for (MemberDefinition <?> m : ac .getBody ().getBody ())
1167- if (m .isConstructor () && m .isConcrete ()) constructor2Class .put (m .getValue (), ac );
1166+ for (Node m : ac .getBody ().getBody ()) {
1167+ if (m instanceof MemberDefinition ) {
1168+ MemberDefinition md = (MemberDefinition ) m ;
1169+ if (md .isConstructor () && md .isConcrete ()) constructor2Class .put (md .getValue (), ac );
1170+ }
1171+ }
11681172 visitSequence (ac .getId (), ac .getSuperClass (), ac .getBody (), nd );
1169- writeSuccessors (nd , visitSequence (getStaticFields (ac .getBody ()), getDecoratorsOfClass (ac ), i .getAllSuccessors ()));
1173+ writeSuccessors (nd , visitSequence (getStaticInitializers (ac .getBody ()), getDecoratorsOfClass (ac ), i .getAllSuccessors ()));
11701174 return null ;
11711175 }
11721176
@@ -1203,15 +1207,18 @@ private List<Node> getDecoratorsOfClass(AClass ac) {
12031207 List <Node > staticDecorators = new ArrayList <>();
12041208 List <Node > constructorParameterDecorators = new ArrayList <>();
12051209 List <Node > classDecorators = (List <Node >)(List <?>)ac .getDecorators ();
1206- for (MemberDefinition <?> member : ac .getBody ().getBody ()) {
1207- if (!member .isConcrete ()) continue ;
1208- List <Node > decorators = getMemberDecorators (member );
1209- if (member .isConstructor ()) {
1210- constructorParameterDecorators .addAll (decorators );
1211- } else if (member .isStatic ()) {
1212- staticDecorators .addAll (decorators );
1213- } else {
1214- instanceDecorators .addAll (decorators );
1210+ for (Node memberNode : ac .getBody ().getBody ()) {
1211+ if (memberNode instanceof MemberDefinition ) {
1212+ MemberDefinition <?> member = (MemberDefinition <?>) memberNode ;
1213+ if (!member .isConcrete ()) continue ;
1214+ List <Node > decorators = getMemberDecorators (member );
1215+ if (member .isConstructor ()) {
1216+ constructorParameterDecorators .addAll (decorators );
1217+ } else if (member .isStatic ()) {
1218+ staticDecorators .addAll (decorators );
1219+ } else {
1220+ instanceDecorators .addAll (decorators );
1221+ }
12151222 }
12161223 }
12171224 List <Node > result = new ArrayList <>();
@@ -1612,25 +1619,32 @@ public Void visit(ClassBody nd, SuccessorInfo i) {
16121619
16131620 private List <MemberDefinition <?>> getMethods (ClassBody nd ) {
16141621 List <MemberDefinition <?>> mds = new ArrayList <>();
1615- for (MemberDefinition <?> md : nd .getBody ()) {
1616- if (md instanceof MethodDefinition ) mds .add (md );
1622+ for (Node md : nd .getBody ()) {
1623+ if (md instanceof MethodDefinition ) mds .add (( MemberDefinition <?>) md );
16171624 }
16181625 return mds ;
16191626 }
16201627
1621- private List <MemberDefinition <?>> getStaticFields (ClassBody nd ) {
1622- List <MemberDefinition <?>> mds = new ArrayList <>();
1623- for (MemberDefinition <?> md : nd .getBody ()) {
1624- if (md instanceof FieldDefinition && md .isStatic ()) mds .add (md );
1628+ /**
1629+ * Gets the static fields, and static initializer blocks, from `nd`.
1630+ */
1631+ private List <Node > getStaticInitializers (ClassBody nd ) {
1632+ List <Node > nodes = new ArrayList <>();
1633+ for (Node node : nd .getBody ()) {
1634+ if (node instanceof FieldDefinition && ((FieldDefinition )node ).isStatic ()) nodes .add (node );
1635+ if (node instanceof BlockStatement ) nodes .add (node );
16251636 }
1626- return mds ;
1637+ return nodes ;
16271638 }
16281639
16291640 private List <FieldDefinition > getConcreteInstanceFields (ClassBody nd ) {
16301641 List <FieldDefinition > fds = new ArrayList <>();
1631- for (MemberDefinition <?> md : nd .getBody ())
1642+ for (Node node : nd .getBody ()) {
1643+ if (!(node instanceof MemberDefinition )) continue ;
1644+ MemberDefinition <?> md = (MemberDefinition <?>)node ;
16321645 if (md instanceof FieldDefinition && !md .isStatic () && md .isConcrete ())
16331646 fds .add ((FieldDefinition ) md );
1647+ }
16341648 return fds ;
16351649 }
16361650
0 commit comments