Questions tagged [openrewrite]

OpenRewrite is a software product that automates refactoring of code. Use this tag for questions regarding the OpenRewrite product.

OpenRewrite enables large-scale distributed source code refactoring.

OpenRewrite is hosted on GitHub: https://github.com/openrewrite
There is also a documentation site: https://docs.openrewrite.org/

43 questions
1
vote
1 answer

How to add a line comment just after a method with OpenRewrite

What I want to do I am trying to add single-line comments around a method annotated with Lombok's @Generated to tell Parasoft Jtest to suppress the reporting of findings in the method like this: class FooBar { // parasoft-begin-suppress ALL …
SATO Yusuke
  • 1,600
  • 15
  • 39
1
vote
1 answer

how to replace an annotation with his Attribute with openrewrite?

To migrate a java API I need to replace an annotation with the value of an attribute and I'm looking for how to do it: Before: @Foo(values = {@Bar(value="one"), @Bar(Value="two")}) private void stuff() { } After : @Foo(values = {…
pdesprez
  • 49
  • 1
  • 3
1
vote
1 answer

JavaVisitor vs. JavaIsoVisitor: When to use what?

I wonder, what the difference between JavaVistitor and JavaIsoVisittor is. When shall I use what. This is not clear to me from the documentatio https://docs.openrewrite.org/.
MGK
  • 101
  • 5
1
vote
1 answer

Openrewrite: Run unit test in the IDE (IntelliJ) that uses classes from the same multiproject (not packages in a jar)

My unit test in optaplanner-rewrite has this code using OpenRewrite bom 1.11.0: @Override public void defaults(RecipeSpec spec) { spec.recipe(new AsConstraintBuilder()) .parser(JavaParser.fromJavaVersion() …
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
1
vote
1 answer

Openrewrite: how do I replace a method with 2 parameters `foo(a, b)` by 2 methods with 1 parameter each `foo(a).bar(b)`?

I want to convert x.foo(a, b); into x.foo(a).bar(b); I can easily match for acme.X foo(acme.A, acme.B), but how do I build a JavaTemplate that can do that replacement for me? When I run @Override protected TreeVisitor
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
1
vote
2 answers

OpenRewrite: problem with custom Recipe and doAfterVisit method

I am trying to make a custom recipe with the following logic: If I find a specific value for a property found in a yaml file, then I add a maven dependency to pom.xml. In principle it seems to be an easy case, but I can't get it to work... For this…
0
votes
0 answers

Why WebMvcConfigurerAdapter class is not replaced by openrewrite while upgrading to spring boot 3.1

WebMvcConfigurerAdapter is deprecated of course and I know what to use instead of it. But my question is 'was the replacement not taken care in the recipe' Similarly I see that OrderImpl class from hibernate is deprecated and was not taken care by…
Randhir Ray
  • 540
  • 5
  • 14
0
votes
0 answers

OpenRewrite: recipes example for adding a new key: value pair if a specific template matches in yaml

I have multiple yaml files, but we have to add a addition parameter only if specific template matches. Ex: stages: - template: templates/my-java-service-v1.yaml@codeway parameters: lintingParams: skipSchemaValidation: false …
0
votes
1 answer

OpenRewrite: AddCommentToMavenDependencymaven recipe not working with given POM

I am trying to use AddCommentToMavenDependency recipe to add a comment line inside a dependency declaration. But I think I am not able to provide the correct xpath, please correct. recipeList: - org.openrewrite.maven.AddCommentToMavenDependency: …
0
votes
1 answer

When updating from spring boot 2.7 to 3 with openrewrite I get a Java heap space error

I am trying to migrate from Spring Boot 2.7 to 3 using openrewrite.recipe:rewrite-spring:5.0.3 I am using Java 17 and running the plugin in the command line like this: mvn -U org.openrewrite.maven:rewrite-maven-plugin:run…
0
votes
1 answer

openRewrite: Unable to configure org.openrewrite.java.spring.framework.UpgradeSpringFrameworkDependencies

Getting below warning error while running UpgradeSpringBoot_3_0 recipe through maven command line. mvn -U org.openrewrite.maven:rewrite-maven-plugin:dryRun -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE …
0
votes
0 answers

OpenRewrite: Add dependencies in Maven POM

I am trying to add a Spring cloud dependencies through OpenRewrite recipe:- io.awspring.cloud spring-cloud-aws-starter tried with org.openrewrite.maven.AddDependency ,…
0
votes
1 answer

Facing Error while creating a custom recipe to add log level guard

I am trying to create a snippet using Java parser to add a if block. Expression condition = JavaParser.buildSnippet( String.format("if (logger.%sEnabled())", logLevel) ).get(0); For the above code, I am getting error in buildSnippet()…
0
votes
1 answer

OpenRewrite: Can we have recipe to change Java or Spring library Import

Can we change import in java class, ex: import org.springframework.security.oauth2.client.OAuth2RestTemplate; to import org.springframework.web.client.RestTemplate; We have one ChangePackage recipe but it is only working with user predefine packages…
0
votes
1 answer

OpenRewrite: recipes example for adding a new key: value pair in yaml

I want to append a new key: value pair in one of .yaml file as below:- stages: - template: myproject/scops-java-service-v1.yaml@codeway parameters: **newKey: newValue** lintingParams: skipSchemaValidation: false I tried with…