From bd71d36cc83cba028c920d8aae60ce341afa2324 Mon Sep 17 00:00:00 2001 From: Dwouglas Mhagnum Date: Sun, 26 Apr 2026 13:37:56 -0300 Subject: [PATCH 1/3] refactor: rename recipe classes for clearer semantics Rename recipe classes to better describe their detection mechanism: - FormatSqlBlockRecipe -> FormatSqlTextBlockByAnnotation (detects SQL in Text Blocks via annotations like @HQL, @SQL, @Query) - FormatSqlTextBlockRecipe -> FormatSqlTextBlockByLanguageInjection (detects SQL in Text Blocks via // language=sql comment) BREAKING CHANGE: Update your configurations accordingly. See CHANGELOG.md for the migration table. --- .vscode/settings.json | 3 +- CHANGELOG.md | 27 ++++++++++++ README.md | 42 +++++++++---------- ...va => FormatSqlTextBlockByAnnotation.java} | 4 +- ...ormatSqlTextBlockByLanguageInjection.java} | 4 +- .../resources/META-INF/rewrite/examples.yml | 8 ++-- ...> FormatSqlTextBlockByAnnotationTest.java} | 6 +-- ...tSqlTextBlockByLanguageInjectionTest.java} | 4 +- 8 files changed, 63 insertions(+), 35 deletions(-) create mode 100644 CHANGELOG.md rename src/main/java/io/github/mhagnumdw/{FormatSqlBlockRecipe.java => FormatSqlTextBlockByAnnotation.java} (91%) rename src/main/java/io/github/mhagnumdw/{FormatSqlTextBlockRecipe.java => FormatSqlTextBlockByLanguageInjection.java} (93%) rename src/test/java/io/github/mhagnumdw/{FormatSqlBlockRecipeTest.java => FormatSqlTextBlockByAnnotationTest.java} (98%) rename src/test/java/io/github/mhagnumdw/{FormatSqlTextBlockRecipeTest.java => FormatSqlTextBlockByLanguageInjectionTest.java} (98%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 706a886..869d2fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "sonarlint.connectedMode.project": { "connectionId": "SonarQube for IDE - Visual Studio Code", "projectKey": "mhagnumdw_rewrite-format-sql" - } + }, + "java.compile.nullAnalysis.mode": "automatic" } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b76eb92 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,27 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Breaking Changes + +- **Renamed recipes** (class names changed - update your configurations): + - `FormatSqlBlockRecipe` → `FormatSqlTextBlockByAnnotation` + - `FormatSqlTextBlockRecipe` → `FormatSqlTextBlockByLanguageInjection` + + Update your `pom.xml`, `rewrite.yml`, or CLI arguments accordingly: + + | Old Name | New Name | + |---------|---------| + | `io.github.mhagnumdw.FormatSqlBlockRecipe` | `io.github.mhagnumdw.FormatSqlTextBlockByAnnotation` | + | `io.github.mhagnumdw.FormatSqlTextBlockRecipe` | `io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection` | + +### Added + +- New recipe names that better describe their purpose: + - `FormatSqlTextBlockByAnnotation` - formats SQL in Text Blocks by annotation (`@HQL`, `@SQL`, `@Query`) + - `FormatSqlTextBlockByLanguageInjection` - formats SQL in Text Blocks marked with `// language=sql` comment diff --git a/README.md b/README.md index 7b20227..5d2297c 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ A set of [OpenRewrite](https://docs.openrewrite.org/) recipes for formatting SQL/HQL code. - [Recipes](#recipes) - - [FormatSqlBlockRecipe](#formatsqlblockrecipe) - - [FormatSqlTextBlockRecipe](#formatsqltextblockrecipe) + - [FormatSqlTextBlockByAnnotation](#formatsqltextblockbyannotation) + - [FormatSqlTextBlockByLanguageInjection](#formatsqltextblockbylanguageinjection) - [FormatSqlFileRecipe](#formatsqlfilerecipe) - [Configurable Options](#configurable-options) - [Examples](#examples) - - [FormatSqlBlockRecipe Example](#formatsqlblockrecipe-example) - - [FormatSqlTextBlockRecipe Example](#formatsqltextblockrecipe-example) - - [FormatSqlFileRecipe Example](#formatsqlfilerecipe-example) + - [FormatSqlTextBlockByAnnotation example](#formatsqltextblockbyannotation-example) + - [FormatSqlTextBlockByLanguageInjection example](#formatsqltextblockbylanguageinjection-example) + - [FormatSqlFileRecipe example](#formatsqlfilerecipe-example) - [Usage](#usage) - [Configuring in `pom.xml`](#configuring-in-pomxml) - [Without adding anything to the project](#without-adding-anything-to-the-project) @@ -25,9 +25,9 @@ A set of [OpenRewrite](https://docs.openrewrite.org/) recipes for formatting SQL Below is a detailed description of each Recipe. -### FormatSqlBlockRecipe +### FormatSqlTextBlockByAnnotation -The `io.github.mhagnumdw.FormatSqlBlockRecipe` recipe automatically formats SQL or HQL embedded in [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) present in the following annotations: +The `io.github.mhagnumdw.FormatSqlTextBlockByAnnotation` recipe automatically formats SQL or HQL embedded in [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) present in the following annotations: - `org.hibernate.annotations.processing.HQL` - `org.hibernate.annotations.processing.SQL` @@ -35,9 +35,9 @@ The `io.github.mhagnumdw.FormatSqlBlockRecipe` recipe automatically formats SQL > Future enhancements may allow configuration of custom annotations. Please open an issue. -### FormatSqlTextBlockRecipe +### FormatSqlTextBlockByLanguageInjection -The `io.github.mhagnumdw.FormatSqlTextBlockRecipe` recipe formats SQL code in Java [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) that are preceded by a `// language=sql` comment (case-insensitive). +The `io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection` recipe formats SQL code in Java [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) that are preceded by a `// language=sql` comment (case-insensitive). This is the same [language injection comment](https://www.jetbrains.com/help/idea/language-injections.html) recognized by IntelliJ IDEA for SQL syntax highlighting. @@ -47,11 +47,11 @@ The `io.github.mhagnumdw.FormatSqlFileRecipe` recipe automatically formats the c ## Configurable Options -The following options are applicable to `FormatSqlBlockRecipe`, `FormatSqlTextBlockRecipe`, and `FormatSqlFileRecipe`: +The following options are applicable to `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection`, and `FormatSqlFileRecipe`: | Type | Name | Description | Example | Default Value | | :------ | :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :------------------------- | -| String | `filePath` | Optional. The path to the files that the Recipe should process. Accepts a glob expression; multiple patterns can be specified, separated by a semicolon `;`. If omitted, processes all matching files. | `**/*DAO.java`
`**/*.sql` | FormatSqlBlockRecipe: `**/*.java`
FormatSqlTextBlockRecipe: `**/*.java`
FormatSqlFileRecipe: `**/*.sql` | +| String | `filePath` | Optional. The path to the files that the Recipe should process. Accepts a glob expression; multiple patterns can be specified, separated by a semicolon `;`. If omitted, processes all matching files. | `**/*DAO.java`
`**/*.sql` | FormatSqlTextBlockByAnnotation: `**/*.java`
FormatSqlTextBlockByLanguageInjection: `**/*.java`
FormatSqlFileRecipe: `**/*.sql` | | String | `sqlDialect` | Optional. The SQL dialect to be used for formatting. Valid options: `sql` (StandardSql), `mysql`, `postgresql`, `db2`, `plsql` (Oracle PL/SQL), `n1ql` (Couchbase N1QL), `redshift`, `spark`, `tsql` (SQL Server Transact-SQL). Details [here](https://github.com/vertical-blank/sql-formatter). | `plsql` | `sql` | | String | `indent` | Optional. The string to be used for indentation. | `" "` for 2 spaces
`"\t"` for a tab | 4 spaces `" "` | | Integer | `maxColumnLength` | Optional. The maximum length of a line before the formatter tries to break it. | `100` | `120` | @@ -59,7 +59,7 @@ The following options are applicable to `FormatSqlBlockRecipe`, `FormatSqlTextBl ## Examples -### FormatSqlBlockRecipe Example +### FormatSqlTextBlockByAnnotation example Before @@ -99,7 +99,7 @@ public interface HolidayRepository { } ``` -### FormatSqlTextBlockRecipe Example +### FormatSqlTextBlockByLanguageInjection example Before @@ -126,7 +126,7 @@ private static final String QUERY = """ u.name"""; ``` -### FormatSqlFileRecipe Example +### FormatSqlFileRecipe example Consider the following `example.sql` file: @@ -174,8 +174,8 @@ Inside the plugins section, add: - io.github.mhagnumdw.FormatSqlBlockRecipe - io.github.mhagnumdw.FormatSqlTextBlockRecipe + io.github.mhagnumdw.FormatSqlTextBlockByAnnotation + io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection io.github.mhagnumdw.FormatSqlFileRecipe false @@ -204,12 +204,12 @@ type: specs.openrewrite.org/v1beta/recipe name: io.github.mhagnumdw.FormatSqlCustomConfig recipeList: # Add the Recipes you want to use here - - io.github.mhagnumdw.FormatSqlBlockRecipe: + - io.github.mhagnumdw.FormatSqlTextBlockByAnnotation: sqlDialect: "plsql" - - io.github.mhagnumdw.FormatSqlTextBlockRecipe: + - io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection: sqlDialect: "plsql" - io.github.mhagnumdw.FormatSqlFileRecipe: - sqlDialect: "mysql" + sqlDialect: "plsql" ``` > - This file is a way to create your own custom recipe from other recipes. @@ -223,7 +223,7 @@ And change the `` tag in `pom.xml` to: io.github.mhagnumdw.FormatSqlCustomConfig ``` -> As in this example the `FormatSqlCustomConfig` recipe includes both `FormatSqlBlockRecipe`, `FormatSqlTextBlockRecipe` and `FormatSqlFileRecipe` recipes, in `pom.xml` it is only necessary to define the `FormatSqlCustomConfig` recipe. +> As in this example the `FormatSqlCustomConfig` recipe includes both `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection` and `FormatSqlFileRecipe` recipes, in `pom.xml` it is only necessary to define the `FormatSqlCustomConfig` recipe. Then run: @@ -239,7 +239,7 @@ This mode is indicated if your intention is to run the recipe only once. ```bash ./mvnw org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.activeRecipes=io.github.mhagnumdw.FormatSqlBlockRecipe,io.github.mhagnumdw.FormatSqlTextBlockRecipe,io.github.mhagnumdw.FormatSqlFileRecipe \ + -Drewrite.activeRecipes=io.github.mhagnumdw.FormatSqlTextBlockByAnnotation,io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection,io.github.mhagnumdw.FormatSqlFileRecipe \ -Drewrite.recipeArtifactCoordinates=io.github.mhagnumdw:rewrite-format-sql:1.0.0 ``` diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlBlockRecipe.java b/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java similarity index 91% rename from src/main/java/io/github/mhagnumdw/FormatSqlBlockRecipe.java rename to src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java index 6ccf2af..b6be299 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlBlockRecipe.java +++ b/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java @@ -18,12 +18,12 @@ */ @Value @EqualsAndHashCode(callSuper = false) -public class FormatSqlBlockRecipe extends FormatSqlRecipeAbstract { +public class FormatSqlTextBlockByAnnotation extends FormatSqlRecipeAbstract { private static final String DEFAULT_FILE_PATH = "**/*.java"; @JsonCreator - public FormatSqlBlockRecipe(@Nullable @JsonProperty("filePath") String filePath, + public FormatSqlTextBlockByAnnotation(@Nullable @JsonProperty("filePath") String filePath, @Nullable @JsonProperty("sqlDialect") String sqlDialect, @Nullable @JsonProperty("indent") String indent, @Nullable @JsonProperty("maxColumnLength") Integer maxColumnLength, diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockRecipe.java b/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java similarity index 93% rename from src/main/java/io/github/mhagnumdw/FormatSqlTextBlockRecipe.java rename to src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java index d50565f..d02956c 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockRecipe.java +++ b/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java @@ -15,12 +15,12 @@ @Value @EqualsAndHashCode(callSuper = false) -public class FormatSqlTextBlockRecipe extends FormatSqlRecipeAbstract { +public class FormatSqlTextBlockByLanguageInjection extends FormatSqlRecipeAbstract { private static final String DEFAULT_FILE_PATH = "**/*.java"; @JsonCreator - public FormatSqlTextBlockRecipe( + public FormatSqlTextBlockByLanguageInjection( @Nullable @JsonProperty("filePath") String filePath, @Nullable @JsonProperty("sqlDialect") String sqlDialect, @Nullable @JsonProperty("indent") String indent, diff --git a/src/main/resources/META-INF/rewrite/examples.yml b/src/main/resources/META-INF/rewrite/examples.yml index 215aa43..aada8a9 100644 --- a/src/main/resources/META-INF/rewrite/examples.yml +++ b/src/main/resources/META-INF/rewrite/examples.yml @@ -1,8 +1,8 @@ --- type: specs.openrewrite.org/v1beta/example -recipeName: io.github.mhagnumdw.FormatSqlBlockRecipe +recipeName: io.github.mhagnumdw.FormatSqlTextBlockByAnnotation examples: -- description: '`FormatSqlBlockRecipeTest#shouldFormatSimpleSqlBlock`' +- description: '`FormatSqlTextBlockByAnnotationTest#shouldFormatSimpleSqlBlock`' parameters: - io/github/mhagnumdw/fake/holidays/HolidayRepository.java - plsql @@ -45,9 +45,9 @@ examples: language: java --- type: specs.openrewrite.org/v1beta/example -recipeName: io.github.mhagnumdw.FormatSqlTextBlockRecipe +recipeName: io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection examples: -- description: '`FormatSqlTextBlockRecipeTest#shouldFormatFieldWithLanguageSqlComment`' +- description: '`FormatSqlTextBlockByLanguageInjectionTest#shouldFormatFieldWithLanguageSqlComment`' parameters: - io/github/mhagnumdw/test/*.java - sql diff --git a/src/test/java/io/github/mhagnumdw/FormatSqlBlockRecipeTest.java b/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java similarity index 98% rename from src/test/java/io/github/mhagnumdw/FormatSqlBlockRecipeTest.java rename to src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java index 9dfaeee..c3bd550 100644 --- a/src/test/java/io/github/mhagnumdw/FormatSqlBlockRecipeTest.java +++ b/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java @@ -15,12 +15,12 @@ import org.openrewrite.test.RewriteTest; @SuppressWarnings("java:S2699") -class FormatSqlBlockRecipeTest implements RewriteTest { +class FormatSqlTextBlockByAnnotationTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec.recipe( - new FormatSqlBlockRecipe( + new FormatSqlTextBlockByAnnotation( "io/github/mhagnumdw/fake/holidays/HolidayRepository.java", "plsql", null, @@ -157,7 +157,7 @@ void shouldFormatSqlBlockWithTabs() { rewriteRun( spec -> spec.recipe( - new FormatSqlBlockRecipe( + new FormatSqlTextBlockByAnnotation( "io/github/mhagnumdw/fake/holidays/HolidayRepository.java", "plsql", "\t", // Use tab for SQL block indentation diff --git a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockRecipeTest.java b/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java similarity index 98% rename from src/test/java/io/github/mhagnumdw/FormatSqlTextBlockRecipeTest.java rename to src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java index 1b117b7..160e925 100644 --- a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockRecipeTest.java +++ b/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java @@ -10,12 +10,12 @@ // SonarQube doesn't recognize internal assertions in rewriteRun() @SuppressWarnings("java:S2699") -class FormatSqlTextBlockRecipeTest implements RewriteTest { +class FormatSqlTextBlockByLanguageInjectionTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec.recipe( - new FormatSqlTextBlockRecipe( + new FormatSqlTextBlockByLanguageInjection( "io/github/mhagnumdw/test/*.java", "sql", null, From c3cb1854d1995487a9cac3e58d6a8cd3921c746f Mon Sep 17 00:00:00 2001 From: Dwouglas Mhagnum Date: Sun, 26 Apr 2026 14:27:04 -0300 Subject: [PATCH 2/3] move between packages --- .vscode/settings.json | 3 +- CHANGELOG.md | 5 ++-- README.md | 28 +++++++++---------- .../AnnotationOnlyOneArgumentProcessor.java | 2 +- .../{ => recipes}/FormatSqlFileRecipe.java | 3 +- .../FormatSqlRecipeAbstract.java | 2 +- .../FormatSqlTextBlockByAnnotation.java | 3 +- ...FormatSqlTextBlockByLanguageInjection.java | 3 +- .../mhagnumdw/{ => utils}/TextBlockUtil.java | 2 +- .../{ => visitors}/FormatSqlBlockVisitor.java | 4 +-- .../{ => visitors}/FormatSqlFileVisitor.java | 2 +- .../FormatSqlTextBlockVisitor.java | 5 ++-- .../resources/META-INF/rewrite/examples.yml | 4 +-- .../FormatSqlFileRecipeTest.java | 2 +- .../FormatSqlTextBlockByAnnotationTest.java | 2 +- ...atSqlTextBlockByLanguageInjectionTest.java | 2 +- 16 files changed, 38 insertions(+), 34 deletions(-) rename src/main/java/io/github/mhagnumdw/{ => recipes}/FormatSqlFileRecipe.java (94%) rename src/main/java/io/github/mhagnumdw/{ => recipes}/FormatSqlRecipeAbstract.java (99%) rename src/main/java/io/github/mhagnumdw/{ => recipes}/FormatSqlTextBlockByAnnotation.java (95%) rename src/main/java/io/github/mhagnumdw/{ => recipes}/FormatSqlTextBlockByLanguageInjection.java (95%) rename src/main/java/io/github/mhagnumdw/{ => utils}/TextBlockUtil.java (99%) rename src/main/java/io/github/mhagnumdw/{ => visitors}/FormatSqlBlockVisitor.java (89%) rename src/main/java/io/github/mhagnumdw/{ => visitors}/FormatSqlFileVisitor.java (97%) rename src/main/java/io/github/mhagnumdw/{ => visitors}/FormatSqlTextBlockVisitor.java (94%) rename src/test/java/io/github/mhagnumdw/{ => recipes}/FormatSqlFileRecipeTest.java (98%) rename src/test/java/io/github/mhagnumdw/{ => recipes}/FormatSqlTextBlockByAnnotationTest.java (99%) rename src/test/java/io/github/mhagnumdw/{ => recipes}/FormatSqlTextBlockByLanguageInjectionTest.java (99%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 869d2fe..706a886 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,5 @@ "sonarlint.connectedMode.project": { "connectionId": "SonarQube for IDE - Visual Studio Code", "projectKey": "mhagnumdw_rewrite-format-sql" - }, - "java.compile.nullAnalysis.mode": "automatic" + } } diff --git a/CHANGELOG.md b/CHANGELOG.md index b76eb92..e294195 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | Old Name | New Name | |---------|---------| - | `io.github.mhagnumdw.FormatSqlBlockRecipe` | `io.github.mhagnumdw.FormatSqlTextBlockByAnnotation` | - | `io.github.mhagnumdw.FormatSqlTextBlockRecipe` | `io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection` | + | `io.github.mhagnumdw.FormatSqlFileRecipe` | `io.github.mhagnumdw.recipes.FormatSqlFileRecipe` | + | `io.github.mhagnumdw.FormatSqlBlockRecipe` | `io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation` | + | `io.github.mhagnumdw.FormatSqlTextBlockRecipe` | `io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection` | ### Added diff --git a/README.md b/README.md index 5d2297c..223696e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Below is a detailed description of each Recipe. ### FormatSqlTextBlockByAnnotation -The `io.github.mhagnumdw.FormatSqlTextBlockByAnnotation` recipe automatically formats SQL or HQL embedded in [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) present in the following annotations: +The `io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation` recipe automatically formats SQL or HQL embedded in [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) present in the following annotations: - `org.hibernate.annotations.processing.HQL` - `org.hibernate.annotations.processing.SQL` @@ -37,13 +37,13 @@ The `io.github.mhagnumdw.FormatSqlTextBlockByAnnotation` recipe automatically fo ### FormatSqlTextBlockByLanguageInjection -The `io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection` recipe formats SQL code in Java [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) that are preceded by a `// language=sql` comment (case-insensitive). +The `io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection` recipe formats SQL code in Java [Text Blocks](https://docs.oracle.com/en/java/javase/13/text_blocks/index.html) that are preceded by a `// language=sql` comment (case-insensitive). This is the same [language injection comment](https://www.jetbrains.com/help/idea/language-injections.html) recognized by IntelliJ IDEA for SQL syntax highlighting. ### FormatSqlFileRecipe -The `io.github.mhagnumdw.FormatSqlFileRecipe` recipe automatically formats the content of SQL files. +The `io.github.mhagnumdw.recipes.FormatSqlFileRecipe` recipe automatically formats the content of SQL files. ## Configurable Options @@ -174,9 +174,9 @@ Inside the plugins section, add: - io.github.mhagnumdw.FormatSqlTextBlockByAnnotation - io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection - io.github.mhagnumdw.FormatSqlFileRecipe + io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation + io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection + io.github.mhagnumdw.recipes.FormatSqlFileRecipe false @@ -201,14 +201,14 @@ To customize the recipe configuration, you need to have a `rewrite.yml` file in ```yml --- type: specs.openrewrite.org/v1beta/recipe -name: io.github.mhagnumdw.FormatSqlCustomConfig +name: io.github.mhagnumdw.recipes.FormatSqlCustomConfig recipeList: # Add the Recipes you want to use here - - io.github.mhagnumdw.FormatSqlTextBlockByAnnotation: + - io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation: sqlDialect: "plsql" - - io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection: + - io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection: sqlDialect: "plsql" - - io.github.mhagnumdw.FormatSqlFileRecipe: + - io.github.mhagnumdw.recipes.FormatSqlFileRecipe: sqlDialect: "plsql" ``` @@ -220,7 +220,7 @@ recipeList: And change the `` tag in `pom.xml` to: ```xml -io.github.mhagnumdw.FormatSqlCustomConfig +io.github.mhagnumdw.recipes.FormatSqlCustomConfig ``` > As in this example the `FormatSqlCustomConfig` recipe includes both `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection` and `FormatSqlFileRecipe` recipes, in `pom.xml` it is only necessary to define the `FormatSqlCustomConfig` recipe. @@ -239,7 +239,7 @@ This mode is indicated if your intention is to run the recipe only once. ```bash ./mvnw org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.activeRecipes=io.github.mhagnumdw.FormatSqlTextBlockByAnnotation,io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection,io.github.mhagnumdw.FormatSqlFileRecipe \ + -Drewrite.activeRecipes=io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation,io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection,io.github.mhagnumdw.recipes.FormatSqlFileRecipe \ -Drewrite.recipeArtifactCoordinates=io.github.mhagnumdw:rewrite-format-sql:1.0.0 ``` @@ -249,11 +249,11 @@ Then run: ```bash ./mvnw org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.activeRecipes=io.github.mhagnumdw.FormatSqlCustomConfig \ + -Drewrite.activeRecipes=io.github.mhagnumdw.recipes.FormatSqlCustomConfig \ -Drewrite.recipeArtifactCoordinates=io.github.mhagnumdw:rewrite-format-sql:1.0.0 ``` -> - `io.github.mhagnumdw.FormatSqlCustomConfig` is the `name` defined in the `rewrite.yml` file. +> - `io.github.mhagnumdw.recipes.FormatSqlCustomConfig` is the `name` defined in the `rewrite.yml` file. > - For a single recipe, you don't even need to have the `rewrite.yml` file to customize the configuration, see [here](https://docs.openrewrite.org/reference/faq#is-it-possible-to-pass-arguments-to-a-recipe-from-the-command-line). ## For Developers diff --git a/src/main/java/io/github/mhagnumdw/processors/AnnotationOnlyOneArgumentProcessor.java b/src/main/java/io/github/mhagnumdw/processors/AnnotationOnlyOneArgumentProcessor.java index c4cef40..22da7c7 100644 --- a/src/main/java/io/github/mhagnumdw/processors/AnnotationOnlyOneArgumentProcessor.java +++ b/src/main/java/io/github/mhagnumdw/processors/AnnotationOnlyOneArgumentProcessor.java @@ -4,7 +4,7 @@ import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; -import io.github.mhagnumdw.TextBlockUtil; +import io.github.mhagnumdw.utils.TextBlockUtil; import org.openrewrite.Cursor; import org.openrewrite.java.tree.Expression; import org.openrewrite.java.tree.J; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlFileRecipe.java b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java similarity index 94% rename from src/main/java/io/github/mhagnumdw/FormatSqlFileRecipe.java rename to src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java index 82f9fea..9b5b9c9 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlFileRecipe.java +++ b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java @@ -1,9 +1,10 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; +import io.github.mhagnumdw.visitors.FormatSqlFileVisitor; import lombok.EqualsAndHashCode; import lombok.Value; import org.jspecify.annotations.Nullable; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlRecipeAbstract.java b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlRecipeAbstract.java similarity index 99% rename from src/main/java/io/github/mhagnumdw/FormatSqlRecipeAbstract.java rename to src/main/java/io/github/mhagnumdw/recipes/FormatSqlRecipeAbstract.java index 45878c8..66bdeab 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlRecipeAbstract.java +++ b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlRecipeAbstract.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.vertical_blank.sqlformatter.core.FormatConfig; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotation.java similarity index 95% rename from src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java rename to src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotation.java index b6be299..ba71578 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotation.java +++ b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotation.java @@ -1,9 +1,10 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; +import io.github.mhagnumdw.visitors.FormatSqlBlockVisitor; import lombok.EqualsAndHashCode; import lombok.Value; import org.jspecify.annotations.Nullable; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjection.java similarity index 95% rename from src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java rename to src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjection.java index d02956c..26ad18a 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjection.java +++ b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjection.java @@ -1,9 +1,10 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; +import io.github.mhagnumdw.visitors.FormatSqlTextBlockVisitor; import lombok.EqualsAndHashCode; import lombok.Value; import org.jspecify.annotations.Nullable; diff --git a/src/main/java/io/github/mhagnumdw/TextBlockUtil.java b/src/main/java/io/github/mhagnumdw/utils/TextBlockUtil.java similarity index 99% rename from src/main/java/io/github/mhagnumdw/TextBlockUtil.java rename to src/main/java/io/github/mhagnumdw/utils/TextBlockUtil.java index 5e7ed78..36035f4 100644 --- a/src/main/java/io/github/mhagnumdw/TextBlockUtil.java +++ b/src/main/java/io/github/mhagnumdw/utils/TextBlockUtil.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.utils; import static org.openrewrite.Tree.randomId; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlBlockVisitor.java b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlBlockVisitor.java similarity index 89% rename from src/main/java/io/github/mhagnumdw/FormatSqlBlockVisitor.java rename to src/main/java/io/github/mhagnumdw/visitors/FormatSqlBlockVisitor.java index 05e3913..56786ff 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlBlockVisitor.java +++ b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlBlockVisitor.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.visitors; import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; @@ -13,7 +13,7 @@ public class FormatSqlBlockVisitor extends JavaIsoVisitor { private final Dialect dialect; private final FormatConfig formatConfig; - FormatSqlBlockVisitor(Dialect dialect, FormatConfig formatConfig) { + public FormatSqlBlockVisitor(Dialect dialect, FormatConfig formatConfig) { this.dialect = dialect; this.formatConfig = formatConfig; } diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlFileVisitor.java b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlFileVisitor.java similarity index 97% rename from src/main/java/io/github/mhagnumdw/FormatSqlFileVisitor.java rename to src/main/java/io/github/mhagnumdw/visitors/FormatSqlFileVisitor.java index 716ddcc..ff1dec5 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlFileVisitor.java +++ b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlFileVisitor.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.visitors; import com.github.vertical_blank.sqlformatter.SqlFormatter; import com.github.vertical_blank.sqlformatter.core.FormatConfig; diff --git a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockVisitor.java b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlTextBlockVisitor.java similarity index 94% rename from src/main/java/io/github/mhagnumdw/FormatSqlTextBlockVisitor.java rename to src/main/java/io/github/mhagnumdw/visitors/FormatSqlTextBlockVisitor.java index 11008bb..a7d8c07 100644 --- a/src/main/java/io/github/mhagnumdw/FormatSqlTextBlockVisitor.java +++ b/src/main/java/io/github/mhagnumdw/visitors/FormatSqlTextBlockVisitor.java @@ -1,9 +1,10 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.visitors; import static org.openrewrite.java.tree.J.Literal; import com.github.vertical_blank.sqlformatter.core.FormatConfig; import com.github.vertical_blank.sqlformatter.languages.Dialect; +import io.github.mhagnumdw.utils.TextBlockUtil; import org.openrewrite.ExecutionContext; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.tree.Comment; @@ -24,7 +25,7 @@ public class FormatSqlTextBlockVisitor extends JavaIsoVisitor private final Dialect dialect; private final FormatConfig formatConfig; - FormatSqlTextBlockVisitor(Dialect dialect, FormatConfig formatConfig) { + public FormatSqlTextBlockVisitor(Dialect dialect, FormatConfig formatConfig) { this.dialect = dialect; this.formatConfig = formatConfig; } diff --git a/src/main/resources/META-INF/rewrite/examples.yml b/src/main/resources/META-INF/rewrite/examples.yml index aada8a9..eb5cf4a 100644 --- a/src/main/resources/META-INF/rewrite/examples.yml +++ b/src/main/resources/META-INF/rewrite/examples.yml @@ -1,6 +1,6 @@ --- type: specs.openrewrite.org/v1beta/example -recipeName: io.github.mhagnumdw.FormatSqlTextBlockByAnnotation +recipeName: io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation examples: - description: '`FormatSqlTextBlockByAnnotationTest#shouldFormatSimpleSqlBlock`' parameters: @@ -45,7 +45,7 @@ examples: language: java --- type: specs.openrewrite.org/v1beta/example -recipeName: io.github.mhagnumdw.FormatSqlTextBlockByLanguageInjection +recipeName: io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection examples: - description: '`FormatSqlTextBlockByLanguageInjectionTest#shouldFormatFieldWithLanguageSqlComment`' parameters: diff --git a/src/test/java/io/github/mhagnumdw/FormatSqlFileRecipeTest.java b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java similarity index 98% rename from src/test/java/io/github/mhagnumdw/FormatSqlFileRecipeTest.java rename to src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java index 6e004dc..31a73c3 100644 --- a/src/test/java/io/github/mhagnumdw/FormatSqlFileRecipeTest.java +++ b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import static org.openrewrite.test.SourceSpecs.other; import static org.openrewrite.test.SourceSpecs.text; diff --git a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotationTest.java similarity index 99% rename from src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java rename to src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotationTest.java index c3bd550..ffcc017 100644 --- a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByAnnotationTest.java +++ b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByAnnotationTest.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import static java.util.Collections.emptySet; import static java.util.Collections.singletonList; diff --git a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjectionTest.java similarity index 99% rename from src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java rename to src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjectionTest.java index 160e925..4efe2f4 100644 --- a/src/test/java/io/github/mhagnumdw/FormatSqlTextBlockByLanguageInjectionTest.java +++ b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlTextBlockByLanguageInjectionTest.java @@ -1,4 +1,4 @@ -package io.github.mhagnumdw; +package io.github.mhagnumdw.recipes; import static org.openrewrite.java.Assertions.java; import static org.openrewrite.java.Assertions.javaVersion; From 86b69853c01750ea5d7bd2a21f609d5fe86745bc Mon Sep 17 00:00:00 2001 From: Dwouglas Mhagnum Date: Sun, 26 Apr 2026 15:32:43 -0300 Subject: [PATCH 3/3] Rename FormatSqlFileRecipe > FormatSqlFile --- CHANGELOG.md | 3 +-- README.md | 22 +++++++++---------- ...tSqlFileRecipe.java => FormatSqlFile.java} | 4 ++-- ...RecipeTest.java => FormatSqlFileTest.java} | 6 ++--- 4 files changed, 17 insertions(+), 18 deletions(-) rename src/main/java/io/github/mhagnumdw/recipes/{FormatSqlFileRecipe.java => FormatSqlFile.java} (91%) rename src/test/java/io/github/mhagnumdw/recipes/{FormatSqlFileRecipeTest.java => FormatSqlFileTest.java} (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0848b70..773eacb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes - Rename recipe `io.github.mhagnumdw.FormatSqlBlockRecipe` to `io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation` -- Rename recipe `io.github.mhagnumdw.FormatSqlTextBlockRecipe` to `io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection` -- Rename recipe `io.github.mhagnumdw.FormatSqlFileRecipe` to `io.github.mhagnumdw.recipes.FormatSqlFileRecipe` +- Rename recipe `io.github.mhagnumdw.FormatSqlFileRecipe` to `io.github.mhagnumdw.recipes.FormatSqlFile` ### Added diff --git a/README.md b/README.md index 223696e..b29fdc9 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,12 @@ A set of [OpenRewrite](https://docs.openrewrite.org/) recipes for formatting SQL - [Recipes](#recipes) - [FormatSqlTextBlockByAnnotation](#formatsqltextblockbyannotation) - [FormatSqlTextBlockByLanguageInjection](#formatsqltextblockbylanguageinjection) - - [FormatSqlFileRecipe](#formatsqlfilerecipe) + - [FormatSqlFile](#formatsqlfile) - [Configurable Options](#configurable-options) - [Examples](#examples) - [FormatSqlTextBlockByAnnotation example](#formatsqltextblockbyannotation-example) - [FormatSqlTextBlockByLanguageInjection example](#formatsqltextblockbylanguageinjection-example) - - [FormatSqlFileRecipe example](#formatsqlfilerecipe-example) + - [FormatSqlFile example](#formatsqlfile-example) - [Usage](#usage) - [Configuring in `pom.xml`](#configuring-in-pomxml) - [Without adding anything to the project](#without-adding-anything-to-the-project) @@ -41,17 +41,17 @@ The `io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection` recipe f This is the same [language injection comment](https://www.jetbrains.com/help/idea/language-injections.html) recognized by IntelliJ IDEA for SQL syntax highlighting. -### FormatSqlFileRecipe +### FormatSqlFile -The `io.github.mhagnumdw.recipes.FormatSqlFileRecipe` recipe automatically formats the content of SQL files. +The `io.github.mhagnumdw.recipes.FormatSqlFile` recipe automatically formats the content of SQL files. ## Configurable Options -The following options are applicable to `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection`, and `FormatSqlFileRecipe`: +The following options are applicable to `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection`, and `FormatSqlFile`: | Type | Name | Description | Example | Default Value | | :------ | :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :------------------------- | -| String | `filePath` | Optional. The path to the files that the Recipe should process. Accepts a glob expression; multiple patterns can be specified, separated by a semicolon `;`. If omitted, processes all matching files. | `**/*DAO.java`
`**/*.sql` | FormatSqlTextBlockByAnnotation: `**/*.java`
FormatSqlTextBlockByLanguageInjection: `**/*.java`
FormatSqlFileRecipe: `**/*.sql` | +| String | `filePath` | Optional. The path to the files that the Recipe should process. Accepts a glob expression; multiple patterns can be specified, separated by a semicolon `;`. If omitted, processes all matching files. | `**/*DAO.java`
`**/*.sql` | FormatSqlTextBlockByAnnotation: `**/*.java`
FormatSqlTextBlockByLanguageInjection: `**/*.java`
FormatSqlFile: `**/*.sql` | | String | `sqlDialect` | Optional. The SQL dialect to be used for formatting. Valid options: `sql` (StandardSql), `mysql`, `postgresql`, `db2`, `plsql` (Oracle PL/SQL), `n1ql` (Couchbase N1QL), `redshift`, `spark`, `tsql` (SQL Server Transact-SQL). Details [here](https://github.com/vertical-blank/sql-formatter). | `plsql` | `sql` | | String | `indent` | Optional. The string to be used for indentation. | `" "` for 2 spaces
`"\t"` for a tab | 4 spaces `" "` | | Integer | `maxColumnLength` | Optional. The maximum length of a line before the formatter tries to break it. | `100` | `120` | @@ -126,7 +126,7 @@ private static final String QUERY = """ u.name"""; ``` -### FormatSqlFileRecipe example +### FormatSqlFile example Consider the following `example.sql` file: @@ -176,7 +176,7 @@ Inside the plugins section, add: io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection - io.github.mhagnumdw.recipes.FormatSqlFileRecipe + io.github.mhagnumdw.recipes.FormatSqlFile false
@@ -208,7 +208,7 @@ recipeList: sqlDialect: "plsql" - io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection: sqlDialect: "plsql" - - io.github.mhagnumdw.recipes.FormatSqlFileRecipe: + - io.github.mhagnumdw.recipes.FormatSqlFile: sqlDialect: "plsql" ``` @@ -223,7 +223,7 @@ And change the `` tag in `pom.xml` to: io.github.mhagnumdw.recipes.FormatSqlCustomConfig ``` -> As in this example the `FormatSqlCustomConfig` recipe includes both `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection` and `FormatSqlFileRecipe` recipes, in `pom.xml` it is only necessary to define the `FormatSqlCustomConfig` recipe. +> As in this example the `FormatSqlCustomConfig` recipe includes both `FormatSqlTextBlockByAnnotation`, `FormatSqlTextBlockByLanguageInjection` and `FormatSqlFile` recipes, in `pom.xml` it is only necessary to define the `FormatSqlCustomConfig` recipe. Then run: @@ -239,7 +239,7 @@ This mode is indicated if your intention is to run the recipe only once. ```bash ./mvnw org.openrewrite.maven:rewrite-maven-plugin:run \ - -Drewrite.activeRecipes=io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation,io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection,io.github.mhagnumdw.recipes.FormatSqlFileRecipe \ + -Drewrite.activeRecipes=io.github.mhagnumdw.recipes.FormatSqlTextBlockByAnnotation,io.github.mhagnumdw.recipes.FormatSqlTextBlockByLanguageInjection,io.github.mhagnumdw.recipes.FormatSqlFile \ -Drewrite.recipeArtifactCoordinates=io.github.mhagnumdw:rewrite-format-sql:1.0.0 ``` diff --git a/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFile.java similarity index 91% rename from src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java rename to src/main/java/io/github/mhagnumdw/recipes/FormatSqlFile.java index 9b5b9c9..993bfd3 100644 --- a/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipe.java +++ b/src/main/java/io/github/mhagnumdw/recipes/FormatSqlFile.java @@ -18,12 +18,12 @@ */ @Value @EqualsAndHashCode(callSuper = false) -public class FormatSqlFileRecipe extends FormatSqlRecipeAbstract { +public class FormatSqlFile extends FormatSqlRecipeAbstract { private static final String DEFAULT_FILE_PATH = "**/*.sql"; @JsonCreator - public FormatSqlFileRecipe(@Nullable @JsonProperty("filePath") String filePath, + public FormatSqlFile(@Nullable @JsonProperty("filePath") String filePath, @Nullable @JsonProperty("sqlDialect") String sqlDialect, @Nullable @JsonProperty("indent") String indent, @Nullable @JsonProperty("maxColumnLength") Integer maxColumnLength, diff --git a/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileTest.java similarity index 94% rename from src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java rename to src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileTest.java index 31a73c3..dd26a69 100644 --- a/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileRecipeTest.java +++ b/src/test/java/io/github/mhagnumdw/recipes/FormatSqlFileTest.java @@ -9,12 +9,12 @@ import org.openrewrite.test.RewriteTest; @SuppressWarnings("java:S2699") -class FormatSqlFileRecipeTest implements RewriteTest { +class FormatSqlFileTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec.recipe( - new FormatSqlFileRecipe( + new FormatSqlFile( "file.sql", "plsql", null, @@ -85,7 +85,7 @@ void shouldNotChangeEmptyFile() { @Test void shouldFormatWithCustomOptions() { rewriteRun( - spec -> spec.recipe(new FormatSqlFileRecipe(null, "plsql", "\t", null, false)), + spec -> spec.recipe(new FormatSqlFile(null, "plsql", "\t", null, false)), text( """ select e.emp_id, e.name, d.dept_name from employees e join departments d on e.dept_id = d.dept_id where e.salary > 50000;