Skip to content

Commit

Permalink
MEL metric for quality analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Jan 23, 2025
1 parent a48d370 commit b2504ed
Show file tree
Hide file tree
Showing 29 changed files with 113 additions and 22 deletions.
Binary file modified AssertStatement.class
Binary file not shown.
Binary file modified AssignStatement.class
Binary file not shown.
Binary file modified BehaviouralFeature.class
Binary file not shown.
5 changes: 3 additions & 2 deletions BehaviouralFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down Expand Up @@ -4421,6 +4421,7 @@ else if (useCase != null)

int acomp = activity.syntacticComplexity();
out.println("*** Activity syntactic complexity = " + acomp);

if (acomp > TestParameters.operationSizeLimit)
{ System.err.println("!!! Code smell (EOS): too high activity complexity (" + acomp + ") for " + nme);
System.err.println(">>> Recommend refactoring by splitting operation");
Expand Down Expand Up @@ -4474,7 +4475,7 @@ public java.util.Map dataDependencies()
Vector postvars = new Vector();
postvars.add("result");
Vector deps = activity.dataDependents(
allvars,postvars);
allvars,postvars);
System.out.println();
System.out.println(">***> result is derived from:\n " + deps);

Expand Down
Binary file modified BinaryExpression.class
Binary file not shown.
9 changes: 8 additions & 1 deletion BinaryExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javax.swing.JOptionPane;

/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down Expand Up @@ -20658,6 +20658,13 @@ public Map energyUse(Map res, Vector rUses, Vector aUses)
// are amber flags.
// ->select(...)->any() is a red flag.

int syn = syntacticComplexity();
if (syn > TestParameters.syntacticComplexityLimit)
{ aUses.add("! Excessive expression size (MEL) in " + this + " : try to simplify OCL expression");
int ascore = (int) res.get("amber");
res.set("amber", ascore+1);
}

left.energyUse(res, rUses, aUses);
right.energyUse(res, rUses, aUses);

Expand Down
Binary file modified BreakStatement.class
Binary file not shown.
Binary file modified CaseStatement.class
Binary file not shown.
Binary file modified CatchStatement.class
Binary file not shown.
Binary file modified ConditionalExpression.class
Binary file not shown.
11 changes: 9 additions & 2 deletions ConditionalExpression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down Expand Up @@ -183,7 +183,14 @@ public Expression simplifyOCL()
}

public Map energyUse(Map res, Vector rUses, Vector oUses)
{ test.energyUse(res,rUses,oUses);
{ int syn = syntacticComplexity();
if (syn > TestParameters.syntacticComplexityLimit)
{ oUses.add("! Excessive expression size (MEL) in " + this + " : try to simplify OCL expression");
int ascore = (int) res.get("amber");
res.set("amber", ascore+1);
}

test.energyUse(res,rUses,oUses);
ifExp.energyUse(res,rUses,oUses);
elseExp.energyUse(res,rUses,oUses);

Expand Down
Binary file modified ConditionalStatement.class
Binary file not shown.
Binary file modified ContinueStatement.class
Binary file not shown.
Binary file modified CreationStatement.class
Binary file not shown.
2 changes: 1 addition & 1 deletion Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down
Binary file modified ErrorStatement.class
Binary file not shown.
Binary file modified FinalStatement.class
Binary file not shown.
Binary file modified IfCase.class
Binary file not shown.
Binary file modified IfStatement.class
Binary file not shown.
Binary file modified ImplicitInvocationStatement.class
Binary file not shown.
Binary file modified InvocationStatement.class
Binary file not shown.
Binary file modified ReturnStatement.class
Binary file not shown.
Binary file modified SequenceStatement.class
Binary file not shown.
101 changes: 88 additions & 13 deletions Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javax.swing.JOptionPane;

/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down Expand Up @@ -2267,7 +2267,7 @@ else if (op != null)
}

public Map energyUse(Map uses,
Vector rUses, Vector oUses)
Vector rUses, Vector oUses)
{ if (value == null)
{ return uses; }
value.energyUse(uses, rUses, oUses);
Expand Down Expand Up @@ -2569,7 +2569,15 @@ public Statement replaceModuleReferences(UseCase uc)
public int syntacticComplexity()
{ if (value == null)
{ return 1; }
return value.syntacticComplexity() + 1;

int syncomp = value.syntacticComplexity();

if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + value);
System.err.println(">>> Recommend OCL refactoring");
}

return syncomp + 1;
}

public int cyclomaticComplexity()
Expand Down Expand Up @@ -3921,7 +3929,14 @@ public Statement replaceModuleReferences(UseCase uc)
public int syntacticComplexity()
{ if (callExp == null)
{ return 1; }
return callExp.syntacticComplexity() + 1;

int syncomp = callExp.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + callExp);
System.err.println(">>> Recommend OCL refactoring");
}

return syncomp + 1;
}

public int cyclomaticComplexity()
Expand Down Expand Up @@ -4374,7 +4389,14 @@ public Statement replaceModuleReferences(UseCase uc)
public int syntacticComplexity()
{ if (callExp == null)
{ return 1; }
return callExp.syntacticComplexity() + 1;

int syncomp = callExp.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + callExp);
System.err.println(">>> Recommend OCL refactoring");
}

return syncomp + 1;
}

public int cyclomaticComplexity()
Expand Down Expand Up @@ -6282,14 +6304,27 @@ public int syntacticComplexity()

if (loopKind == FOR)
{ if (loopRange != null)
{ int rcomp = loopRange.syntacticComplexity();
{ int rcomp = loopRange.syntacticComplexity();

if (rcomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + rcomp + ") for " + loopRange);
System.err.println(">>> Recommend OCL refactoring");
}

return res + rcomp + 1;
}
}

if (loopTest == null)
{ return res + 1; }
return loopTest.syntacticComplexity() + res + 1;
{ return res + 1; }

int syncomp = loopTest.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + loopTest);
System.err.println(">>> Recommend OCL refactoring");
}

return syncomp + res + 1;
}

public int cyclomaticComplexity()
Expand Down Expand Up @@ -7707,7 +7742,17 @@ public Statement replaceModuleReferences(UseCase uc)
{ return this; }

public int syntacticComplexity()
{ return 3; } // depends upon the type really.
{ if (initialExpression == null)
{ return 3; } // depends upon the type really.

int syncomp = initialExpression.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + initialExpression);
System.err.println(">>> Recommend OCL refactoring");
}

return 3 + syncomp;
}

public int cyclomaticComplexity()
{ return 0; }
Expand Down Expand Up @@ -9838,7 +9883,14 @@ public Statement replaceModuleReferences(UseCase uc)

public int syntacticComplexity()
{ if (thrownObject != null)
{ return 1 + thrownObject.syntacticComplexity(); }
{ int syncomp = thrownObject.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + thrownObject);
System.err.println(">>> Recommend OCL refactoring");
}
return 1 + syncomp;
}

return 1;
}

Expand Down Expand Up @@ -10235,7 +10287,13 @@ public Statement replaceModuleReferences(UseCase uc)
{ return this; }

public int syntacticComplexity()
{ int res = condition.syntacticComplexity();
{ int res = condition.syntacticComplexity();

if (res > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + res + ") for " + condition);
System.err.println(">>> Recommend OCL refactoring");
}

res++;
if (message != null)
{ return res + message.syntacticComplexity(); }
Expand Down Expand Up @@ -13581,7 +13639,13 @@ public Statement replaceModuleReferences(UseCase uc)
}

public int syntacticComplexity()
{ return lhs.syntacticComplexity() + rhs.syntacticComplexity() + 1; }
{ int syncomp = rhs.syntacticComplexity();
if (syncomp > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + syncomp + ") for " + rhs);
System.err.println(">>> Recommend OCL refactoring");
}
return lhs.syntacticComplexity() + syncomp + 1;
}

public int cyclomaticComplexity()
{ return 0; }
Expand Down Expand Up @@ -13933,7 +13997,12 @@ public IfCase replaceModuleReferences(UseCase uc)
}

public int syntacticComplexity()
{ int res = test.syntacticComplexity();
{ int res = test.syntacticComplexity();
if (res > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + res + ") for " + test);
System.err.println(">>> Recommend OCL refactoring");
}

res = res + ifPart.syntacticComplexity();
return res + 1;
}
Expand Down Expand Up @@ -14755,6 +14824,12 @@ public Statement replaceModuleReferences(UseCase uc)

public int syntacticComplexity()
{ int res = test.syntacticComplexity();

if (res > TestParameters.syntacticComplexityLimit)
{ System.err.println("!!! Code smell (MEL): too high expression complexity (" + res + ") for " + test);
System.err.println(">>> Recommend OCL refactoring");
}

res = res + ifPart.syntacticComplexity();
if (elsePart != null)
{ res = res + elsePart.syntacticComplexity(); }
Expand Down
Binary file modified TestParameters.class
Binary file not shown.
5 changes: 3 additions & 2 deletions TestParameters.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down Expand Up @@ -30,7 +30,8 @@ public class TestParameters

/* Settings for flaw/technical debt detection */

public static int cloneSizeLimit = 6;
public static int syntacticComplexityLimit = 8; /* for MEL */
public static int cloneSizeLimit = 6; /* for DC */
public static int statementNestingLimit = 5;
public static int cyclomaticComplexityLimit = 10;
public static int numberOfDataFeaturesLimit = 20;
Expand Down
Binary file modified TryStatement.class
Binary file not shown.
2 changes: 1 addition & 1 deletion UCDArea.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/******************************
* Copyright (c) 2003--2024 Kevin Lano
* Copyright (c) 2003--2025 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
Expand Down
Binary file modified WhileStatement.class
Binary file not shown.

0 comments on commit b2504ed

Please sign in to comment.