Skip to content

Commit ee6b28d

Browse files
author
Vincent Potucek
committed
[rewrite] fix JavaLangAPIs #2804 (#2810)
1 parent e1e970a commit ee6b28d

9 files changed

Lines changed: 197 additions & 190 deletions

File tree

.github/workflows/changelog-print.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
with:
1515
java-version: 21
1616
distribution: 'temurin'
17-
- name: Setup Gradle 🐘
17+
- name: gradle caching
1818
uses: gradle/actions/setup-gradle@v5
1919
- run: ./gradlew changelogPrint

.github/workflows/ci.yml

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches: [main, release]
99
workflow_dispatch:
10+
1011
concurrency:
1112
group: ${{ github.workflow }}-${{ github.ref }}
1213
cancel-in-progress: true
@@ -18,35 +19,34 @@ jobs:
1819
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
1920
buildcachepass: ${{ secrets.BUILDCACHE_PASS }}
2021
steps:
21-
- name: Checkout Code 📥
22+
- name: Checkout
2223
uses: actions/checkout@v6
2324
with:
2425
fetch-depth: 0
2526
- uses: actions/setup-java@v5
2627
with:
27-
distribution: temurin
28+
distribution: "temurin"
2829
java-version: 21
29-
- name: Setup Gradle 🐘
30+
- name: gradle caching
3031
uses: gradle/actions/setup-gradle@v5
3132
- name: Spotless ✨
32-
run: ./gradlew clean spotlessCheck
33-
- name: Error Prone 🚧
34-
run: ./gradlew clean assemble
35-
- name: Test Classes ⚙️
36-
run: ./gradlew clean testClasses
33+
run: ./gradlew spotlessCheck
3734
- name: Rewrite ♻️
38-
run: ./gradlew clean rewriteDryRun
35+
run: ./gradlew rewriteDryRun
36+
- name: assemble testClasses
37+
run: ./gradlew assemble testClasses
3938
build:
40-
name: Build 🏗️
4139
needs: sanity-check
4240
strategy:
4341
fail-fast: false
4442
matrix:
4543
kind: [maven, gradle]
46-
jre: [17, 21, 24] # test on the latest Java version once Gradle & Maven support it.
44+
# Test on the latest Java version once Gradle & Maven support it.
45+
jre: [17, 21, 24]
4746
os: [ubuntu-latest, windows-latest]
4847
include:
49-
- kind: npm # npm on linux only (crazy slow on windows).
48+
# npm on linux only (crazy slow on windows)
49+
- kind: npm
5050
jre: 17
5151
os: ubuntu-latest
5252
- kind: shfmt
@@ -58,64 +58,66 @@ jobs:
5858
os: ubuntu-latest
5959
runs-on: ${{ matrix.os }}
6060
steps:
61-
- name: Checkout Code 📥
61+
- name: Checkout
6262
uses: actions/checkout@v6
6363
- uses: actions/setup-java@v5
6464
with:
65-
distribution: temurin
65+
distribution: "temurin"
6666
java-version: ${{ matrix.jre }}
67-
- name: Setup Gradle 🐘
67+
- name: gradle caching
6868
uses: gradle/actions/setup-gradle@v5
69-
- name: Build Maven 🪶
69+
- name: build (maven-only)
7070
if: matrix.kind == 'maven'
71-
run: ./gradlew :plugin-maven:build -x spotlessCheck
72-
- name: Build Gradle 🐘
71+
run: ./gradlew :plugin-maven:build -x spotlessCheck -x rewriteDryRun
72+
- name: build (everything-but-maven)
7373
if: matrix.kind == 'gradle'
74-
run: ./gradlew build -PSPOTLESS_EXCLUDE_MAVEN=true -x spotlessCheck
75-
- name: Test npm 📊
74+
run: ./gradlew build -x spotlessCheck -x rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
75+
- name: test npm
7676
if: matrix.kind == 'npm'
7777
run: ./gradlew testNpm
78-
- name: Setup Go
78+
- name: Setup go
7979
if: matrix.kind == 'shfmt'
8080
uses: actions/setup-go@v6
8181
with:
82-
go-version: stable
83-
- name: Install shfmt 📥
82+
go-version: 'stable'
83+
- name: Install shfmt
8484
if: matrix.kind == 'shfmt'
85-
run: go install mvdan.cc/sh/v3/cmd/shfmt@${{ matrix.shfmt-version }}
86-
- name: Test shfmt 📊
85+
run: |
86+
go install mvdan.cc/sh/v3/cmd/shfmt@${{ matrix.shfmt-version }}
87+
- name: Test shfmt
8788
if: matrix.kind == 'shfmt'
8889
run: ./gradlew testShfmt
89-
- name: Test IDEA 📊
90+
- name: Test idea
9091
if: matrix.kind == 'idea'
9192
run: |
9293
download_link=$(curl https://data.services.jetbrains.com/products/releases\?code\=IIC\&latest\=true\&type\=release | jq -r '.IIC[0].downloads.linux.link')
93-
curl --location $download_link -o idea.tar.gz
94+
curl --location "$download_link" -o idea.tar.gz
9495
tar -xf idea.tar.gz
9596
cd idea-IC*
9697
export PATH=${PATH}:$(pwd)/bin
9798
cd ..
9899
./gradlew testIdea
99-
- name: Junit Report 📋
100+
- name: junit result
100101
uses: mikepenz/action-junit-report@v6
101-
if: always() # always run even if the previous step fails.
102+
if: always() # always run even if the previous step fails
102103
with:
103104
check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }}
104105
report_paths: '*/build/test-results/*/TEST-*.xml'
105106
check_retries: true
106-
complete: # this check is required in branch protection rules.
107-
name: Complete ✅
107+
108+
# Status check that is required in branch protection rules.
109+
final-status:
108110
needs:
109111
- sanity-check
110112
- build
111113
runs-on: ubuntu-latest
112114
if: always()
113115
steps:
114-
- name: Check 🦉
116+
- name: Check
115117
run: |
116118
results=$(tr -d '\n' <<< '${{ toJSON(needs.*.result) }}')
117-
if ! grep -q -v -E '(failure|cancelled)' <<< $results; then
118-
echo One or more required jobs failed.
119+
if ! grep -q -v -E '(failure|cancelled)' <<< "$results"; then
120+
echo "One or more required jobs failed"
119121
exit 1
120122
fi
121-
echo All required jobs completed successfully.
123+
echo "All required jobs completed successfully."

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
3737

3838
steps:
39-
- name: Checkout Code 📥
39+
- name: Checkout repository
4040
uses: actions/checkout@v6
4141
with:
4242
# We must fetch at least the immediate parents so that if this is
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
languages: ${{ matrix.language }}
5656
# If you wish to specify custom queries, you can do so here or in a config file.
57-
# By default, queries listed here will override any specified in a config file.
57+
# By default, queries listed here will override any specified in a config file.
5858
# Prefix the list here with "+" to use these queries and those in the config file.
5959
# queries: ./path/to/local/query, your-org/your-repo/queries@main
6060

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
with:
4343
java-version: 21
4444
distribution: 'temurin'
45-
- name: Setup Gradle 🐘
45+
- name: gradle caching
4646
uses: gradle/actions/setup-gradle@v5
4747
- name: git fetch origin main
4848
run: git fetch origin main

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Spotless can format &lt;antlr | c | c# | c++ | css | flow | graphql | groovy | h
88

99
You probably want one of the links below:
1010

11-
## [️ Spotless for Gradle](plugin-gradle) (with integrations for [VS Code](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) and [IntelliJ](https://plugins.jetbrains.com/plugin/18321-spotless-gradle))
11+
## [️ Spotless for Gradle](plugin-gradle) (with integrations for [VS Code](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) and [IntelliJ](https://plugins.jetbrains.com/plugin/18321-spotless-gradle))
1212

1313
```console
1414
user@machine repo % ./gradlew build
@@ -25,7 +25,7 @@ user@machine repo % ./gradlew build
2525
BUILD SUCCESSFUL
2626
```
2727

28-
## [️ Spotless for Maven](plugin-maven)
28+
## [️ Spotless for Maven](plugin-maven)
2929

3030
```console
3131
user@machine repo % mvn spotless:check
@@ -40,7 +40,7 @@ user@machine repo % mvn spotless:check
4040
[INFO] BUILD SUCCESS
4141
```
4242

43-
## [️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless)
43+
## [️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless)
4444
## [Other build systems](CONTRIBUTING.md#how-to-add-a-new-plugin-for-a-build-system)
4545

4646
## How it works (for potential contributors)

rewrite.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ recipeList:
77
- org.openrewrite.gradle.EnableGradleBuildCache
88
- org.openrewrite.gradle.EnableGradleParallelExecution
99
- org.openrewrite.gradle.GradleBestPractices
10-
- org.openrewrite.hcl.format.RemoveTrailingWhitespace
1110
- org.openrewrite.java.RemoveUnusedImports
12-
- org.openrewrite.java.ShortenFullyQualifiedTypeReferences
13-
- org.openrewrite.java.SimplifySingleElementAnnotation
14-
- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
1511
- org.openrewrite.java.format.NormalizeFormat
1612
- org.openrewrite.java.format.NormalizeLineBreaks
17-
- org.openrewrite.java.format.PadEmptyForLoopComponents
1813
- org.openrewrite.java.format.RemoveTrailingWhitespace
1914
- org.openrewrite.java.migrate.UpgradeToJava17
2015
- org.openrewrite.java.migrate.lang.JavaLangAPIs
@@ -27,32 +22,19 @@ recipeList:
2722
- org.openrewrite.java.recipes.RecipeTestingBestPractices
2823
- org.openrewrite.java.security.JavaSecurityBestPractices
2924
- org.openrewrite.staticanalysis.BufferedWriterCreationRecipes
30-
- org.openrewrite.staticanalysis.ChainStringBuilderAppendCalls
3125
- org.openrewrite.staticanalysis.CommonStaticAnalysis
32-
- org.openrewrite.staticanalysis.CustomImportOrder
33-
- org.openrewrite.staticanalysis.DefaultComesLast
34-
- org.openrewrite.staticanalysis.EmptyBlock
3526
- org.openrewrite.staticanalysis.EqualsAvoidsNull
36-
- org.openrewrite.staticanalysis.ExplicitInitialization
37-
- org.openrewrite.staticanalysis.FallThrough
38-
- org.openrewrite.staticanalysis.FinalizePrivateFields
39-
- org.openrewrite.staticanalysis.ForLoopControlVariablePostfixOperators
40-
- org.openrewrite.staticanalysis.HideUtilityClassConstructor
4127
- org.openrewrite.staticanalysis.JavaApiBestPractices
4228
- org.openrewrite.staticanalysis.LowercasePackage
4329
- org.openrewrite.staticanalysis.MissingOverrideAnnotation
4430
- org.openrewrite.staticanalysis.ModifierOrder
45-
- org.openrewrite.staticanalysis.NeedBraces
4631
- org.openrewrite.staticanalysis.NoFinalizer
4732
- org.openrewrite.staticanalysis.NoToStringOnStringType
4833
- org.openrewrite.staticanalysis.NoValueOfOnStringType
4934
- org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
5035
- org.openrewrite.staticanalysis.RemoveUnusedPrivateFields
5136
- org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
52-
- org.openrewrite.staticanalysis.ReplaceStringBuilderWithString
53-
- org.openrewrite.staticanalysis.ReplaceThreadRunWithThreadStart
5437
- org.openrewrite.staticanalysis.SimplifyTernaryRecipes
55-
- org.openrewrite.staticanalysis.TypecastParenPad
5638
- org.openrewrite.staticanalysis.URLEqualsHashCodeRecipes
5739
- org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources
5840
- org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2016-2025 DiffPlug
3+
*
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+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
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 com.diffplug.spotless;
17+
18+
import java.lang.reflect.Method;
19+
import java.lang.reflect.Modifier;
20+
import java.lang.reflect.Parameter;
21+
import java.util.Arrays;
22+
import java.util.Iterator;
23+
24+
/**
25+
* Utilities for dumping class info, helpful for
26+
* debugging reflection code. Probably easiest to
27+
* just copy-paste these methods where you need
28+
* them.
29+
*/
30+
public class ReflectionUtil {
31+
public static void dumpAllInfo(String name, Object obj) {
32+
System.out.println(name + " of type " + obj.getClass());
33+
for (Method method : obj.getClass().getMethods()) {
34+
dumpMethod(method);
35+
}
36+
}
37+
38+
public static void dumpMethod(Method method) {
39+
System.out.print(Modifier.toString(method.getModifiers()));
40+
System.out.print(" " + method.getReturnType());
41+
System.out.print(" " + method.getName() + "(");
42+
Iterator<Parameter> paramIter = Arrays.asList(method.getParameters()).iterator();
43+
while (paramIter.hasNext()) {
44+
Parameter param = paramIter.next();
45+
46+
System.out.print(param.getType().getName());
47+
if (paramIter.hasNext()) {
48+
System.out.print(", ");
49+
}
50+
}
51+
System.out.println(")");
52+
}
53+
}

0 commit comments

Comments
 (0)