Skip to content

Commit 040d0ab

Browse files
committed
Reapply "Init of Java 25 parser (#5942)"
This reverts commit c71d752.
1 parent c71d752 commit 040d0ab

File tree

31 files changed

+5818
-69
lines changed

31 files changed

+5818
-69
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ concurrency:
1919
jobs:
2020
build:
2121
uses: openrewrite/gh-automation/.github/workflows/ci-gradle.yml@main
22+
with:
23+
java_version: |
24+
25-ea
25+
21
2226
secrets:
2327
gradle_enterprise_access_key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
2428
sonatype_username: ${{ secrets.SONATYPE_USERNAME }}

.github/workflows/receive-pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ concurrency:
1414
# Since this pull request receives untrusted code, we should **NOT** have any secrets in the environment.
1515
jobs:
1616
upload-patch:
17+
if: false # Temporarily disable to avoid excessive suggestion spam
1718
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main
1819
with:
20+
java_version: |
21+
25-ea
22+
21
1923
recipe: 'org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPracticesSubset'
24+

IDE.properties.tmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rewrite-java-test
2323
rewrite-java-tck
2424
rewrite-java-17
2525
rewrite-java-21
26+
rewrite-java-25
2627

2728
# Other language modules
2829

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists
8-
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
8+
distributionSha256Sum=8fad3d78296ca518113f3d29016617c7f9367dc005f932bd9d93bf45ba46072b

gradlew

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ case "$( uname )" in #(
114114
NONSTOP* ) nonstop=true ;;
115115
esac
116116

117-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
117+
CLASSPATH="\\\"\\\""
118118

119119

120120
# Determine the Java command to use to start the JVM.
@@ -205,15 +205,15 @@ fi
205205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206206

207207
# Collect all arguments for the java command:
208-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209209
# and any embedded shellness will be escaped.
210210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211211
# treated as '${Hostname}' itself on the command line.
212212

213213
set -- \
214214
"-Dorg.gradle.appname=$APP_BASE_NAME" \
215215
-classpath "$CLASSPATH" \
216-
org.gradle.wrapper.GradleWrapperMain \
216+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217217
"$@"
218218

219219
# Stop when "xargs" is not available.

gradlew.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ goto fail
7070
:execute
7171
@rem Setup the command line
7272

73-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73+
set CLASSPATH=
7474

7575

7676
@rem Execute Gradle
77-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
77+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7878

7979
:end
8080
@rem End local scope for the variables with windows NT shell

rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,15 +1761,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
17611761
// The spacing of initialized enums such as `ONE (1)` is handled in the `visitNewClass` method, so set it explicitly to “” here.
17621762
String prefix = isEnum(t) ? "" : source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
17631763
cursor += prefix.length();
1764-
// Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both
1765-
// Though this is the Java 17 parser, we still need to support it if people use this parser with newer Java versions (e.g. https://github.com/PicnicSupermarket/error-prone-support/pull/1557)
1766-
Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
1767-
DocCommentTree commentTree = (DocCommentTree) getCommentTreeMethod.invoke(docCommentTable, t);
1768-
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, commentTree));
1764+
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t)));
17691765
return j;
1770-
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
1771-
reportJavaParsingException(ex);
1772-
throw new IllegalStateException("Failed to invoke getCommentTree method", ex);
17731766
} catch (Throwable ex) {
17741767
reportJavaParsingException(ex);
17751768
throw ex;

rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21ParserVisitor.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,14 +1788,8 @@ public J visitWildcard(WildcardTree node, Space fmt) {
17881788
// The spacing of initialized enums such as `ONE (1)` is handled in the `visitNewClass` method, so set it explicitly to “” here.
17891789
String prefix = isEnum(t) ? "" : source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
17901790
cursor += prefix.length();
1791-
// Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both
1792-
Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
1793-
DocCommentTree commentTree = (DocCommentTree) getCommentTreeMethod.invoke(docCommentTable, t);
1794-
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, commentTree));
1791+
@SuppressWarnings("unchecked") J2 j = (J2) scan(t, formatWithCommentTree(prefix, (JCTree) t, docCommentTable.getCommentTree((JCTree) t)));
17951792
return j;
1796-
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
1797-
reportJavaParsingException(ex);
1798-
throw new IllegalStateException("Failed to invoke getCommentTree method", ex);
17991793
} catch (Throwable ex) {
18001794
reportJavaParsingException(ex);
18011795
throw ex;

rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ReloadableJava21TypeMapping implements JavaTypeMapping<Tree> {
4646
private final JavaTypeCache typeCache;
4747

4848
public JavaType type(com.sun.tools.javac.code.@Nullable Type type) {
49-
if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || isUnknownType(type) ||
49+
if (type == null || type instanceof Type.ErrorType || type instanceof Type.PackageType || type instanceof Type.UnknownType ||
5050
type instanceof NullType) {
5151
return JavaType.Class.Unknown.getInstance();
5252
}
@@ -488,7 +488,7 @@ public JavaType.Primitive primitive(TypeTag tag) {
488488
}
489489

490490
if (selectType == null || selectType instanceof Type.ErrorType || symbol == null || symbol.kind == Kinds.Kind.ERR ||
491-
isUnknownType(symbol.type)) {
491+
symbol.type instanceof Type.UnknownType) {
492492
return null;
493493
}
494494

@@ -553,7 +553,7 @@ public JavaType.Primitive primitive(TypeTag tag) {
553553
exceptionTypes.add(javaType);
554554
}
555555
}
556-
} else if (isUnknownType(selectType)) {
556+
} else if (selectType instanceof Type.UnknownType) {
557557
returnType = JavaType.Unknown.getInstance();
558558
}
559559

@@ -776,11 +776,4 @@ private Object annotationElementValue(Object value) {
776776
}
777777
return JavaType.Unknown.getInstance();
778778
}
779-
780-
/**
781-
* Check for the `UnknownType` which existed up until JDK 22; starting with JDK 23 only the `ErrorType` is used
782-
*/
783-
public static boolean isUnknownType(@Nullable Type type) {
784-
return type != null && type.getClass().getName().equals("com.sun.tools.javac.code.Type$UnknownType");
785-
}
786779
}

rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeSignatureBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Set;
3131
import java.util.StringJoiner;
3232

33-
import static org.openrewrite.java.isolated.ReloadableJava21TypeMapping.isUnknownType;
3433

3534
class ReloadableJava21TypeSignatureBuilder implements JavaTypeSignatureBuilder {
3635
@Nullable
@@ -42,7 +41,7 @@ public String signature(@Nullable Object t) {
4241
}
4342

4443
private String signature(@Nullable Type type) {
45-
if (type == null || isUnknownType(type) || type instanceof NullType) {
44+
if (type == null || type instanceof Type.UnknownType || type instanceof NullType) {
4645
return "{undefined}";
4746
} else if (type instanceof Type.IntersectionClassType) {
4847
return intersectionSignature(type);
@@ -300,7 +299,7 @@ private String methodArgumentSignature(Type selectType) {
300299
return resolvedArgumentTypes.toString();
301300
} else if (selectType instanceof Type.ForAll) {
302301
return methodArgumentSignature(((Type.ForAll) selectType).qtype);
303-
} else if (selectType instanceof Type.JCNoType || isUnknownType(selectType)) {
302+
} else if (selectType instanceof Type.JCNoType || selectType instanceof Type.UnknownType) {
304303
return "{undefined}";
305304
}
306305

0 commit comments

Comments
 (0)