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 d89974d13c6..fa145ead363 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 @@ -38,6 +38,7 @@ import org.eclipse.jdt.internal.javac.JavacProblemConverter; import com.sun.source.tree.CaseTree.CaseKind; +import com.sun.source.tree.ModuleTree.ModuleKind; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.parser.Tokens.Comment; @@ -194,6 +195,7 @@ 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); if (javac.getDirectives() != null) { List directives = javac.getDirectives(); for (int i = 0; i < directives.size(); i++) { @@ -262,6 +264,7 @@ private RequiresDirective convert(JCRequires javac) { RequiresDirective res = this.ast.newRequiresDirective(); res.setName(toName(javac.getModuleName())); int javacStart = javac.getStartPosition(); + List modifiersToAdd = new ArrayList<>(); if (javac.isTransitive()) { ModuleModifier trans = this.ast.newModuleModifier(ModuleModifierKeyword.TRANSITIVE_KEYWORD); int transStart = this.rawText.substring(javacStart).indexOf(ModuleModifierKeyword.TRANSITIVE_KEYWORD.toString()); @@ -269,7 +272,7 @@ private RequiresDirective convert(JCRequires javac) { int trueStart = javacStart + transStart; trans.setSourceRange(trueStart, ModuleModifierKeyword.TRANSITIVE_KEYWORD.toString().length()); } - res.modifiers().add(trans); + modifiersToAdd.add(trans); } if (javac.isStatic()) { ModuleModifier stat = this.ast.newModuleModifier(ModuleModifierKeyword.STATIC_KEYWORD); @@ -278,8 +281,10 @@ private RequiresDirective convert(JCRequires javac) { int trueStart = javacStart + statStart; stat.setSourceRange(trueStart, ModuleModifierKeyword.STATIC_KEYWORD.toString().length()); } - res.modifiers().add(stat); + modifiersToAdd.add(stat); } + modifiersToAdd.sort((a, b) -> ((ASTNode)a).getStartPosition() - ((ASTNode)b).getStartPosition()); + modifiersToAdd.stream().forEach(res.modifiers()::add); commonSettings(res, javac); return res; }