|
48 | 48 | import javax.lang.model.element.Modifier; |
49 | 49 | import javax.lang.model.element.Name; |
50 | 50 | import java.lang.reflect.Field; |
| 51 | +import java.lang.reflect.InvocationTargetException; |
| 52 | +import java.lang.reflect.Method; |
51 | 53 | import java.nio.charset.Charset; |
52 | 54 | import java.nio.file.Path; |
53 | 55 | import java.util.*; |
@@ -1850,8 +1852,14 @@ public J visitWildcard(WildcardTree node, Space fmt) { |
1850 | 1852 | // The spacing of initialized enums such as `ONE (1)` is handled in the `visitNewClass` method, so set it explicitly to “” here. |
1851 | 1853 | String prefix = isEnum(t) ? "" : source.substring(cursor, indexOfNextNonWhitespace(cursor, source)); |
1852 | 1854 | cursor += prefix.length(); |
1853 | | - @SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t))); |
| 1855 | + // Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both |
| 1856 | + Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class); |
| 1857 | + DocCommentTree commentTree = (DocCommentTree) getCommentTreeMethod.invoke(docCommentTable, t); |
| 1858 | + @SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, commentTree)); |
1854 | 1859 | return j; |
| 1860 | + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { |
| 1861 | + reportJavaParsingException(ex); |
| 1862 | + throw new IllegalStateException("Failed to invoke getCommentTree method", ex); |
1855 | 1863 | } catch (Throwable ex) { |
1856 | 1864 | reportJavaParsingException(ex); |
1857 | 1865 | throw ex; |
|
0 commit comments