Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and skip unsupported templates #5

Closed
knutwannheden opened this issue May 12, 2023 · 10 comments · Fixed by PicnicSupermarket/error-prone-support#925
Closed

Detect and skip unsupported templates #5

knutwannheden opened this issue May 12, 2023 · 10 comments · Fixed by PicnicSupermarket/error-prone-support#925
Assignees
Labels

Comments

@knutwannheden
Copy link
Contributor

Until the Refaster support is feature complete, it would still be nice to be able to use the annotation processor on a code base where some of the Refaster templates can be supported. For this to work the annotation processor must identify the templates which cannot be supported and then make sure to not generate anything for them (possibly even check if there is a corresponding generated file which should be deleted). It would also be nice to emit some messages to the developer, so it is clear why no recipe was generated.

@knutwannheden knutwannheden added the enhancement New feature or request label May 12, 2023
@knutwannheden knutwannheden self-assigned this May 12, 2023
@knutwannheden knutwannheden moved this to In Progress in OpenRewrite May 12, 2023
knutwannheden added a commit that referenced this issue May 12, 2023
If a template has multiple before templates, uses any unsupported Refaster annotations, or any of the static methods of the `Refaster` class, no recipe will be generated.

Issue: #5
@knutwannheden knutwannheden changed the title Refaster: Detect and skip unsupported templates Detect and skip unsupported templates May 12, 2023
@knutwannheden
Copy link
Contributor Author

@rpau The annotation processor now generates compiling code for most of Picnic's Refaster templates. I will investigate the remaining few issues and then we will need to decide how much of that we still want to address now and what we will leave as is.

knutwannheden added a commit that referenced this issue May 12, 2023
knutwannheden added a commit that referenced this issue May 12, 2023
@rpau rpau added this to the Increase our recipe catalog with refaster templates milestone May 29, 2023
@timtebeek
Copy link
Contributor

Perhaps good to use the set of refaster rules developed at Picnic as a threshold of when we sufficiently exclude patterns we don't support yet. We could add the annotation processor there, if accepted, such that their error-prone-contrib module also becomes a rewrite recipe module.

@Stephan202
Copy link
Contributor

We could add the annotation processor there, if accepted, such that their error-prone-contrib module also becomes a rewrite recipe module.

We're certainly open to this! (It's also on my/our TODO list, but speeding that along by submitting a proposal can't hurt 😄.)

@knutwannheden
Copy link
Contributor Author

Currently the big limitations are:

  • No support for generics
  • No support for Refaster library functions or annotations other than BeforeTemplate and AfterTemplate

But we try to detect the cases we don't support and don't generate any code rather than wrong code, so I think we should already be able to get working recipes for a good subset of the rules.

@timtebeek
Copy link
Contributor

Played around with adding the annotation processor to error-prone-support just now; got initial recipe production going through:
mvn clean compile -Dlicense.skipAddThirdParty=true -Dmaven.compiler.failOnError=false

diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml
index 75a31b47..67cda282 100644
--- a/error-prone-contrib/pom.xml
+++ b/error-prone-contrib/pom.xml
@@ -221,6 +221,12 @@
             <artifactId>testng</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.openrewrite</groupId>
+            <artifactId>rewrite-java</artifactId>
+            <version>8.2.0</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -246,12 +252,24 @@
                                 <artifactId>refaster-support</artifactId>
                                 <version>${project.version}</version>
                             </path>
+                            <path>
+                                <groupId>org.openrewrite</groupId>
+                                <artifactId>rewrite-templating</artifactId>
+                                <version>LATEST</version>
+                            </path>
                         </annotationProcessorPaths>
                         <compilerArgs combine.children="append">
                             <arg>-Xplugin:RefasterRuleCompiler</arg>
                             <arg>-Xplugin:DocumentationGenerator -XoutputDirectory=${project.build.directory}/docs</arg>
                         </compilerArgs>
                     </configuration>
+                    <dependencies>
+                        <dependency>
+                            <groupId>org.openrewrite</groupId>
+                            <artifactId>rewrite-java</artifactId>
+                            <version>8.2.0</version>
+                        </dependency>
+                    </dependencies>
                 </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>

That already generates quite come rules, with quite some more rules added if we were to cover Refaster.anyOf(...).
image

@timtebeek timtebeek removed this from the Increase our recipe catalog with refaster templates milestone Nov 30, 2023
@timtebeek
Copy link
Contributor

A bit of a progress update after some recent improvements.

We're now able to generate recipes for some 91 before templates ``` AssortedRulesRecipes$LogicalImplicationRecipe$1_before.java BigDecimalRulesRecipes$BigDecimalValueOfRecipe$1_before.java BugCheckerRulesRecipes$BugCheckerRefactoringTestHelperAddInputLinesExpectUnchangedRecipe$1_before.java BugCheckerRulesRecipes$ConstantsFormatRecipe$1_before.java DoubleStreamRulesRecipes$ConcatOneDoubleStreamRecipe$1_before.java DoubleStreamRulesRecipes$ConcatTwoDoubleStreamsRecipe$1_before.java DoubleStreamRulesRecipes$DoubleStreamAllMatchRecipe$1_before.java DoubleStreamRulesRecipes$DoubleStreamFilterSortedRecipe$1_before.java DoubleStreamRulesRecipes$DoubleStreamMinRecipe$1_before.java DoubleStreamRulesRecipes$DoubleStreamTakeWhileRecipe$1_before.java EqualityRulesRecipes$DoubleNegationRecipe$1_before.java FileRulesRecipes$FilesReadStringRecipe$1_before.java FileRulesRecipes$FilesReadStringWithCharsetRecipe$1_before.java IntStreamRulesRecipes$ConcatOneIntStreamRecipe$1_before.java IntStreamRulesRecipes$ConcatTwoIntStreamsRecipe$1_before.java IntStreamRulesRecipes$IntStreamAllMatchRecipe$1_before.java IntStreamRulesRecipes$IntStreamClosedOpenRangeRecipe$1_before.java IntStreamRulesRecipes$IntStreamFilterSortedRecipe$1_before.java IntStreamRulesRecipes$IntStreamMinRecipe$1_before.java IntStreamRulesRecipes$IntStreamTakeWhileRecipe$1_before.java LongStreamRulesRecipes$ConcatOneLongStreamRecipe$1_before.java LongStreamRulesRecipes$ConcatTwoLongStreamsRecipe$1_before.java LongStreamRulesRecipes$LongStreamAllMatchRecipe$1_before.java LongStreamRulesRecipes$LongStreamClosedOpenRangeRecipe$1_before.java LongStreamRulesRecipes$LongStreamFilterSortedRecipe$1_before.java LongStreamRulesRecipes$LongStreamMinRecipe$1_before.java LongStreamRulesRecipes$LongStreamTakeWhileRecipe$1_before.java MockitoRulesRecipes$InvocationOnMockGetArgumentsRecipe$1_before.java PrimitiveRulesRecipes$BooleanCompareRecipe$1_before.java PrimitiveRulesRecipes$BooleanHashCodeRecipe$1_before.java PrimitiveRulesRecipes$ByteHashCodeRecipe$1_before.java PrimitiveRulesRecipes$CharacterBytesRecipe$1_before.java PrimitiveRulesRecipes$CharacterCompareRecipe$1_before.java PrimitiveRulesRecipes$CharacterHashCodeRecipe$1_before.java PrimitiveRulesRecipes$DoubleBytesRecipe$1_before.java PrimitiveRulesRecipes$DoubleCompareRecipe$1_before.java PrimitiveRulesRecipes$DoubleHashCodeRecipe$1_before.java PrimitiveRulesRecipes$DoubleIsFiniteRecipe$1_before.java PrimitiveRulesRecipes$FloatBytesRecipe$1_before.java PrimitiveRulesRecipes$FloatCompareRecipe$1_before.java PrimitiveRulesRecipes$FloatHashCodeRecipe$1_before.java PrimitiveRulesRecipes$FloatIsFiniteRecipe$1_before.java PrimitiveRulesRecipes$GreaterThanOrEqualToRecipe$1_before.java PrimitiveRulesRecipes$GreaterThanRecipe$1_before.java PrimitiveRulesRecipes$IntegerBytesRecipe$1_before.java PrimitiveRulesRecipes$IntegerCompareRecipe$1_before.java PrimitiveRulesRecipes$IntegerHashCodeRecipe$1_before.java PrimitiveRulesRecipes$LessThanOrEqualToRecipe$1_before.java PrimitiveRulesRecipes$LessThanRecipe$1_before.java PrimitiveRulesRecipes$LongBytesRecipe$1_before.java PrimitiveRulesRecipes$LongCompareRecipe$1_before.java PrimitiveRulesRecipes$LongHashCodeRecipe$1_before.java PrimitiveRulesRecipes$LongToIntExactRecipe$1_before.java PrimitiveRulesRecipes$ShortBytesRecipe$1_before.java PrimitiveRulesRecipes$ShortCompareRecipe$1_before.java PrimitiveRulesRecipes$ShortHashCodeRecipe$1_before.java ReactorRulesRecipes$StepVerifierLastStepVerifyCompleteRecipe$1_before.java ReactorRulesRecipes$StepVerifierLastStepVerifyErrorMessageRecipe$1_before.java ReactorRulesRecipes$StepVerifierLastStepVerifyErrorRecipe$1_before.java ReactorRulesRecipes$StepVerifierLastStepVerifyTimeoutRecipe$1_before.java StringRulesRecipes$StringValueOfRecipe$1_before.java StringRulesRecipes$SubstringRemainderRecipe$1_before.java StringRulesRecipes$Utf8EncodedLengthRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixDeleteRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixPostfixWithRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixPrefixWithRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixReplaceStartEndRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixReplaceTreeRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixReplaceTreeStartEndRecipe$1_before.java SuggestedFixRulesRecipes$SuggestedFixSwapRecipe$1_before.java TimeRulesRecipes$ClockInstantRecipe$1_before.java TimeRulesRecipes$DurationBetweenInstantsRecipe$1_before.java TimeRulesRecipes$DurationOfDaysRecipe$1_before.java TimeRulesRecipes$DurationOfHoursRecipe$1_before.java TimeRulesRecipes$DurationOfMillisRecipe$1_before.java TimeRulesRecipes$DurationOfMinutesRecipe$1_before.java TimeRulesRecipes$DurationOfNanosRecipe$1_before.java TimeRulesRecipes$DurationOfSecondsRecipe$1_before.java TimeRulesRecipes$InstantAtOffsetRecipe$1_before.java TimeRulesRecipes$InstantAtZoneRecipe$1_before.java TimeRulesRecipes$LocalDateAtStartOfDayRecipe$1_before.java TimeRulesRecipes$OffsetDateTimeOfInstantRecipe$1_before.java TimeRulesRecipes$OffsetTimeOfInstantRecipe$1_before0.java TimeRulesRecipes$OffsetTimeOfInstantRecipe$1_before.java TimeRulesRecipes$UtcClockRecipe$1_before.java WebClientRulesRecipes$WebClientPatchRecipe$1_before0.java WebClientRulesRecipes$WebClientPatchRecipe$1_before.java WebClientRulesRecipes$WebClientPostRecipe$1_before0.java WebClientRulesRecipes$WebClientPostRecipe$1_before.java WebClientRulesRecipes$WebClientPutRecipe$1_before0.java WebClientRulesRecipes$WebClientPutRecipe$1_before.java ```

Here you can see what changes I've made so far to add rewrite-templating to error-prone-support:

There's one small caveat: one particular recipe does not want to work yet, and I don't yet know how to skip that:

When I comment out that one problematic recipe OrOrElseThrow in error-prone-support, then the error-prone-contrib jar can also be used as a recipe jar.

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
  -Drewrite.activeRecipes=tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes \
  -Drewrite.recipeArtifactCoordinates=tech.picnic.error-prone-support:error-prone-contrib:LATEST,org.openrewrite:rewrite-templating:LATEST

Note how rewrite-templating also needs to be passing in through recipeArtifactCoordinates as that's not a transitive dependency.

Or as 102 discovered recipes
$ mvn -U org.openrewrite.maven:rewrite-maven-plugin:discover -Drewrite.recipeArtifactCoordinates=tech.picnic.error-prone-support:error-prone-contrib:0.14.1-SNAPSHOT,org.openrewrite:rewrite-templating:LATEST

tim@tim-xps-15-9520:~/Documents/workspace/spring-projects/spring-petclinic$ mvn -U org.openrewrite.maven:rewrite-maven-plugin:discover -Drewrite.recipeArtifactCoordinates=tech.picnic.error-prone-support:error-prone-contrib:0.14.1-SNAPSHOT,org.openrewrite:rewrite-templating:LATEST 
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloading from spring-milestones: https://repo.spring.io/milestone/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml (5.1 kB at 26 kB/s)
[INFO] 
[INFO] ------------< org.springframework.samples:spring-petclinic >------------
[INFO] Building petclinic 3.2.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- rewrite:5.15.5:discover (default-cli) @ spring-petclinic ---
Downloading from spring-snapshots: https://repo.spring.io/snapshot/tech/picnic/error-prone-support/error-prone-contrib/0.14.1-SNAPSHOT/maven-metadata.xml
Downloading from spring-snapshots: https://repo.spring.io/snapshot/tech/picnic/error-prone-support/error-prone-support/0.14.1-SNAPSHOT/maven-metadata.xml
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloading from spring-milestones: https://repo.spring.io/milestone/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-templating/maven-metadata.xml (805 B at 67 kB/s)
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/rewrite-templating/1.4.0-SNAPSHOT/maven-metadata.xml
[INFO] Available Recipes:
[INFO]     tech.picnic.errorprone.refasterrules.AssortedRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.AssortedRulesRecipes$LogicalImplicationRecipe
[INFO]     tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes$BigDecimalValueOfRecipe
[INFO]     tech.picnic.errorprone.refasterrules.BugCheckerRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.BugCheckerRulesRecipes$BugCheckerRefactoringTestHelperAddInputLinesExpectUnchangedRecipe
[INFO]     tech.picnic.errorprone.refasterrules.BugCheckerRulesRecipes$ConstantsFormatRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$ConcatOneDoubleStreamRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$ConcatTwoDoubleStreamsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$DoubleStreamAllMatchRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$DoubleStreamFilterSortedRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$DoubleStreamMinRecipe
[INFO]     tech.picnic.errorprone.refasterrules.DoubleStreamRulesRecipes$DoubleStreamTakeWhileRecipe
[INFO]     tech.picnic.errorprone.refasterrules.EqualityRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.EqualityRulesRecipes$DoubleNegationRecipe
[INFO]     tech.picnic.errorprone.refasterrules.FileRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.FileRulesRecipes$FilesReadStringRecipe
[INFO]     tech.picnic.errorprone.refasterrules.FileRulesRecipes$FilesReadStringWithCharsetRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$ConcatOneIntStreamRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$ConcatTwoIntStreamsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$IntStreamAllMatchRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$IntStreamClosedOpenRangeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$IntStreamFilterSortedRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$IntStreamMinRecipe
[INFO]     tech.picnic.errorprone.refasterrules.IntStreamRulesRecipes$IntStreamTakeWhileRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$ConcatOneLongStreamRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$ConcatTwoLongStreamsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$LongStreamAllMatchRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$LongStreamClosedOpenRangeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$LongStreamFilterSortedRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$LongStreamMinRecipe
[INFO]     tech.picnic.errorprone.refasterrules.LongStreamRulesRecipes$LongStreamTakeWhileRecipe
[INFO]     tech.picnic.errorprone.refasterrules.MockitoRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.MockitoRulesRecipes$InvocationOnMockGetArgumentsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$BooleanCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$BooleanHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$ByteHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$CharacterBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$CharacterCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$CharacterHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$DoubleBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$DoubleCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$DoubleHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$DoubleIsFiniteRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$FloatBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$FloatCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$FloatHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$FloatIsFiniteRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$GreaterThanOrEqualToRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$GreaterThanRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$IntegerBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$IntegerCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$IntegerHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LessThanOrEqualToRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LessThanRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LongBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LongCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LongHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$LongToIntExactRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$ShortBytesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$ShortCompareRecipe
[INFO]     tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes$ShortHashCodeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.ReactorRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.ReactorRulesRecipes$StepVerifierLastStepVerifyCompleteRecipe
[INFO]     tech.picnic.errorprone.refasterrules.ReactorRulesRecipes$StepVerifierLastStepVerifyErrorMessageRecipe
[INFO]     tech.picnic.errorprone.refasterrules.ReactorRulesRecipes$StepVerifierLastStepVerifyErrorRecipe
[INFO]     tech.picnic.errorprone.refasterrules.ReactorRulesRecipes$StepVerifierLastStepVerifyTimeoutRecipe
[INFO]     tech.picnic.errorprone.refasterrules.StringRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.StringRulesRecipes$StringValueOfRecipe
[INFO]     tech.picnic.errorprone.refasterrules.StringRulesRecipes$SubstringRemainderRecipe
[INFO]     tech.picnic.errorprone.refasterrules.StringRulesRecipes$Utf8EncodedLengthRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixDeleteRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixPostfixWithRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixPrefixWithRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixReplaceStartEndRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixReplaceTreeRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixReplaceTreeStartEndRecipe
[INFO]     tech.picnic.errorprone.refasterrules.SuggestedFixRulesRecipes$SuggestedFixSwapRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$ClockInstantRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationBetweenInstantsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfDaysRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfHoursRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfMillisRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfMinutesRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfNanosRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$DurationOfSecondsRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$InstantAtOffsetRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$InstantAtZoneRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$LocalDateAtStartOfDayRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$OffsetDateTimeOfInstantRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$OffsetTimeOfInstantRecipe
[INFO]     tech.picnic.errorprone.refasterrules.TimeRulesRecipes$UtcClockRecipe
[INFO]     tech.picnic.errorprone.refasterrules.WebClientRulesRecipes
[INFO]     tech.picnic.errorprone.refasterrules.WebClientRulesRecipes$WebClientPatchRecipe
[INFO]     tech.picnic.errorprone.refasterrules.WebClientRulesRecipes$WebClientPostRecipe
[INFO]     tech.picnic.errorprone.refasterrules.WebClientRulesRecipes$WebClientPutRecipe
[INFO] 
[INFO] Available Styles:
[INFO] 
[INFO] Active Styles:
[INFO] 
[INFO] Active Recipes:
[INFO] 
[INFO] Found 102 available recipes and 0 available styles.
[INFO] Configured with 0 active recipes and 0 active styles.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.941 s
[INFO] Finished at: 2023-12-16T17:48:33+01:00
[INFO] ------------------------------------------------------------------------

One notable difference between the error-prone-support recipes and OpenRewrite refaster recipes is that we don't pick up the Javadocs attached to the first for documentation, while we also lack @RecipeDescriptor annotation that we add to our own.

That means we end up with generic generated documentation only
tim@tim-xps-15-9520:~/Documents/workspace/spring-projects/spring-petclinic$ mvn -U org.openrewrite.maven:rewrite-maven-plugin:discover -Drewrite.recipeArtifactCoordinates=tech.picnic.error-prone-support:error-prone-contrib:0.14.1-SNAPSHOT,org.openrewrite:rewrite-templating:LATEST -Drecipe=tech.picnic.errorprone.refasterrules.StringRulesRecipes -Ddetail=true
[INFO] Scanning for projects...
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloading from spring-milestones: https://repo.spring.io/milestone/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openrewrite/maven/rewrite-maven-plugin/maven-metadata.xml (5.1 kB at 37 kB/s)
[INFO] 
[INFO] ------------< org.springframework.samples:spring-petclinic >------------
[INFO] Building petclinic 3.2.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- rewrite:5.15.5:discover (default-cli) @ spring-petclinic ---
Downloading from spring-snapshots: https://repo.spring.io/snapshot/tech/picnic/error-prone-support/error-prone-contrib/0.14.1-SNAPSHOT/maven-metadata.xml
Downloading from spring-snapshots: https://repo.spring.io/snapshot/tech/picnic/error-prone-support/error-prone-support/0.14.1-SNAPSHOT/maven-metadata.xml
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloading from spring-milestones: https://repo.spring.io/milestone/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-templating/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openrewrite/rewrite-templating/maven-metadata.xml (805 B at 62 kB/s)
Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/openrewrite/rewrite-templating/1.4.0-SNAPSHOT/maven-metadata.xml
[INFO] `StringRules` Refaster recipes
[INFO]     tech.picnic.errorprone.refasterrules.StringRulesRecipes
[INFO]     Refaster template recipes for `tech.picnic.errorprone.refasterrules.StringRules`.
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.747 s
[INFO] Finished at: 2023-12-16T17:52:58+01:00
[INFO] ------------------------------------------------------------------------

Once we add support for Refaster.anyOf(...) we would be able to cover many more recipes:

All in all nice progress, with some improvements to be made still, but this would allow us to run these rules as recipes, and allow applying those at scale.

@knutwannheden
Copy link
Contributor Author

It would be interesting if we could also get the test cases of these Refaster templates to work to verify our recipes. I am sure that could help surface some bugs.

@timtebeek
Copy link
Contributor

Ok problematic case fixed; that then leaves some license & JavaDoc warnings to fix, but I think we have enough to open a draft PR ; Would you agree @Stephan202 ?

@Stephan202
Copy link
Contributor

Very cool! Yes, @rickie and I would be happy to review! 🚀

@timtebeek
Copy link
Contributor

Done!

@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
4 participants