Skip to content

Commit

Permalink
Mostly fix testBug516785_0001_since_9 - module.open must be set; flag…
Browse files Browse the repository at this point in the history
…s must be in correct order

Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed May 2, 2024
1 parent d1c89ae commit 969bca4
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<JCDirective> directives = javac.getDirectives();
for (int i = 0; i < directives.size(); i++) {
Expand Down Expand Up @@ -262,14 +264,15 @@ 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());
if( transStart != -1 ) {
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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 969bca4

Please sign in to comment.