I started to playing with OpenRewrite and what I need is to use OpenRewrite to change the formatting of curly braces (for all the Java classes and interfaces).
So from this:
public class Foo
{
// something here
}
to have this:
public class Foo { // <-- left curly bracket on the same line as a class name
// something here
}
I was trying to achieve this with simple existing org.openrewrite.java.format.AutoFormat
recipe, but it seems this one completely ignores the curly braces.
Then I tried to write some custom recipe and I was playing with method autoFormat
. Something like this:
@Override
public J.ClassDeclaration visitClassDeclaration(final J.ClassDeclaration classDec, final ExecutionContext executionContext) {
return autoFormat(classDec, executionContext);
}
but it seems that autoFormat
just uses AutoFormatVisitor
and it seems to me that this one is also used by existing org.openrewrite.java.format.AutoFormat
recipe - so it doesn't have the desired effect.
Could you please point me to some idea how this can be solved by OpenRewrite?
UPDATE I tried to apply default IntelliJ style.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.44.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.format.AutoFormat</recipe>
</activeRecipes>
<activeStyles>
<style>org.openrewrite.java.style.IntelliJ</style>
</activeStyles>
</configuration>
</plugin>
but it still didn't change the curly brackets.