Skip to content

Commit

Permalink
incorporated the code review changes and added a new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Sep 30, 2024
1 parent 15b0112 commit 8d66756
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5483,7 +5483,7 @@ interface I {
assertEquals(1, variableElement.getSourceRange().getLength());
}

public void testSVDStartPositionIssue() throws JavaModelException {
public void testSVDStartPositionIssue_1() throws JavaModelException {
String contents = """
public class X {
public static void example() {
Expand Down Expand Up @@ -5515,4 +5515,33 @@ public static void example() {
assertEquals("Single Variable Declaration startPosition is not correct", svd.getStartPosition(), contents.indexOf("RuntimeException"));
}

public void testSVDStartPositionIssue_2() throws JavaModelException {
String contents = """
public class X {
public static void example() {
try {
System.out.println("try");
}
/** */
catch(/** abc*/ RuntimeException e) {
System.out.println("catch");
}
}
}
""";
this.workingCopy = getWorkingCopy("/Converter22/src/xyz/X.java", true/*resolve*/);
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy);
TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 0);
MethodDeclaration methodDeclaration = (MethodDeclaration) typedeclaration.bodyDeclarations().get(0);
Block block = methodDeclaration.getBody();
List<ASTNode> statements = block.statements();
TryStatement tryStatement = (TryStatement) statements.get(0);
List<ASTNode> catchClauseList = tryStatement.catchClauses();
CatchClause catchClause = (CatchClause) catchClauseList.get(0);
SingleVariableDeclaration svd = catchClause.getException();

assertEquals("Single Variable Declaration length is not correct", svd.getLength(), contents.substring(contents.indexOf("/** abc*/ RuntimeException e")).indexOf(')'));
assertEquals("Single Variable Declaration startPosition is not correct", svd.getStartPosition(), contents.indexOf("/** abc*/ RuntimeException"));
}

}

0 comments on commit 8d66756

Please sign in to comment.