Skip to content

Commit

Permalink
Swith javac to Java 23
Browse files Browse the repository at this point in the history
Due to changes in javac internals this is needed in order to be able to
run on Java 23.
  • Loading branch information
akurtakov authored and mickaelistria committed Jul 10, 2024
1 parent 454ed58 commit 80d4fa3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pipeline {
}
tools {
maven 'apache-maven-latest'
jdk 'openjdk-jdk22-latest'
jdk 'openjdk-jdk23-latest'
}
stages {
stage('Build and Test') {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.javac/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-23">
<attributes>
<attribute name="module" value="true"/>
<attribute name="add-exports" value="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.compliance=23
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -12,7 +12,7 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=21
org.eclipse.jdt.core.compiler.source=23
org.eclipse.jdt.core.formatter.align_arrows_in_switch_on_columns=false
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bundle-SymbolicName: org.eclipse.jdt.core.javac;singleton:=true
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.jdt.core
Automatic-Module-Name: org.eclipse.jdt.core.javac
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=22))"
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=23))"
Import-Package: org.eclipse.jdt.core.dom
Export-Package: org.eclipse.jdt.internal.javac;x-friends:="org.eclipse.jdt.core.tests.javac",
org.eclipse.jdt.internal.javac.dom;x-friends:="org.eclipse.jdt.core.tests.javac"
3 changes: 2 additions & 1 deletion org.eclipse.jdt.core.javac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<artifactId>tycho-compiler-plugin</artifactId>
<configuration>
<deriveReleaseCompilerArgumentFromTargetLevel>false</deriveReleaseCompilerArgumentFromTargetLevel>
<compilerArgs>
<compilerId>javac</compilerId>
<compilerArgs combine.self="override">
<arg>--add-exports</arg>
<arg>java.base/java.lang=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private void attachMissingComments(CompilationUnit unit, Context context, String
@Override
protected com.sun.tools.javac.parser.Tokens.Comment processComment(int pos, int endPos, CommentStyle style) {
// workaround Java bug 9077218
if (style == CommentStyle.JAVADOC && endPos - pos <= 4) {
if (style == CommentStyle.JAVADOC_BLOCK && endPos - pos <= 4) {
style = CommentStyle.BLOCK;
}
var res = super.processComment(pos, endPos, style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.parser.Tokens.Comment;
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
import com.sun.tools.javac.tree.DCTree.DCDocComment;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotatedType;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
Expand Down Expand Up @@ -171,7 +172,7 @@ void populateCompilationUnit(CompilationUnit res, JCCompilationUnit javacCompila
if (javacCompilationUnit.getModule() != null) {
res.setModule(convert(javacCompilationUnit.getModuleDecl()));
}
javacCompilationUnit.getImports().stream().map(jc -> convert(jc)).forEach(res.imports()::add);
javacCompilationUnit.getImports().stream().filter(imp -> imp instanceof JCImport).map(jc -> convert((JCImport)jc)).forEach(res.imports()::add);
javacCompilationUnit.getTypeDecls().stream()
.map(n -> convertBodyDeclaration(n, res))
.filter(Objects::nonNull)
Expand Down Expand Up @@ -1077,7 +1078,7 @@ private FieldDeclaration convertFieldDeclaration(JCVariableDecl javac, ASTNode p

private void setJavadocForNode(JCTree javac, ASTNode node) {
Comment c = this.javacCompilationUnit.docComments.getComment(javac);
if( c != null && c.getStyle() == Comment.CommentStyle.JAVADOC) {
if( c != null && c.getStyle() == Comment.CommentStyle.JAVADOC_BLOCK) {
Javadoc javadoc = (Javadoc)convert(c, javac);
if (node instanceof BodyDeclaration bodyDeclaration) {
bodyDeclaration.setJavadoc(javadoc);
Expand Down Expand Up @@ -3012,26 +3013,29 @@ private Name convert(com.sun.tools.javac.util.Name javac, String selected) {
}

public org.eclipse.jdt.core.dom.Comment convert(Comment javac, JCTree context) {
if (javac.getStyle() == CommentStyle.JAVADOC && context != null) {
if (javac.getStyle() == CommentStyle.JAVADOC_BLOCK && context != null) {
var docCommentTree = this.javacCompilationUnit.docComments.getCommentTree(context);
JavadocConverter javadocConverter = new JavadocConverter(this, docCommentTree, TreePath.getPath(this.javacCompilationUnit, context), this.buildJavadoc);
if (docCommentTree instanceof DCDocComment dcDocComment) {
JavadocConverter javadocConverter = new JavadocConverter(this, dcDocComment, TreePath.getPath(this.javacCompilationUnit, context), this.buildJavadoc);
this.javadocConverters.add(javadocConverter);
Javadoc javadoc = javadocConverter.convertJavadoc();
this.javadocDiagnostics.addAll(javadocConverter.getDiagnostics());
return javadoc;
}
}
org.eclipse.jdt.core.dom.Comment jdt = switch (javac.getStyle()) {
case LINE -> this.ast.newLineComment();
case BLOCK -> this.ast.newBlockComment();
case JAVADOC -> this.ast.newJavadoc();
case JAVADOC_BLOCK -> this.ast.newJavadoc();
case JAVADOC_LINE -> this.ast.newJavadoc();
};
javac.isDeprecated(); javac.getText(); // initialize docComment
jdt.setSourceRange(javac.getSourcePos(0), javac.getText().length());
return jdt;
}

public org.eclipse.jdt.core.dom.Comment convert(Comment javac, int pos, int endPos) {
if (javac.getStyle() == CommentStyle.JAVADOC) {
if (javac.getStyle() == CommentStyle.JAVADOC_BLOCK) {
var parser = new com.sun.tools.javac.parser.DocCommentParser(ParserFactory.instance(this.context), Log.instance(this.context).currentSource(), javac);
JavadocConverter javadocConverter = new JavadocConverter(this, parser.parse(), pos, endPos, this.buildJavadoc);
this.javadocConverters.add(javadocConverter);
Expand All @@ -3042,7 +3046,8 @@ public org.eclipse.jdt.core.dom.Comment convert(Comment javac, int pos, int endP
org.eclipse.jdt.core.dom.Comment jdt = switch (javac.getStyle()) {
case LINE -> this.ast.newLineComment();
case BLOCK -> this.ast.newBlockComment();
case JAVADOC -> this.ast.newJavadoc();
case JAVADOC_BLOCK -> this.ast.newJavadoc();
case JAVADOC_LINE -> this.ast.newJavadoc();
};
javac.isDeprecated(); javac.getText(); // initialize docComment
jdt.setSourceRange(pos, endPos - pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class AbstractCompilerTest extends TestCase {
protected static boolean isJRE20Plus = false;
protected static boolean isJRE21Plus = false;
protected static boolean isJRE22Plus = false;
protected static boolean isJRE23Plus = false;
protected static boolean reflectNestedClassUseDollar;

public static int[][] complianceTestLevelMapping = new int[][] {
Expand Down Expand Up @@ -348,7 +349,8 @@ public static int getPossibleComplianceLevels() {
if (spec > Integer.parseInt(CompilerOptions.getLatestVersion())) {
specVersion = CompilerOptions.getLatestVersion();
}
isJRE22Plus = CompilerOptions.VERSION_22.equals(specVersion);
isJRE23Plus = CompilerOptions.VERSION_23.equals(specVersion);
isJRE22Plus = isJRE23Plus ||CompilerOptions.VERSION_22.equals(specVersion);
isJRE21Plus = isJRE22Plus || CompilerOptions.VERSION_21.equals(specVersion);
isJRE20Plus = isJRE21Plus || CompilerOptions.VERSION_20.equals(specVersion);
isJRE19Plus = isJRE20Plus || CompilerOptions.VERSION_19.equals(specVersion);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<executionEnvironment>JavaSE-22</executionEnvironment> <!-- Overrides one from .target -->
<executionEnvironment>JavaSE-23</executionEnvironment> <!-- Overrides one from .target -->
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 80d4fa3

Please sign in to comment.