Code cleanup
Recipe ID
org.openrewrite.staticanalysis.CodeCleanupArtifactorg.openrewrite.recipe:rewrite-static-analysisAutomatically cleanup code, e.g. remove unnecessary parentheses, simplify expressions.
Composite recipeMSAL
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.staticanalysis.CodeCleanup")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.44.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.staticanalysis.CodeCleanupIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-static-analysis:RELEASEDefinition
This recipe runs the following recipes in order.
- Default comes last
org.openrewrite.staticanalysis.DefaultComesLast - Remove empty blocks
org.openrewrite.staticanalysis.EmptyBlock - End files with a single newline
org.openrewrite.java.format.EmptyNewlineAtEndOfFile forloop counters should use postfix operatorsorg.openrewrite.staticanalysis.ForLoopControlVariablePostfixOperators- Finalize private fields
org.openrewrite.staticanalysis.FinalizePrivateFields - Method parameter padding
org.openrewrite.java.format.MethodParamPad - No whitespace after
org.openrewrite.java.format.NoWhitespaceAfter - No whitespace before
org.openrewrite.java.format.NoWhitespaceBefore - Pad empty
forloop componentsorg.openrewrite.java.format.PadEmptyForLoopComponents - Typecast parenthesis padding
org.openrewrite.staticanalysis.TypecastParenPad - Equals avoids null
org.openrewrite.staticanalysis.EqualsAvoidsNull - Explicit initialization
org.openrewrite.staticanalysis.ExplicitInitialization - Fall through
org.openrewrite.staticanalysis.FallThrough - Hide utility class constructor
org.openrewrite.staticanalysis.HideUtilityClassConstructor - Fix missing braces
org.openrewrite.staticanalysis.NeedBraces - Operator wrapping
org.openrewrite.staticanalysis.OperatorWrap - Remove unnecessary parentheses
org.openrewrite.staticanalysis.UnnecessaryParentheses - Replace calls to
Thread.run()withThread.start()org.openrewrite.staticanalysis.ReplaceThreadRunWithThreadStart - Chain
StringBuilder.append()callsorg.openrewrite.staticanalysis.ChainStringBuilderAppendCalls - Remove methods that only call super
org.openrewrite.staticanalysis.RemoveMethodsOnlyCallSuper - Replace
StringBuilder#appendwithStringorg.openrewrite.staticanalysis.ReplaceStringBuilderWithString - Add imports for fully qualified references to types
org.openrewrite.java.ShortenFullyQualifiedTypeReferences - Simplify single-element annotation
org.openrewrite.java.SimplifySingleElementAnnotation - Order imports
org.openrewrite.java.OrderImports - Remove unused labels
org.openrewrite.staticanalysis.RemoveUnusedLabels
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats