Code cleanup
Recipe ID
org.openrewrite.staticanalysis.CodeCleanupArtifact
org.openrewrite.recipe:rewrite-static-analysisAutomatically cleanup code, e.g. remove unnecessary parentheses, simplify expressions.
Usage
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:2.40.0Definition
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