Skip to content

Commit 6af6b4a

Browse files
authored
Merge branch 'main' into joda-time
2 parents 35f0472 + c48a656 commit 6af6b4a

16 files changed

+400
-234
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=57dafb5c2622c6cc08b993c85b7c06956a2f53536432a30ead46166dbca0f1e9
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
3+
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.openrewrite.ExecutionContext;
19+
import org.openrewrite.Preconditions;
20+
import org.openrewrite.Recipe;
21+
import org.openrewrite.TreeVisitor;
22+
import org.openrewrite.internal.ListUtils;
23+
import org.openrewrite.java.ChangeType;
24+
import org.openrewrite.java.JavaIsoVisitor;
25+
import org.openrewrite.java.search.FindMethods;
26+
import org.openrewrite.java.search.UsesMethod;
27+
import org.openrewrite.java.tree.J;
28+
import org.openrewrite.java.tree.TypeUtils;
29+
30+
public class ArrayStoreExceptionToTypeNotPresentException extends Recipe {
31+
32+
private static final String ARRAY_STORE_EXCEPTION = "java.lang.ArrayStoreException";
33+
private static final String TYPE_NOT_PRESENT_EXCEPTION = "java.lang.TypeNotPresentException";
34+
35+
@Override
36+
public String getDisplayName() {
37+
return "Catch `TypeNotPresentException` thrown by `Class.getAnnotation()`";
38+
}
39+
40+
@Override
41+
public String getDescription() {
42+
return "Replace catch blocks for `ArrayStoreException` around `Class.getAnnotation()` with `TypeNotPresentException` to ensure compatibility with Java 11+.";
43+
}
44+
45+
@Override
46+
public TreeVisitor<?, ExecutionContext> getVisitor() {
47+
String classGetAnnotationPattern = "java.lang.Class getAnnotation(java.lang.Class)";
48+
return Preconditions.check(new UsesMethod<>(classGetAnnotationPattern), new JavaIsoVisitor<ExecutionContext>() {
49+
@Override
50+
public J.Try visitTry(J.Try tryStatement, ExecutionContext ctx) {
51+
J.Try try_ = super.visitTry(tryStatement, ctx);
52+
if (FindMethods.find(try_, classGetAnnotationPattern).isEmpty()) {
53+
return try_;
54+
}
55+
return try_.withCatches(ListUtils.map(try_.getCatches(), catch_ -> {
56+
if (TypeUtils.isOfClassType(catch_.getParameter().getType(), ARRAY_STORE_EXCEPTION)) {
57+
return (J.Try.Catch) new ChangeType(ARRAY_STORE_EXCEPTION, TYPE_NOT_PRESENT_EXCEPTION, true)
58+
.getVisitor().visit(catch_, ctx);
59+
}
60+
return catch_;
61+
}));
62+
}
63+
});
64+
}
65+
}

src/main/java/org/openrewrite/java/migrate/RemoveMethodInvocation.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/org/openrewrite/java/migrate/lang/MigrateSecurityManagerMulticast.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
5353
J.MethodInvocation m = super.visitMethodInvocation(method, ctx);
5454

5555
if (MULTICAST_METHOD.matches(m) && m.getArguments().size() == 2) {
56-
return m.withArguments(Collections.singletonList(m.getArguments().get(0)));
56+
return m.withArguments(Collections.singletonList(m.getArguments().get(0)))
57+
.withMethodType(m.getMethodType()
58+
.withParameterNames(m.getMethodType().getParameterNames().subList(0, 1))
59+
.withParameterTypes(m.getMethodType().getParameterTypes().subList(0, 1))
60+
);
5761
}
5862
return m;
5963
}

src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.java.migrate.lang.var;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.openrewrite.Cursor;
1920
import org.openrewrite.java.tree.*;
2021

@@ -198,4 +199,30 @@ private static boolean isInsideInitializer(Cursor cursor, int nestedBlockLevel)
198199

199200
return isInsideInitializer(requireNonNull(cursor.getParent()), nestedBlockLevel);
200201
}
202+
203+
/**
204+
* Checks whether the initializer {@linkplain Expression} is a {@linkplain J.MethodInvocation} targeting a static method.
205+
*
206+
* @param initializer {@linkplain J.VariableDeclarations.NamedVariable#getInitializer()} value
207+
* @return true iff is initialized by static method
208+
*/
209+
public static boolean initializedByStaticMethod(@Nullable Expression initializer) {
210+
if (initializer == null) {
211+
return false;
212+
}
213+
initializer = initializer.unwrap();
214+
215+
if (!(initializer instanceof J.MethodInvocation)) {
216+
// no MethodInvocation -> false
217+
return false;
218+
}
219+
220+
J.MethodInvocation invocation = (J.MethodInvocation) initializer;
221+
if (invocation.getMethodType() == null) {
222+
// not a static method -> false
223+
return false;
224+
}
225+
226+
return invocation.getMethodType().hasFlags(Flag.Static);
227+
}
201228
}

src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations v
7575
boolean isPrimitive = DeclarationCheck.isPrimitive(vd);
7676
boolean usesGenerics = DeclarationCheck.useGenerics(vd);
7777
boolean usesTernary = DeclarationCheck.initializedByTernary(vd);
78-
boolean usesArrayInitializer = vd.getVariables().get(0).getInitializer() instanceof J.NewArray;
79-
if (isPrimitive || usesGenerics || usesTernary || usesArrayInitializer) {
78+
Expression initializer = vd.getVariables().get(0).getInitializer();
79+
boolean usesArrayInitializer = initializer instanceof J.NewArray;
80+
boolean initializedByStaticMethod = DeclarationCheck.initializedByStaticMethod(initializer);
81+
if (isPrimitive || usesGenerics || usesTernary || usesArrayInitializer || initializedByStaticMethod) {
8082
return vd;
8183
}
8284

src/main/java/org/openrewrite/java/migrate/maven/UpdateMavenProjectPropertyJavaVersion.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
8888
Xml.Document d = super.visitDocument(document, ctx);
8989

9090
// Return early if the parent appears to be within the current repository, as properties defined there will be updated
91-
if (d.getRoot().getChild("parent")
92-
.flatMap(parent -> parent.getChild("relativePath"))
93-
.flatMap(Xml.Tag::getValue)
94-
.isPresent()) {
91+
if (getResolutionResult().parentPomIsProjectPom()) {
9592
return d;
9693
}
9794

src/main/resources/META-INF/rewrite/jakarta-ee-10.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ type: specs.openrewrite.org/v1beta/recipe
4242
name: org.openrewrite.java.migrate.jakarta.ServletCookieBehaviorChangeRFC6265
4343
displayName: Remove `getComment` and `getVersion` methods
4444
description: >-
45-
Jakarta Servlet methods have been deprecated for removal in Jakarta Servlet 6.0 to align with RFC 6265.
45+
Jakarta Servlet methods have been deprecated for removal in Jakarta Servlet 6.0 to align with RFC 6265.
4646
In addition, the behavior of these methods has been changed so the setters no longer have any effect, the getComment methods return null, and the getVersion method returns 0.
4747
The deprecated methods are removed.
4848
recipeList:
49-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
49+
- org.openrewrite.java.RemoveMethodInvocations:
5050
methodPattern: jakarta.servlet.http.Cookie getComment()
51-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
51+
- org.openrewrite.java.RemoveMethodInvocations:
5252
methodPattern: jakarta.servlet.http.Cookie getVersion()
53-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
53+
- org.openrewrite.java.RemoveMethodInvocations:
5454
methodPattern: jakarta.servlet.http.Cookie setComment(String)
55-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
55+
- org.openrewrite.java.RemoveMethodInvocations:
5656
methodPattern: jakarta.servlet.http.Cookie setVersion(int)
57-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
57+
- org.openrewrite.java.RemoveMethodInvocations:
5858
methodPattern: jakarta.servlet.SessionCookieConfig getComment()
59-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
59+
- org.openrewrite.java.RemoveMethodInvocations:
6060
methodPattern: jakarta.servlet.SessionCookieConfig setComment(String)
6161
---
6262
type: specs.openrewrite.org/v1beta/recipe
@@ -75,7 +75,7 @@ type: specs.openrewrite.org/v1beta/recipe
7575
name: org.openrewrite.java.migrate.jakarta.RemovedIsParmetersProvidedMethod
7676
displayName: Use `isParametersProvided()`
7777
description: >-
78-
Expression Language prior to 5.0 provides the deprecated MethodExpression.isParmetersProvided() method, with the word 'parameter' misspelled in the method name.
78+
Expression Language prior to 5.0 provides the deprecated MethodExpression.isParmetersProvided() method, with the word 'parameter' misspelled in the method name.
7979
This method is unavailable in Jakarta Expression Language 5.0. Use the correctly spelled MethodExpression.isParametersProvided() method instead.
8080
recipeList:
8181
- org.openrewrite.java.ChangeMethodName:
@@ -86,7 +86,7 @@ type: specs.openrewrite.org/v1beta/recipe
8686
name: org.openrewrite.java.migrate.jakarta.RemovedSOAPElementFactory
8787
displayName: Use `jakarta.xml.soap.SOAPFactory` to create `SOAPElements`
8888
description: >-
89-
XML Web Services prior to 4.0 provides the deprecated SOAPElementFactory class,
89+
XML Web Services prior to 4.0 provides the deprecated SOAPElementFactory class,
9090
which is removed in XML Web Services 4.0. The recommended replacement is to use jakarta.xml.soap.SOAPFactory to create SOAPElements.
9191
recipeList:
9292
- org.openrewrite.java.ChangeMethodName:

src/main/resources/META-INF/rewrite/java-version-11.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ recipeList:
4343
- org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf
4444
- org.openrewrite.java.migrate.concurrent.JavaConcurrentAPIs
4545
- org.openrewrite.java.migrate.lang.JavaLangAPIs
46-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
46+
- org.openrewrite.java.RemoveMethodInvocations:
4747
methodPattern: java.lang.Runtime runFinalizersOnExit(boolean)
48-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
48+
- org.openrewrite.java.RemoveMethodInvocations:
4949
methodPattern: java.lang.System runFinalizersOnExit(boolean)
5050
- org.openrewrite.java.migrate.logging.JavaLoggingAPIs
5151
- org.openrewrite.java.migrate.lombok.UpdateLombokToJava11
@@ -73,6 +73,8 @@ recipeList:
7373
- org.openrewrite.scala.migrate.UpgradeScala_2_12
7474
- org.openrewrite.java.migrate.ReplaceComSunAWTUtilitiesMethods
7575
- org.openrewrite.java.migrate.ReplaceLocalizedStreamMethods
76+
- org.openrewrite.java.migrate.ArrayStoreExceptionToTypeNotPresentException
77+
7678
---
7779
type: specs.openrewrite.org/v1beta/recipe
7880
name: org.openrewrite.java.migrate.UpgradeBuildToJava11
@@ -268,9 +270,9 @@ description: >-
268270
tags:
269271
- java11
270272
recipeList:
271-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
273+
- org.openrewrite.java.RemoveMethodInvocations:
272274
methodPattern: java.lang.Thread destroy()
273-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
275+
- org.openrewrite.java.RemoveMethodInvocations:
274276
methodPattern: java.lang.Thread stop(java.lang.Throwable)
275277
---
276278
type: specs.openrewrite.org/v1beta/recipe

src/main/resources/META-INF/rewrite/java-version-17.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ recipeList:
5151
groupId: com.google.inject
5252
artifactId: guice
5353
newVersion: 5.x
54+
- org.openrewrite.java.migrate.AddLombokMapstructBinding
5455

5556
---
5657
type: specs.openrewrite.org/v1beta/recipe
@@ -226,7 +227,7 @@ description: >-
226227
tags:
227228
- java17
228229
recipeList:
229-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
230+
- org.openrewrite.java.RemoveMethodInvocations:
230231
methodPattern: 'java.lang.Thread countStackFrames()'
231232
---
232233
type: specs.openrewrite.org/v1beta/recipe
@@ -281,7 +282,37 @@ description: >-
281282
tags:
282283
- java17
283284
recipeList:
284-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
285+
- org.openrewrite.java.RemoveMethodInvocations:
285286
methodPattern: 'java.lang.Runtime traceInstructions(boolean)'
286-
- org.openrewrite.java.migrate.RemoveMethodInvocation:
287+
- org.openrewrite.java.RemoveMethodInvocations:
287288
methodPattern: 'java.lang.Runtime traceMethodCalls(boolean)'
289+
---
290+
type: specs.openrewrite.org/v1beta/recipe
291+
name: org.openrewrite.java.migrate.AddLombokMapstructBinding
292+
displayName: Add `lombok-mapstruct-binding` when both MapStruct and Lombok are used
293+
description: Add the `lombok-mapstruct-binding` annotation processor as needed when both MapStruct and Lombok are used.
294+
tags:
295+
- java17
296+
preconditions:
297+
- org.openrewrite.java.dependencies.DependencyInsight:
298+
groupIdPattern: org.projectlombok
299+
artifactIdPattern: lombok
300+
- org.openrewrite.java.dependencies.DependencyInsight:
301+
groupIdPattern: org.mapstruct
302+
artifactIdPattern: mapstruct
303+
recipeList:
304+
- org.openrewrite.gradle.AddDependency:
305+
groupId: org.projectlombok
306+
artifactId: lombok-mapstruct-binding
307+
version: 0.2.0
308+
configuration: annotationProcessor
309+
acceptTransitive: false
310+
- org.openrewrite.maven.AddDependency:
311+
groupId: org.projectlombok
312+
artifactId: lombok-mapstruct-binding
313+
version: 0.2.0
314+
acceptTransitive: false
315+
- org.openrewrite.maven.AddAnnotationProcessor:
316+
groupId: org.projectlombok
317+
artifactId: lombok-mapstruct-binding
318+
version: 0.2.0

0 commit comments

Comments
 (0)