Skip to content

Commit

Permalink
Fix for #1603: adjust offsets of qualified types in throws clause
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 3, 2024
1 parent 142f93f commit a19a517
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,20 @@ protected void throwsList(AST node, List<ClassNode> list) {
} else {
name = identifier(node);
}
/* GRECLIPSE edit
ClassNode exception = ClassHelper.make(name);
*/
ClassNode exception = makeClassNode(name);
// GRECLIPSE end
configureAST(exception, node);
// GRECLIPSE add
if (isType(DOT, node)) {
GroovySourceAST type = (GroovySourceAST) node.getFirstChild().getNextSibling();
exception.setNameStart2(locations.findOffset(type.getLine(), type.getColumn()));
exception.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
exception.setLastLineNumber(type.getLineLast()); exception.setLastColumnNumber(type.getColumnLast());
}
// GRECLIPSE end
list.add(exception);
AST next = node.getNextSibling();
if (next != null) throwsList(next, list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,20 @@ protected void throwsList(AST node, List<ClassNode> list) {
} else {
name = identifier(node);
}
/* GRECLIPSE edit
ClassNode exception = ClassHelper.make(name);
*/
ClassNode exception = makeClassNode(name);
// GRECLIPSE end
configureAST(exception, node);
// GRECLIPSE add
if (isType(DOT, node)) {
GroovySourceAST type = (GroovySourceAST) node.getFirstChild().getNextSibling();
exception.setNameStart2(locations.findOffset(type.getLine(), type.getColumn()));
exception.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
exception.setLastLineNumber(type.getLineLast()); exception.setLastColumnNumber(type.getColumnLast());
}
// GRECLIPSE end
list.add(exception);
AST next = node.getNextSibling();
if (next != null) throwsList(next, list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,20 @@ protected void throwsList(AST node, List<ClassNode> list) {
} else {
name = identifier(node);
}
/* GRECLIPSE edit
ClassNode exception = ClassHelper.make(name);
*/
ClassNode exception = makeClassNode(name);
// GRECLIPSE end
configureAST(exception, node);
// GRECLIPSE add
if (isType(DOT, node)) {
var type = (GroovySourceAST) node.getFirstChild().getNextSibling();
exception.setNameStart2(locations.findOffset(type.getLine(), type.getColumn()));
exception.setEnd(locations.findOffset(type.getLineLast(), type.getColumnLast()));
exception.setLastLineNumber(type.getLineLast()); exception.setLastColumnNumber(type.getColumnLast());
}
// GRECLIPSE end
list.add(exception);
AST next = node.getNextSibling();
if (next != null) throwsList(next, list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5268,6 +5268,19 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
new HighlightedTypedPosition(contents.indexOf('String'), 6, CLASS))
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1603
void testQualifiedType9() {
String contents = '''\
|def foo() throws java.lang.Exception , java.lang.Throwable {
|}
|'''.stripMargin()

assertHighlighting(contents,
new HighlightedTypedPosition(contents.indexOf('foo'), 3, METHOD),
new HighlightedTypedPosition(contents.indexOf('Exception'), 9, CLASS),
new HighlightedTypedPosition(contents.indexOf('Throwable'), 9, CLASS))
}

@Test
void testSwitch1() {
assumeTrue(isParrotParser() && isAtLeastGroovy(40))
Expand Down

0 comments on commit a19a517

Please sign in to comment.