From b8c0427b3d1a5dc688f496ba64b755d5c12c4581 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Mon, 16 Sep 2024 20:42:09 +0200 Subject: [PATCH] [#3722] Support new JDK23 CommentStyle --- .github/workflows/ant.yml | 4 ++-- .../lombok/delombok/DocCommentIntegrator.java | 2 +- src/utils/lombok/javac/Javac.java | 18 ++++++++++++++++-- test/pretty/resource/after/Javadoc.java | 17 +++++++++++++++++ test/pretty/resource/before/Javadoc.java | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 test/pretty/resource/after/Javadoc.java create mode 100644 test/pretty/resource/before/Javadoc.java diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 4a53d4278f..8d743478a3 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -41,10 +41,10 @@ jobs: runs-on: ubuntu-latest needs: build env: - EA_JDK: 22 + EA_JDK: 23 strategy: matrix: - jdk: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] + jdk: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] goal: [javacCurrent] include: - jdk: 11 diff --git a/src/delombok/lombok/delombok/DocCommentIntegrator.java b/src/delombok/lombok/delombok/DocCommentIntegrator.java index f74ea249c5..3464964ebe 100644 --- a/src/delombok/lombok/delombok/DocCommentIntegrator.java +++ b/src/delombok/lombok/delombok/DocCommentIntegrator.java @@ -137,7 +137,7 @@ static void attach(final JCTree node, String docCommentContent, final int pos, O } @Override public CommentStyle getStyle() { - return CommentStyle.JAVADOC; + return (CommentStyle) Javac.getCommentStyle(); } @Override public boolean isDeprecated() { diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index 1c9bed09e4..f783468716 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2024 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,6 +43,7 @@ import com.sun.tools.javac.code.Type; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.parser.Tokens.Comment; +import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; import com.sun.tools.javac.tree.DocCommentTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -330,6 +331,10 @@ public static void setDocComment(JCCompilationUnit cu, JCTree node, String javad } } + public static Object getCommentStyle() { + return JavadocOps_8.COMMENT_STYLE; + } + private static class JavadocOps_8 { static String getJavadoc(Object dc, JCTree node) { DocCommentTable dct = (DocCommentTable) dc; @@ -350,6 +355,15 @@ static void setJavadoc(Object dc, JCTree node, String javadoc) { dct.putComment(node, newCmt); } + private static final CommentStyle COMMENT_STYLE = getCommentStyle(); + private static CommentStyle getCommentStyle() { + try { + return CommentStyle.valueOf("JAVADOC"); + } catch (IllegalArgumentException e) { + return CommentStyle.valueOf("JAVADOC_BLOCK"); + } + } + private static Comment createJavadocComment(final String text, final JCTree field) { return new Comment() { @Override public String getText() { @@ -361,7 +375,7 @@ private static Comment createJavadocComment(final String text, final JCTree fiel } @Override public CommentStyle getStyle() { - return CommentStyle.JAVADOC; + return COMMENT_STYLE; } @Override public boolean isDeprecated() { diff --git a/test/pretty/resource/after/Javadoc.java b/test/pretty/resource/after/Javadoc.java new file mode 100644 index 0000000000..038d0dc4fb --- /dev/null +++ b/test/pretty/resource/after/Javadoc.java @@ -0,0 +1,17 @@ +/** + * Block comment + */ +class BlockComment { + /** + * Method + */ + private void test() { + } +} +/// Markdown +/// Comment +class MarkdownComment { + /// Method + private void test() { + } +} \ No newline at end of file diff --git a/test/pretty/resource/before/Javadoc.java b/test/pretty/resource/before/Javadoc.java new file mode 100644 index 0000000000..b0fce82496 --- /dev/null +++ b/test/pretty/resource/before/Javadoc.java @@ -0,0 +1,19 @@ +/** + * Block comment + */ +class BlockComment { + + /** + * Method + */ + private void test() {} +} + +/// Markdown +/// Comment +class MarkdownComment { + + /// Method + private void test() {} + +} \ No newline at end of file