-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/JLL/url-equals-hashcode
- Loading branch information
Showing
222 changed files
with
7,986 additions
and
2,417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[src/test*/java/**.java] | ||
indent_size = 4 | ||
ij_continuation_indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: comment-pr | ||
|
||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow | ||
on: | ||
workflow_run: | ||
workflows: ["receive-pr"] | ||
types: | ||
- completed | ||
|
||
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code. | ||
jobs: | ||
post-suggestions: | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
uses: openrewrite/gh-automation/.github/workflows/comment-pr.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: receive-pr | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: '${{ github.workflow }} @ ${{ github.ref }}' | ||
cancel-in-progress: true | ||
|
||
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
# Since this pull request receives untrusted code, we should **NOT** have any secrets in the environment. | ||
jobs: | ||
upload-patch: | ||
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026 | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip | ||
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6 | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/org/openrewrite/staticanalysis/AddSerialAnnotationToSerialVersionUID.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.staticanalysis; | ||
|
||
import org.jspecify.annotations.NonNull; | ||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Preconditions; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.TreeVisitor; | ||
import org.openrewrite.java.JavaIsoVisitor; | ||
import org.openrewrite.java.JavaTemplate; | ||
import org.openrewrite.java.search.FindAnnotations; | ||
import org.openrewrite.java.search.UsesJavaVersion; | ||
import org.openrewrite.java.search.UsesType; | ||
import org.openrewrite.java.tree.J; | ||
import org.openrewrite.java.tree.JavaType; | ||
import org.openrewrite.java.tree.TypeUtils; | ||
|
||
import java.time.Duration; | ||
import java.util.Comparator; | ||
|
||
public class AddSerialAnnotationToSerialVersionUID extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "Add `@Serial` annotation to `serialVersionUID`"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Annotation any `serialVersionUID` fields with `@Serial` to indicate it's part of the serialization mechanism."; | ||
} | ||
|
||
@Override | ||
public Duration getEstimatedEffortPerOccurrence() { | ||
return Duration.ofMinutes(1); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return Preconditions.check( | ||
Preconditions.and( | ||
new UsesJavaVersion<>(14), | ||
new UsesType<>("java.io.Serializable", true) | ||
), | ||
new JavaIsoVisitor<ExecutionContext>() { | ||
@Override | ||
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { | ||
if (TypeUtils.isAssignableTo("java.io.Serializable", classDecl.getType())) { | ||
return super.visitClassDeclaration(classDecl, ctx); | ||
} | ||
return classDecl; | ||
} | ||
|
||
@Override | ||
public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) { | ||
J.VariableDeclarations vd = super.visitVariableDeclarations(multiVariable, ctx); | ||
if (isPrivateStaticFinalLongSerialVersionUID(vd) && | ||
FindAnnotations.find(vd, "@java.io.Serial").isEmpty()) { | ||
maybeAddImport("java.io.Serial"); | ||
return JavaTemplate.builder("@Serial") | ||
.imports("java.io.Serial") | ||
.build() | ||
.apply(getCursor(), vd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); | ||
} | ||
return vd; | ||
} | ||
|
||
private boolean isPrivateStaticFinalLongSerialVersionUID(J.VariableDeclarations vd) { | ||
return vd.hasModifier(J.Modifier.Type.Private) && | ||
vd.hasModifier(J.Modifier.Type.Static) && | ||
vd.hasModifier(J.Modifier.Type.Final) && | ||
TypeUtils.asPrimitive(vd.getType()) == JavaType.Primitive.Long && | ||
vd.getVariables().size() == 1 && | ||
"serialVersionUID".equals(vd.getVariables().get(0).getSimpleName()); | ||
} | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.