← All recipes
Moderne licensed

Find similar code

Recipe IDio.moderne.prethink.quality.FindSimilarCode
Artifactio.moderne.recipe:rewrite-prethink

Detect 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

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.FindSimilarCode

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

mod config recipes jar install io.moderne.recipe:rewrite-prethink:0.11.1

Options

NameTypeDescription
similarityThresholdIntegerMinimum Jaccard similarity (as a percentage) for two methods to be considered similar. Defaults to 70.
e.g. 70
maxSimilarityIntegerMaximum 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
minMethodMassIntegerMinimum 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
minFeaturesIntegerMinimum number of distinct AST shingles a method must have to be considered. Defaults to 8.
e.g. 8
minShingleMassIntegerMinimum number of AST nodes a subtree must contain to be used as a shingle (feature). Defaults to 3.
e.g. 3
includeTestSourcesBooleanWhether to include test sources (paths under src/test). Defaults to false.
e.g. false
suppressBoilerplateBooleanWhether to skip getters/setters, equals/hashCode/toString, and all-trivial methods. Defaults to true.
e.g. true
snippetMaxLinesIntegerMaximum number of lines of the representative method to include in the snippet. Defaults to 40.
e.g. 40
maxMembersPerGroupIntegerCap 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