Skip to content

Commit

Permalink
Fix ASTRewrite issue in record & added test coverage support for java23
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Sep 24, 2024
1 parent dfef3c8 commit 8c41728
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1428,5 +1428,43 @@ public void testRecord_028() throws Exception {

}

public void testRecord_029() throws Exception {
if (checkAPILevel()) {
return;
}
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);

StringBuilder buf= new StringBuilder();
buf.append("package test1;\n");
buf.append("record Test(String name) {\n");
buf.append(" public static Builder builder() {}\n");
buf.append(" public static final class Builder {}\n");
buf.append("}\n");

ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null);

CompilationUnit astRoot= createAST(cu);
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
AST ast= astRoot.getAST();

assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
List <RecordDeclaration> methods= astRoot.types();
MethodDeclaration methodDecl= findMethodDeclaration(methods.get(0), "builder");
{
rewrite.remove(methodDecl, null);
}

String preview= evaluateRewrite(cu, rewrite);

buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("record Test(String name) {\n");
buf.append(" \n");
buf.append(" public static final class Builder {}\n");
buf.append("}\n");

assertEqualString(preview, buf.toString());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class ASTRewritingTest extends AbstractJavaModelTests {
private final static int JLS22_INTERNAL = AST.JLS22;
private final static int JLS23_INTERNAL = AST.JLS23;

private final static int JLS23_INTERNAL = AST.JLS23;

private final static int[] JLS_LEVELS = { JLS8_INTERNAL, JLS9_INTERNAL,
JLS10_INTERNAL, JLS14_INTERNAL, JLS15_INTERNAL, JLS16_INTERNAL, JLS17_INTERNAL, JLS18_INTERNAL,
JLS19_INTERNAL, JLS20_INTERNAL, JLS21_INTERNAL , JLS22_INTERNAL, JLS23_INTERNAL};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ final void addEditGroup(TextEditGroup editGroup, TextEdit edit) {
}

final TextEdit doTextRemove(int offset, int len, TextEditGroup editGroup) {
if (len == 0) {
if (len <= 0) {
return null;
}
TextEdit edit= new DeleteEdit(offset, len);
Expand Down

0 comments on commit 8c41728

Please sign in to comment.