Find similar code
Recipe ID
io.moderne.prethink.quality.FindSimilarCodeArtifact
io.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.
Usage
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:0.11.1Options
| 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