Find similar code
Recipe ID
io.moderne.prethink.quality.FindSimilarCodeArtifactio.moderne.recipe:rewrite-prethinkDetect structurally similar (but not identical) methods with MinHash/LSH near-duplicate matching over their AST shingles (zero AI), reporting an approximate similarity percentage. Complements exact duplicate detection by surfacing restructured near-duplicates worth consolidating.
Single recipeProprietary
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("io.moderne.prethink.quality.FindSimilarCode")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("io.moderne.recipe:rewrite-prethink:0.14.1")
}
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 io.moderne.prethink.quality.FindSimilarCodeIf the recipe isn’t available locally, install it with:
mod config recipes jar install io.moderne.recipe:rewrite-prethink:RELEASEOptions
| Name | Type | Description |
|---|---|---|
similarityThreshold | Integer | Minimum Jaccard similarity (as a percentage) for two methods to be considered similar. Defaults to 70. e.g. 70 |
maxSimilarity | Integer | Maximum similarity (percentage) to report. Pairs more similar than this are exact or near-exact duplicates that exact clone detection already covers, so they are excluded here. Defaults to 99; set to 100 to include perfect matches. e.g. 99 |
minMethodMass | Integer | Minimum number of AST nodes a method must contain to be considered. Smaller methods have too few features for a meaningful similarity signal. Defaults to 40. e.g. 40 |
minFeatures | Integer | Minimum number of distinct AST shingles a method must have to be considered. Defaults to 8. e.g. 8 |
minShingleMass | Integer | Minimum number of AST nodes a subtree must contain to be used as a shingle (feature). Defaults to 3. e.g. 3 |
includeTestSources | Boolean | Whether to include test sources (paths under src/test). Defaults to false. e.g. false |
suppressBoilerplate | Boolean | Whether to skip getters/setters, equals/hashCode/toString, and all-trivial methods. Defaults to true. e.g. true |
snippetMaxLines | Integer | Maximum number of lines of the representative method to include in the snippet. Defaults to 40. e.g. 40 |
maxMembersPerGroup | Integer | Cap on the number of member methods listed per group. Defaults to 200. e.g. 200 |
Data tables
Structured output this recipe can produce.
- Similar codeGroups of structurally similar methods detected by MinHash/LSH near-duplicate matching, with an approximate similarity percentage. Complements exact duplicate detection by finding restructured near-duplicates.
io.moderne.prethink.table.SimilarCode - 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