Skip to content

Commit

Permalink
Since the issue is related to ASTConversion, added ASTConverter test
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Oct 15, 2024
1 parent e55e832 commit 56b6e98
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,68 @@ public void test_RecordSemicolon() throws JavaModelException {


}

public void testRecord013() throws JavaModelException {
if (!isJRE16) {
System.err.println("Test " + getName() + " requires a JRE 16");
return;
}
String code = """
record Test(String name) {
public static Builder builder() {return null;}
public static final class Builder {}
}
""";
this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
ASTNode node = buildAST(
code,
this.workingCopy);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit compilationUnit = (CompilationUnit) node;
assertProblemsSize(compilationUnit, 0);
node = ((AbstractTypeDeclaration)compilationUnit.types().get(0));
assertEquals("Not a Record Declaration", ASTNode.RECORD_DECLARATION, node.getNodeType());
RecordDeclaration record = (RecordDeclaration)node;

List<SingleVariableDeclaration> RecordComponents = record.recordComponents();
assertEquals("Not a Single Variable Declaration Declaration", ASTNode.SINGLE_VARIABLE_DECLARATION, RecordComponents.get(0).getNodeType());

List<ASTNode> bodyDeclaration = record.bodyDeclarations();
MethodDeclaration md = (MethodDeclaration) bodyDeclaration.get(0);
TypeDeclaration td = (TypeDeclaration) bodyDeclaration.get(1);
assertEquals("Not a MethodDeclaration", ASTNode.METHOD_DECLARATION, md.getNodeType());
assertEquals("Not a TypeDeclaration", ASTNode.TYPE_DECLARATION, td.getNodeType());
}

public void testClass002() throws CoreException {
if (!isJRE16) {
System.err.println("Test "+getName()+" requires a JRE 16");
return;
}
String code = """
class Test {
public static Builder builder() {return null;}
public static final class Builder {}
}
""";
this.workingCopy = getWorkingCopy("/Converter_16/src/X.java", true/*resolve*/);
ASTNode node = buildAST(
code,
this.workingCopy);
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
CompilationUnit compilationUnit = (CompilationUnit) node;
assertProblemsSize(compilationUnit, 0);
List<AbstractTypeDeclaration> types = compilationUnit.types();
assertEquals("No. of Types is not 1", types.size(), 1);
AbstractTypeDeclaration type = types.get(0);
assertTrue("type not a type", type instanceof TypeDeclaration);
TypeDeclaration typeDecl = (TypeDeclaration)type;
assertTrue("type not a class", !typeDecl.isInterface());

List<ASTNode> bodyDeclaration = typeDecl.bodyDeclarations();
MethodDeclaration md = (MethodDeclaration) bodyDeclaration.get(0);
TypeDeclaration td = (TypeDeclaration) bodyDeclaration.get(1);
assertEquals("Not a MethodDeclaration", ASTNode.METHOD_DECLARATION, md.getNodeType());
assertEquals("Not a TypeDeclaration", ASTNode.TYPE_DECLARATION, td.getNodeType());
}
}

0 comments on commit 56b6e98

Please sign in to comment.