Skip to content

Commit

Permalink
Fix source range fail in testBug515875_004
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed May 2, 2024
1 parent f8a42d4 commit 5721cab
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ private PackageDeclaration convert(JCPackageDecl javac) {
private ModuleDeclaration convert(JCModuleDecl javac) {
ModuleDeclaration res = this.ast.newModuleDeclaration();
res.setName(toName(javac.getName()));
res.setOpen(javac.getModuleType() == ModuleKind.OPEN);
boolean isOpen = javac.getModuleType() == ModuleKind.OPEN;
res.setOpen(isOpen);
if (javac.getDirectives() != null) {
List<JCDirective> directives = javac.getDirectives();
for (int i = 0; i < directives.size(); i++) {
Expand All @@ -204,6 +205,21 @@ private ModuleDeclaration convert(JCModuleDecl javac) {
}
}
commonSettings(res, javac);
if( isOpen ) {
int start = res.getStartPosition();
if( !this.rawText.substring(start).trim().startsWith("open")) {
// we are open but we don't start with open... so... gotta look backwards
String prefix = this.rawText.substring(0,start);
if( prefix.trim().endsWith("open")) {
// previous token is open
int ind = new StringBuffer().append(prefix).reverse().toString().indexOf("nepo");
if( ind != -1 ) {
int gap = ind + 4;
res.setSourceRange(res.getStartPosition() - gap, res.getLength() + gap);
}
}
}
}
List<IExtendedModifier> l = convert(javac.mods, res);
res.annotations().addAll(l);
return res;
Expand Down

0 comments on commit 5721cab

Please sign in to comment.