Skip to main content

Find code smells

io.moderne.prethink.quality.FindCodeSmells

Detect code smells including God Class, Feature Envy, and Data Class using composite metric thresholds with severity ratings.

Recipe source

This recipe is only available to users of Moderne.

This recipe is available under the Moderne Proprietary License.

Used by

This recipe is used as part of the following composite recipes:

Example

Unchanged
package com.example;

/**
* Intentionally bloated class to trigger God Class detection.
* WMC >= 47 (each method has if/else = CC 2, 24 methods = WMC 48).
* TCC < 0.33 (each method accesses a different field).
* ATFD > 5 (methods directly access public fields of Other).
*/
public class BigService {
private int f1;
private int f2;
private int f3;
private int f4;
private int f5;
private int f6;
private int f7;
private int f8;
private int f9;
private int f10;
private int f11;
private int f12;
private int f13;
private int f14;
private int f15;
private int f16;
private int f17;
private int f18;
private int f19;
private int f20;
private int f21;
private int f22;
private int f23;
private int f24;

public int method1(Other ext) {
if (ext.x > 0) { return ext.y; }
return f1;
}
public int method2(Other ext) {
if (ext.y > 0) { return ext.z; }
return f2;
}
public int method3(Other ext) {
if (ext.z > 0) { return ext.w; }
return f3;
}
public int method4(Other ext) {
if (ext.w > 0) { return ext.v; }
return f4;
}
public int method5(Other ext) {
if (ext.v > 0) { return ext.u; }
return f5;
}
public int method6(Other ext) {
if (ext.u > 0) { return ext.t; }
return f6;
}
public int method7(Other ext) {
if (ext.x > 0) { return ext.y; }
return f7;
}
public int method8(Other ext) {
if (ext.y > 0) { return ext.z; }
return f8;
}
public int method9(Other ext) {
if (ext.z > 0) { return ext.w; }
return f9;
}
public int method10(Other ext) {
if (ext.w > 0) { return ext.v; }
return f10;
}
public int method11(Other ext) {
if (ext.v > 0) { return ext.u; }
return f11;
}
public int method12(Other ext) {
if (ext.u > 0) { return ext.t; }
return f12;
}
public int method13(Other ext) {
if (ext.x > 0) { return ext.y; }
return f13;
}
public int method14(Other ext) {
if (ext.y > 0) { return ext.z; }
return f14;
}
public int method15(Other ext) {
if (ext.z > 0) { return ext.w; }
return f15;
}
public int method16(Other ext) {
if (ext.w > 0) { return ext.v; }
return f16;
}
public int method17(Other ext) {
if (ext.v > 0) { return ext.u; }
return f17;
}
public int method18(Other ext) {
if (ext.u > 0) { return ext.t; }
return f18;
}
public int method19(Other ext) {
if (ext.x > 0) { return ext.y; }
return f19;
}
public int method20(Other ext) {
if (ext.y > 0) { return ext.z; }
return f20;
}
public int method21(Other ext) {
if (ext.z > 0) { return ext.w; }
return f21;
}
public int method22(Other ext) {
if (ext.w > 0) { return ext.v; }
return f22;
}
public int method23(Other ext) {
if (ext.v > 0) { return ext.u; }
return f23;
}
public int method24(Other ext) {
if (ext.u > 0) { return ext.t; }
return f24;
}
}
Unchanged
package com.example;

public class Other {
public int x;
public int y;
public int z;
public int w;
public int v;
public int u;
public int t;

public int compute(int a, int b) { return a + b; }
}
Unchanged
test-project

Usage

This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe FindCodeSmells

If the recipe is not available locally, then you can install it using:

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

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform 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.

Data Tables

Code smells

io.moderne.prethink.table.CodeSmells

Detected code smells including God Class, Feature Envy, and Data Class with severity ratings and the metric evidence that triggered detection.

Column NameDescription
Source pathThe path to the source file containing the smell.
Class nameThe fully qualified name of the class.
Method nameThe method name, if the smell is method-level (e.g., Feature Envy). Null for class-level smells.
Smell typeThe type of code smell: GOD_CLASS, FEATURE_ENVY, or DATA_CLASS.
SeveritySeverity based on how far metrics exceed thresholds: LOW, MEDIUM, HIGH, or CRITICAL.
EvidenceThe metric values that triggered detection, e.g., 'WMC=52, TCC=0.21, ATFD=8'.