Skip to content

Commit

Permalink
Get source ranges for module directive source ranges
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 Apr 17, 2024
1 parent fdb10de commit ab420eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,24 @@ private ProvidesDirective convert(JCProvides javac) {
private RequiresDirective convert(JCRequires javac) {
RequiresDirective res = this.ast.newRequiresDirective();
res.setName(toName(javac.getModuleName()));
int javacStart = javac.getStartPosition();
if (javac.isTransitive()) {
res.modifiers().add(this.ast.newModuleModifier(ModuleModifierKeyword.TRANSITIVE_KEYWORD));
ModuleModifier trans = this.ast.newModuleModifier(ModuleModifierKeyword.TRANSITIVE_KEYWORD);
int transStart = this.rawText.substring(javacStart).indexOf(ModuleModifierKeyword.TRANSITIVE_KEYWORD.toString());
if( transStart != -1 ) {
int trueStart = javacStart + transStart;
trans.setSourceRange(trueStart, ModuleModifierKeyword.TRANSITIVE_KEYWORD.toString().length());
}
res.modifiers().add(trans);
}
if (javac.isStatic()) {
res.modifiers().add(this.ast.newModuleModifier(ModuleModifierKeyword.STATIC_KEYWORD));
ModuleModifier stat = this.ast.newModuleModifier(ModuleModifierKeyword.STATIC_KEYWORD);
int statStart = this.rawText.substring(javacStart).indexOf(ModuleModifierKeyword.STATIC_KEYWORD.toString());
if( statStart != -1 ) {
int trueStart = javacStart + statStart;
stat.setSourceRange(trueStart, ModuleModifierKeyword.STATIC_KEYWORD.toString().length());
}
res.modifiers().add(stat);
}
commonSettings(res, javac);
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,25 @@ public void foo() {
deleteProject("P");
}
}


/**
*/
public void testModuleTransitiveDependency() throws CoreException, IOException {
try {
createJavaProject("P", new String[] {""}, new String[0],
null, null, null, null, null, true, null, "", null, null, null, "9", false);
createFile("P/module-info.java",
"""
module name {
requires transitive asdfhjkl;
}
"""
);
ICompilationUnit cuA = getCompilationUnit("P/module-info.java");
runConversion(this.testLevel, cuA, true, true, true);
} finally {
deleteProject("P");
}
}
}

0 comments on commit ab420eb

Please sign in to comment.