Skip to content

Commit

Permalink
[projectlombok#3722] Support new JDK23 CommentStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Sep 20, 2024
1 parent 7526768 commit b8c0427
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/delombok/lombok/delombok/DocCommentIntegrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 16 additions & 2 deletions src/utils/lombok/javac/Javac.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions test/pretty/resource/after/Javadoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Block comment
*/
class BlockComment {
/**
* Method
*/
private void test() {
}
}
/// Markdown
/// Comment
class MarkdownComment {
/// Method
private void test() {
}
}
19 changes: 19 additions & 0 deletions test/pretty/resource/before/Javadoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Block comment
*/
class BlockComment {

/**
* Method
*/
private void test() {}
}

/// Markdown
/// Comment
class MarkdownComment {

/// Method
private void test() {}

}

0 comments on commit b8c0427

Please sign in to comment.