← All recipes
Moderne licensed

Properly use declaration-site type variance

Recipe IDorg.openrewrite.staticanalysis.DeclarationSiteTypeVariance
Artifactorg.openrewrite.recipe:rewrite-static-analysis

Currently, Java requires use-site type variance, so if someone has Function<IN, OUT> method parameter, it should rather be Function<? super IN, ? extends OUT>. Unfortunately, it is not easy to notice that ? super and ? extends is missing, so this recipe adds it where that would improve the situation.

Single recipeMSAL

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.staticanalysis.DeclarationSiteTypeVariance --recipe-option "variantTypes=java.util.function.Function<IN, OUT>"

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-static-analysis:2.40.0

Options

NameTypeDescription
variantTypesrequiredListA list of well-known classes that have in/out type variance.
e.g. java.util.function.Function<IN, OUT>
excludedBoundsListA list of bounds that should not receive explicit variance. Globs supported.
e.g. java.lang.*
excludeFinalClassesBooleanIf true, do not add ? extends variance to final classes. ? super variance will be added regardless of finality.

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