diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index ab971730f4c..c2fe759c6ef 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -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; diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java index 680526c4320..f33b963c0fc 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/JavacASTConverterBugsTestJLS.java @@ -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"); + } + } }