Links

Properly use declaration-site type variance for well-known types

org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances When using a method parameter like Function<IN, OUT>, it should rather be Function<? super IN, ? extends OUT>. This recipe checks for method parameters of well-known types.

Tags

  • RSPEC-1217

Source

  • groupId: org.openrewrite
  • artifactId: rewrite-java
  • version: 7.35.0

Usage

This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies.
Gradle
Maven POM
Maven Command Line
build.gradle
plugins {
id("org.openrewrite.rewrite") version("5.34.0")
}
rewrite {
activeRecipe("org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances")
}
repositories {
mavenCentral()
}
pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.39.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
shell
mvn org.openrewrite.maven:rewrite-maven-plugin:4.39.0:run \
-DactiveRecipes=org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances
Recipes can also be activated directly from the command line by adding the argument -Drewrite.activeRecipes=org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances

Definition

Recipe List
Yaml Recipe List
    • variantTypes: [java.util.function.Consumer<IN>, java.util.function.BiPredicate<IN, IN>, java.util.function.DoubleFunction<OUT>, java.util.function.Function<IN, OUT>, java.util.function.IntFunction<OUT>, java.util.function.LongFunction<OUT>, java.util.function.ObjDoubleConsumer<IN>, java.util.function.ObjIntConsumer<IN>, java.util.function.ObjLongConsumer<IN>, java.util.function.Predicate<IN>, java.util.function.Supplier<OUT>, java.util.function.ToDoubleBiFunction<IN, IN>, java.util.function.ToDoubleFunction<IN>, java.util.function.ToIntBiFunction<IN, IN>, java.util.function.ToIntFunction<IN>, java.util.function.ToLongBiFunction<IN, IN>, java.util.function.ToLongFunction<IN>]
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.cleanup.CommonDeclarationSiteTypeVariances
displayName: Properly use declaration-site type variance for well-known types
description: When using a method parameter like `Function<IN, OUT>`, it should rather be `Function<? super IN, ? extends OUT>`. This recipe checks for method parameters of well-known types.
tags:
- RSPEC-1217
recipeList:
- org.openrewrite.java.cleanup.DeclarationSiteTypeVariance:
variantTypes: [java.util.function.Consumer<IN>, java.util.function.BiPredicate<IN, IN>, java.util.function.DoubleFunction<OUT>, java.util.function.Function<IN, OUT>, java.util.function.IntFunction<OUT>, java.util.function.LongFunction<OUT>, java.util.function.ObjDoubleConsumer<IN>, java.util.function.ObjIntConsumer<IN>, java.util.function.ObjLongConsumer<IN>, java.util.function.Predicate<IN>, java.util.function.Supplier<OUT>, java.util.function.ToDoubleBiFunction<IN, IN>, java.util.function.ToDoubleFunction<IN>, java.util.function.ToIntBiFunction<IN, IN>, java.util.function.ToIntFunction<IN>, java.util.function.ToLongBiFunction<IN, IN>, java.util.function.ToLongFunction<IN>]

See how this recipe works across multiple open-source repositories

Moderne Link Image
The Moderne public SaaS instance enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.