Skip to content

Commit

Permalink
Improved sustainability analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Nov 27, 2024
1 parent e9ab4aa commit 5326028
Show file tree
Hide file tree
Showing 27 changed files with 2,154 additions and 14 deletions.
Binary file modified ASTCompositeTerm.class
Binary file not shown.
72 changes: 65 additions & 7 deletions ASTCompositeTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -23757,6 +23757,50 @@ else if (("println".equals(called) ||

return "execute (OclFile[\"System.err\"].println(" + res + "))";
}
else if ("println".equals(called) ||
"print".equals(called))
{ if (cargs.size() == 0)
{ Vector pars = new Vector();
Expression par =
BasicExpression.newValueBasicExpression("\"\"");
expression =
new UnaryExpression("->display", par);
statement =
new ImplicitInvocationStatement(expression);

return "execute (\"\")->display()";
}

ASTTerm arg1 = (ASTTerm) cargs.get(0);
String callp = arg1.toKM3();

Statement sideEffect = arg1.statement;
if (arg1.hasSideEffect()) { }
else
{ sideEffect = null; }

JOptionPane.showInputDialog(">>> Side effect of println is: " + sideEffect);

String res = arg1.queryForm();

if (argexpr != null && arg1.expression != null)
{ arg1.expression.setBrackets(true);
expression =
BasicExpression.newCallBasicExpression(
called, argexpr, arg1.expression);
Statement stat =
new ImplicitInvocationStatement(expression);

if (sideEffect == null)
{ statement = stat; }
else
{ statement =
new SequenceStatement(stat,sideEffect);
}
}

return "" + statement;
}
else if ("exec".equals(called) &&
"OclProcess".equals(ASTTerm.getType(arg)))
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
Expand Down Expand Up @@ -34006,24 +34050,24 @@ public String toKM3()
expression = t.expression; // queryForm

if (t.updatesObject(null))
{ System.out.println(">> Expression returning value, and with side-effect: " + t);
{ // System.out.println(">> Expression returning value, and with side-effect: " + t);
statement = t.statement; // updateForm
System.out.println(">> Update form: >> " + statement);
// System.out.println(">> Update form: >> " + statement);
System.out.println();
String qf = t.queryForm();
expression = t.expression;
System.out.println(">> Query form: >> " + expression);
// System.out.println(">> Query form: >> " + expression);

return qf + " ; " + initexpr;
}
else if (t.hasSideEffect())
{ System.out.println(">> Expression returning value, and with side-effect: " + t);
statement = t.statement; // updateForm
System.out.println(statement);
System.out.println();
// System.out.println(statement);
// System.out.println();
String qf = t.queryForm();
expression = t.expression;
System.out.println(">> Query form: >> " + expression);
// System.out.println(">> Query form: >> " + expression);

return qf + " ; " + initexpr;
}
Expand Down Expand Up @@ -39494,7 +39538,7 @@ else if (terms.size() == 4 &&
else if (terms.size() == 3 &&
"(".equals(terms.get(0) + "") &&
")".equals(terms.get(2) + ""))
{ // casting
{ // brackets
ASTTerm call = (ASTTerm) terms.get(1);
return call.hasSideEffect();
}
Expand All @@ -39520,6 +39564,10 @@ else if (terms.size() == 5 && "?".equals(terms.get(1) + ""))
return (condx || ifx || elsex);
}
}

if ("methodCall".equals(tag))
{ return false; }

return false;
}

Expand Down Expand Up @@ -39663,6 +39711,15 @@ else if (terms.size() == 4 &&
statement = call.statement;
return res;
}
else if (terms.size() == 3 &&
"(".equals(terms.get(0) + "") &&
")".equals(terms.get(2) + ""))
{ // brackets
ASTTerm call = (ASTTerm) terms.get(1);
String res = call.preSideEffect();
statement = call.statement;
return res;
}
else if (terms.size() == 4 &&
"[".equals(terms.get(1) + "") &&
"]".equals(terms.get(3) + "")) // array access
Expand Down Expand Up @@ -39800,6 +39857,7 @@ public String postSideEffect()
}
return callp1;
}

return null;
}

Expand Down
Binary file modified ATLFileFilter.class
Binary file not shown.
Binary file modified BasicExpression.class
Binary file not shown.
10 changes: 10 additions & 0 deletions BasicExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -5575,6 +5575,7 @@ else if (objectRef.type != null && objectRef.type.isEntity(entities))
!data.equals("setSubrange") &&
!data.equals("insertAt") &&
!data.equals("insertInto") &&
// !(data.equals("split")) &&
!(data.equals("replace")) &&
!(data.equals("replaceFirstMatch")) &&
!(data.equals("replaceAll")) &&
Expand Down Expand Up @@ -6331,6 +6332,15 @@ else if (type == null)
return true;
}

public boolean isOperationCall()
{ if (isEvent && parameters != null)
{ return true; }
if (umlkind == UPDATEOP ||
umlkind == QUERY)
{ return true; }
return false;
}

private void setObjectRefType()
{ if (entity != null && objectRef != null && objectRef.umlkind == VARIABLE &&
objectRef.getType() == null)
Expand Down
Binary file modified BehaviouralFeature.class
Binary file not shown.
31 changes: 24 additions & 7 deletions BehaviouralFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -3312,14 +3312,15 @@ public void removeEntityParameter(Entity ent)
}
}

public void checkParameterNames()
{ if (parameters == null)
{ return; }
public Vector checkParameterNames()
{ Vector unusedVars = new Vector();

if (parameters == null)
{ return unusedVars; }

Vector pnames = new Vector();

int UVA = 0;
Vector unusedVars = new Vector();

for (int i = 0; i < parameters.size(); i++)
{ Attribute par = (Attribute) parameters.get(i);
Expand Down Expand Up @@ -3347,7 +3348,7 @@ public void checkParameterNames()
if (puses.size() == 0)
{ System.err.println("!! Code smell (UVA): parameter " + pname + " is unused in operation " + getName() + " postcondition.");
UVA++;
unusedVars.add(pname);
unusedVars.add(par);
}
}

Expand All @@ -3356,7 +3357,7 @@ public void checkParameterNames()
if (actuses.size() == 0)
{ System.err.println("!! Code smell (UVA): parameter " + pname + " is unused in operation " + getName() + " activity.");
UVA++;
unusedVars.add(pname);
unusedVars.add(par);
}
}
}
Expand All @@ -3366,8 +3367,15 @@ public void checkParameterNames()
System.out.println("!! Unused parameters: " + unusedVars);
System.out.println();
}

return unusedVars;
}

public void removeUnusedParameters()
{ Vector unusedVars = checkParameterNames();
parameters.removeAll(unusedVars);
}


public void splitIntoSegments()
{ if (activity == null)
Expand Down Expand Up @@ -4341,7 +4349,7 @@ public Map energyAnalysis(Vector redUses, Vector amberUses)
}

if (actualClones.size() > 0)
{ amberUses.add("!!! Cloned expressions could be repeated evaluations: " + actualClones + "\n" +
{ amberUses.add("!! Cloned expressions could be repeated evaluations: " + actualClones + "\n" +
">>> Use Extract Local Variable refactoring");
int ascore = (int) res.get("amber");
ascore = ascore + actualClones.size();
Expand All @@ -4350,6 +4358,15 @@ public Map energyAnalysis(Vector redUses, Vector amberUses)
} // In a postcondition they usually are repeats.
}

Vector unusedVars = checkParameterNames();
if (unusedVars.size() > 0)
{ amberUses.add("!! Unused parameters: " + unusedVars + "\n" +
">>> Use remove unused parameters refactoring");
int ascore = (int) res.get("amber");
ascore = ascore + unusedVars.size();
res.set("amber", ascore);
}

return res;
}

Expand Down
Binary file modified BinaryExpression.class
Binary file not shown.
13 changes: 13 additions & 0 deletions BinaryExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,11 @@ else if (operator.equals("div"))
if (type == null)
{ type = new Type("int", null); }
}
/* else if (operator.equals("->split"))
{ elementType = new Type("String",null);
type = new Type("Sequence", null);
type.setElementType(elementType);
} */
else if ("->hasPrefix".equals(operator) ||
"->hasSuffix".equals(operator) ||
"->hasMatch".equals(operator) ||
Expand Down Expand Up @@ -20658,6 +20663,14 @@ else if ("->unionAll".equals(operator) ||
int ascore = (int) res.get("amber");
res.set("amber", ascore+1);
}
else if ("->at".equals(operator) &&
left instanceof BasicExpression &&
((BasicExpression) left).isOperationCall())
{ // redundant results computation
aUses.add("! Redundant results computation in: " + this);
int ascore = (int) res.get("amber");
res.set("amber", ascore+1);
}

return res;
}
Expand Down
Binary file modified ETLFileFilter.class
Binary file not shown.
Binary file modified EcoreFileFilter.class
Binary file not shown.
Binary file modified Entity.class
Binary file not shown.
Binary file modified KM3FileFilter.class
Binary file not shown.
Loading

0 comments on commit 5326028

Please sign in to comment.