Skip to content

Commit cb7d32a

Browse files
authored
Completed VB6 abstraction tools
1 parent 7a4cf81 commit cb7d32a

16 files changed

+805
-252
lines changed

BasicExpression.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,19 @@ public static void updateVariableType(Expression lhs, Expression rhs)
845845
{ if (lhs instanceof BasicExpression)
846846
{ BasicExpression be = (BasicExpression) lhs;
847847
if (be.variable != null)
848-
{ Type elemType = rhs.getElementType();
848+
{ Type vType = rhs.getType();
849+
850+
System.out.println(">>> RHS type: " + vType);
851+
852+
Type oldVType = be.variable.getType();
853+
854+
System.out.println(">>> old type: " + oldVType);
855+
856+
be.variable.setType(
857+
Type.refineType(oldVType, vType));
858+
System.out.println(">> From " + lhs + " := " + rhs + " deduced type " + be.variable.getType() + " for " + be.data);
859+
860+
Type elemType = rhs.getElementType();
849861

850862
System.out.println(">>> RHS element type: " + elemType);
851863

BehaviouralFeature.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ public Object clone()
408408
return res;
409409
} // and copy the use case, readfr, etc?
410410

411+
public BehaviouralFeature interfaceOperation()
412+
{ BehaviouralFeature res = (BehaviouralFeature) clone();
413+
res.activity = null;
414+
res.setAbstract(true);
415+
return res;
416+
}
417+
411418
public BehaviouralFeature addContainerReference(
412419
BasicExpression ref,
413420
String var, Vector excl)
@@ -2522,6 +2529,13 @@ public static boolean isUpdateN(ModelElement mm)
25222529
return false;
25232530
}
25242531

2532+
public void setAbstract(boolean ab)
2533+
{ if (ab)
2534+
{ addStereotype("abstract"); }
2535+
else
2536+
{ removeStereotype("abstract"); }
2537+
}
2538+
25252539
public boolean isAbstract()
25262540
{ return hasStereotype("abstract"); }
25272541

@@ -3428,7 +3442,7 @@ else if (useCase != null)
34283442

34293443
out.println("*** Number of parameters of operation " + nme + " = " + pars);
34303444
if (pars > 10)
3431-
{ System.err.println("*** Bad smell (EPL): too many parameters (" + pars + ") for " + nme);
3445+
{ System.err.println("!!! Bad smell (EPL): too many parameters (" + pars + ") for " + nme);
34323446
System.err.println(">>> Recommend refactoring by introducing value object for parameters or splitting operation into parts");
34333447
}
34343448

@@ -3446,18 +3460,27 @@ else if (useCase != null)
34463460

34473461
if (activity != null)
34483462
{ cyc = activity.cyclomaticComplexity();
3449-
complexity = complexity + cyc;
34503463
out.println("*** Activity cyclomatic complexity = " + cyc);
3464+
int acomp = activity.syntacticComplexity();
3465+
out.println("*** Activity syntactic complexity = " + acomp);
3466+
if (acomp > 100)
3467+
{ System.err.println("!!! Bad smell (EOS): too high activity complexity (" + acomp + ") for " + nme);
3468+
System.err.println(">>> Recommend refactoring by functional decomposition");
3469+
}
3470+
else if (acomp > 50)
3471+
{ System.err.println("*** Warning: high activity complexity (" + acomp + ") for " + nme); }
3472+
complexity = complexity + acomp;
34513473
}
34523474

34533475
out.println("*** Total complexity of operation " + nme + " = " + complexity);
34543476
out.println();
34553477
if (cyc > 10)
3456-
{ System.err.println("*** Bad smell (CC): high cyclomatic complexity (" + cyc + ") for " + nme);
3478+
{ System.err.println("!!! Bad smell (CC): high cyclomatic complexity (" + cyc + ") for " + nme);
34573479
System.err.println(">>> Recommend refactoring by functional decomposition");
34583480
}
3481+
34593482
if (complexity > 100)
3460-
{ System.err.println("*** Bad smell (EHS): too high complexity (" + complexity + ") for " + nme);
3483+
{ System.err.println("!!! Bad smell (EHS): too high complexity (" + complexity + ") for " + nme);
34613484
System.err.println(">>> Recommend refactoring by functional decomposition");
34623485
}
34633486
else if (complexity > 50)
@@ -3496,7 +3519,7 @@ else if (useCase != null)
34963519

34973520
System.out.println("*** Number of parameters of operation " + nme + " = " + pars);
34983521
if (pars > 10)
3499-
{ System.err.println("*** Bad smell (EPL): too many parameters (" + pars + ") for " + nme); }
3522+
{ System.err.println("!!! Bad smell (EPL): too many parameters (" + pars + ") for " + nme); }
35003523

35013524
int complexity = 0;
35023525
int cyc = 0;
@@ -3519,9 +3542,9 @@ else if (useCase != null)
35193542
System.out.println("*** Total complexity of operation " + nme + " = " + complexity);
35203543
System.out.println();
35213544
if (cyc > 10)
3522-
{ System.err.println("*** Bad smell (CC): high cyclomatic complexity (" + cyc + ") for " + nme); }
3545+
{ System.err.println("!!! Bad smell (CC): high cyclomatic complexity (" + cyc + ") for " + nme); }
35233546
if (complexity > 100)
3524-
{ System.err.println("*** Bad smell (EHS): too high complexity (" + complexity + ") for " + nme); }
3547+
{ System.err.println("!!! Bad smell (EHS): too high complexity (" + complexity + ") for " + nme); }
35253548

35263549
return cyc;
35273550
}
@@ -3552,7 +3575,9 @@ else if (useCase != null)
35523575
{ pre.findClones(clones,null, nme); }
35533576
if (post != null)
35543577
{ post.findClones(clones,null, nme); }
3555-
} // and activity
3578+
if (activity != null)
3579+
{ activity.findClones(clones, null, nme); }
3580+
}
35563581

35573582
public void generateJava(PrintWriter out)
35583583
{ out.print(toString()); }

BinaryExpression.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4475,7 +4475,8 @@ else if (operator.equals("->restrict"))
44754475
else if (operator.equals("->including") ||
44764476
operator.equals("->prepend") ||
44774477
operator.equals("->append"))
4478-
{ Type newleftET = Type.refineType(etleft,right.getType());
4478+
{ Type newleftET =
4479+
Type.refineType(etleft,right.getType());
44794480
System.out.println(">> Deduced element type of " + this + " = " + newleftET);
44804481
elementType = newleftET;
44814482
if (type == null)
@@ -4651,7 +4652,7 @@ private void tcMathOps(Type tleft, Type tright,
46514652
else
46524653
{ type = Expression.deduceType(operator,left,right);
46534654

4654-
System.err.println("Warning!: arguments must be numeric in: " + this + ". Deduced type: " + type);
4655+
System.err.println("!Warning!: arguments must be numeric in: " + this + " Deduced type: " + type);
46554656
if (type == null)
46564657
{ JOptionPane.showMessageDialog(null, "Arguments not numeric in: " + this,
46574658
"Type error", JOptionPane.ERROR_MESSAGE);
@@ -4665,14 +4666,14 @@ else if (tlname.equals("long") || trname.equals("long"))
46654666
else if (trname.equals("int") && trname.equals("int"))
46664667
{ type = new Type("int",null); }
46674668
else
4668-
{ System.err.println("TYPE ERROR: invalid types " + tlname + " " + trname + " in: " + this);
4669+
{ System.err.println("!! TYPE ERROR: invalid types " + tlname + " " + trname + " in: " + this);
46694670
type = new Type("int", null);
46704671
}
46714672
}
46724673
else
46734674
{ type = Expression.deduceType(operator,left,right);
46744675

4675-
System.err.println("TYPE ERROR: invalid types " + tleft + " " + tright + " in: " + this + ". Deduced type " + type);
4676+
System.err.println("!! TYPE ERROR: invalid types " + tleft + " " + tright + " in: " + this + ". Deduced type " + type);
46764677
JOptionPane.showMessageDialog(null, "Missing types in: " + this,
46774678
"Type error", JOptionPane.ERROR_MESSAGE);
46784679
if (tleft != null)
@@ -4699,14 +4700,19 @@ private void tcLogical(Type tleft, Type tright,
46994700
if (tlname.equals("boolean") && trname.equals("boolean"))
47004701
{ }
47014702
else
4702-
{ System.err.println("Warning: invalid types in: " + this);
4703+
{ System.err.println("! Warning: invalid types " + tlname + " " + trname + " in: " + this);
47034704
JOptionPane.showMessageDialog(null, "Arguments must be booleans: " + this,
47044705
"Type error", JOptionPane.ERROR_MESSAGE);
4706+
if ("int".equals(tlname) && "int".equals(trname))
4707+
{ // bitwise operator
4708+
System.err.println("!! Bitwise operator expected here !!");
4709+
type = new Type("int", null);
4710+
}
47054711
}
47064712
type = new Type("boolean",null);
47074713
}
47084714
else
4709-
{ System.err.println("TYPE ERROR: invalid types in: " + this);
4715+
{ System.err.println("!! TYPE ERROR: invalid types in: " + this);
47104716
JOptionPane.showMessageDialog(null, "Missing types in: " + this,
47114717
"Type error", JOptionPane.ERROR_MESSAGE);
47124718
}
@@ -18172,8 +18178,16 @@ public Expression featureAdding2(String var, Vector remainder)
1817218178
public int syntacticComplexity()
1817318179
{ int res = left.syntacticComplexity();
1817418180
res = res + right.syntacticComplexity();
18175-
if (operator.equals("#") || operator.equals("#1") || operator.equals("#LC") || operator.equals("!") ||
18176-
operator.equals("|") || operator.equals("|R") || operator.equals("|C"))
18181+
if (operator.equals("#") || operator.equals("#1") ||
18182+
operator.equals("#LC") || operator.equals("!") ||
18183+
operator.equals("|") || operator.equals("|R") ||
18184+
operator.equals("|C") ||
18185+
operator.equals("|A") ||
18186+
operator.equals("|intersectAll") ||
18187+
operator.equals("|unionAll") ||
18188+
operator.equals("|selectMinimals") ||
18189+
operator.equals("|selectMaximals")
18190+
)
1817718191
{ return res; }
1817818192

1817918193
if (operator.equals("->iterate"))
@@ -18189,9 +18203,11 @@ public int syntacticComplexity()
1818918203
}
1819018204

1819118205
public int cyclomaticComplexity()
18192-
{ if (operator.equals("#") || operator.equals("#1") || operator.equals("#LC") || operator.equals("!"))
18206+
{ if (operator.equals("#") || operator.equals("#1") ||
18207+
operator.equals("#LC") || operator.equals("!"))
1819318208
{ return right.cyclomaticComplexity(); }
18194-
else if (operator.equals("&") || operator.equals("or") || operator.equals("=>"))
18209+
else if (operator.equals("&") ||
18210+
operator.equals("or") || operator.equals("=>"))
1819518211
{ return left.cyclomaticComplexity() + right.cyclomaticComplexity(); }
1819618212

1819718213
if (operator.equals("->iterate"))

CGCondition.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,31 @@ public void applyAction(Vector vars, Vector eargs, Vector reps, CGSpec cgs, Vect
125125
for (int x = 0; x < reps.size() && x < vars.size(); x++)
126126
{ String var = (String) vars.get(x);
127127
String arg1 = (String) reps.get(x);
128+
129+
String svarx = var;
130+
String smffeat = null;
131+
Vector stereomfs = CGRule.metafeatures(stereo);
132+
if (stereomfs.size() > 0)
133+
{
134+
// If stereo has a metafeature: _i`mf
135+
// evaluate _i`mf in cgs and set stereo to result
136+
137+
String smf = (String) stereomfs.get(0);
138+
int smfindex = smf.indexOf("`");
139+
svarx = smf.substring(0,smfindex);
140+
smffeat = smf.substring(smfindex+1,smf.length());
141+
if (smffeat != null && var.equals(svarx))
142+
{ int indv = vars.indexOf(svarx);
143+
144+
if (indv >= 0 && eargs.get(indv) instanceof ASTTerm)
145+
{
146+
ASTTerm earg = (ASTTerm) eargs.get(indv);
147+
stereo = CGRule.applyMetafeature(
148+
smffeat,earg,cgs,entities);
149+
}
150+
}
151+
}
152+
128153
stereo = stereo.replace(var,arg1);
129154
}
130155

@@ -677,6 +702,8 @@ public boolean conditionSatisfied(ASTTerm a, Vector entities, CGSpec cgs)
677702
String repl = CGRule.applyMetafeature(
678703
mffeat,a,cgs,entities);
679704

705+
System.out.println(">>> Test LHS = " + repl + " RHS = " + stereotype);
706+
680707
if (repl != null && repl.equals(stereotype))
681708
{ return positive; }
682709
else
@@ -685,6 +712,11 @@ public boolean conditionSatisfied(ASTTerm a, Vector entities, CGSpec cgs)
685712

686713
// Also the stereotype could have one.
687714

715+
// if ("integer".equalsIgnoreCase(stereotype))
716+
// { if (a.isInteger())
717+
// { return positive; }
718+
// }
719+
688720
if (a instanceof ASTCompositeTerm)
689721
{ ASTCompositeTerm ac = (ASTCompositeTerm) a;
690722

CGRule.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ public static String applyMetafeature(String mffeat,
531531
return repl;
532532
}
533533
}
534+
535+
if (term instanceof ASTSymbolTerm)
536+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
537+
return "" + st.symbol.charAt(0);
538+
}
534539

535540
String replx = term.cg(cgs);
536541
return replx;
@@ -549,6 +554,10 @@ public static String applyMetafeature(String mffeat,
549554
return repl;
550555
}
551556
}
557+
if (term instanceof ASTSymbolTerm)
558+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
559+
return "" + st.symbol.charAt(1);
560+
}
552561
}
553562

554563
if ("third".equals(mffeat) ||
@@ -564,6 +573,11 @@ public static String applyMetafeature(String mffeat,
564573
return repl;
565574
}
566575
}
576+
if (term instanceof ASTSymbolTerm)
577+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
578+
return "" + st.symbol.charAt(2);
579+
}
580+
567581
}
568582

569583
if ("fourth".equals(mffeat) ||
@@ -579,6 +593,11 @@ public static String applyMetafeature(String mffeat,
579593
return repl;
580594
}
581595
}
596+
if (term instanceof ASTSymbolTerm)
597+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
598+
return "" + st.symbol.charAt(3);
599+
}
600+
582601
}
583602

584603
if ("fifth".equals(mffeat) ||
@@ -594,17 +613,28 @@ public static String applyMetafeature(String mffeat,
594613
return repl;
595614
}
596615
}
616+
if (term instanceof ASTSymbolTerm)
617+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
618+
return "" + st.symbol.charAt(4);
619+
}
620+
597621
}
598622

599623
if ("last".equals(mffeat))
600-
{ // get first subterm of obj
624+
{ // get last subterm of obj
601625
if (term instanceof ASTCompositeTerm)
602626
{ ASTCompositeTerm ct = (ASTCompositeTerm) term;
603627
int tsize = ct.terms.size();
604628
ASTTerm ct1 = (ASTTerm) ct.terms.get(tsize-1);
605629
String repl = ct1.cg(cgs);
606630
return repl;
607631
}
632+
if (term instanceof ASTSymbolTerm)
633+
{ ASTSymbolTerm st = (ASTSymbolTerm) term;
634+
int ssize = st.symbol.length();
635+
return "" + st.symbol.charAt(ssize-1);
636+
}
637+
608638
}
609639

610640
if ("tail".equals(mffeat))

0 commit comments

Comments
 (0)