Skip to content

Commit

Permalink
Missing anonymous body to enum declarations
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed Apr 5, 2024
1 parent 29c5a1a commit b1d1129
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -857,17 +857,7 @@ private Expression convertExpression(JCExpression javac) {
res.setName(toName(newClass.clazz));
}
if (newClass.getClassBody() != null && newClass.getClassBody() instanceof JCClassDecl javacAnon) {
AnonymousClassDeclaration anon = this.ast.newAnonymousClassDeclaration();
commonSettings(anon, javacAnon);
if (javacAnon.getMembers() != null) {
List<JCTree> members = javacAnon.getMembers();
for( int i = 0; i < members.size(); i++ ) {
ASTNode decl = convertBodyDeclaration(members.get(i), res);
if( decl != null ) {
anon.bodyDeclarations().add(decl);
}
}
}
AnonymousClassDeclaration anon = createAnonymousClassDeclaration(javacAnon, res);
res.setAnonymousClassDeclaration(anon);
}
if (newClass.getArguments() != null) {
Expand Down Expand Up @@ -1096,6 +1086,21 @@ private Expression convertExpression(JCExpression javac) {
throw new UnsupportedOperationException("Missing support to convert '" + javac + "' of type " + javac.getClass().getSimpleName());
}

private AnonymousClassDeclaration createAnonymousClassDeclaration(JCClassDecl javacAnon, ASTNode parent) {
AnonymousClassDeclaration anon = this.ast.newAnonymousClassDeclaration();
commonSettings(anon, javacAnon);
if (javacAnon.getMembers() != null) {
List<JCTree> members = javacAnon.getMembers();
for( int i = 0; i < members.size(); i++ ) {
ASTNode decl = convertBodyDeclaration(members.get(i), parent);
if( decl != null ) {
anon.bodyDeclarations().add(decl);
}
}
}
return anon;
}

private int countDimensions(JCArrayTypeTree tree) {
int ret = 0;
JCTree elem = tree;
Expand Down Expand Up @@ -1836,6 +1841,12 @@ private EnumConstantDeclaration convertEnumConstantDeclaration(JCTree var, ASTNo
enumConstantDeclaration.setSourceRange(start, end-start);
enumConstantDeclaration.setName(typeName);
}
if( enumConstant.init instanceof JCNewClass jcnc && jcnc.def instanceof JCClassDecl jccd) {
AnonymousClassDeclaration e = createAnonymousClassDeclaration(jccd, enumConstantDeclaration);
if( e != null ) {
enumConstantDeclaration.setAnonymousClassDeclaration(e);
}
}
}
}
return enumConstantDeclaration;
Expand Down

0 comments on commit b1d1129

Please sign in to comment.