Skip to content

Commit

Permalink
Improved model generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano committed Apr 18, 2024
1 parent c3aa9ef commit a5b685a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -6704,12 +6704,12 @@ else if ("boolean".equals(t))
opTests.add(attname + " = false;");
}
else if ("String".equals(t))
{ JOptionPane.showMessageDialog(null,
{ /* JOptionPane.showMessageDialog(null,
">> Attribute " + this + " has fixed size: " +
type.getFixedSize() +
" Tests: " + res,
"",
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.INFORMATION_MESSAGE); */
if (type.hasFixedSize())
{ Expression fs = type.getFixedSize();
int fsize = Expression.convertInteger(fs + "");
Expand Down
74 changes: 72 additions & 2 deletions BehaviouralFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class BehaviouralFeature extends ModelElement
private Statement activity = null;
private String text = ""; // The text of the operation

private String comments = null;

private boolean derived = false;
private boolean bx = false;

Expand Down Expand Up @@ -125,6 +127,9 @@ public void setReturnType(Type rt)
{ elementType = rt; } // primitive, String, entity type
}

public void setComments(String comms)
{ comments = comms; }

public Expression makeLambdaExpression(Expression inst)
{ // lambda pars : ParTypes in inst.name(pars)

Expand Down Expand Up @@ -3368,6 +3373,8 @@ public void splitIntoSegments()
newopname, pars, query, resultType);
bf.setEntity(entity);
bf.setPost(new BasicExpression(true));
bf.setComments("Derived from " + nme + " by Split operation refactoring");

if (residue.size() > 0)
{ sseg.addStatements(residue); }
residue = new Vector();
Expand Down Expand Up @@ -5814,6 +5821,9 @@ public String getOperationCode(Entity ent, Vector entities, Vector types)

res = " public " + statc + genPars + ts + " " + name + "(" + pars + ")\n { ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (ent.isInterface())
{ return " public " + genPars + ts + " " + name + "(" + pars + ");\n"; }

Expand Down Expand Up @@ -5856,6 +5866,9 @@ else if (activity != null)

res = " public " + header + genPars + ts + " " + name + "(" + pars + ")\n { ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (tp != null && !"void".equals(ts))
{ res = res + ts + " result;\n"; }
localatts.addAll(parameters);
Expand Down Expand Up @@ -5992,6 +6005,9 @@ public String getOperationCodeJava6(Entity ent, Vector entities, Vector types)

res = " public " + statc + ts + " " + name + "(" + pars + ")\n{ ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (ent != null && ent.isInterface())
{ return " public " + ts + " " + name + "(" + pars + ");\n"; }

Expand Down Expand Up @@ -6034,6 +6050,9 @@ else if (activity != null)

res = " public " + header + ts + " " + name + "(" + pars + ")\n { ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (tp != null && !("void".equals(ts)))
{ res = res + ts + " result;\n"; }

Expand Down Expand Up @@ -6192,6 +6211,9 @@ else if (activity != null)

res = " public " + statc + ts + " " + name + "(" + pars + ")\n{ ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (ent != null && ent.isInterface())
{ return " public " + ts + " " + name + "(" + pars + ");\n"; }

Expand Down Expand Up @@ -6234,6 +6256,9 @@ else if (activity != null)

res = " public " + header + ts + " " + name + "(" + pars + ")\n { ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (tp != null & !"void".equals(ts))
{ res = res + ts + " result;\n"; }

Expand Down Expand Up @@ -6266,10 +6291,12 @@ else if (activity != null)
else
{ actualtyp = new Type("Set",null);
actualtyp.setElementType(preterm.getElementType());

String jType = actualtyp.getJava7(preterm.getElementType());
newdec = " " + jType + " " + pre_var + " = new " + jType + "();\n" +
" " + pre_var + ".addAll(" + pretermqf + ");\n";
}
}

actualtyp.setSorted(preterm.isSorted());
prebe.setSorted(preterm.isSorted());
System.out.println(">> Type of " + preterm + " = " + preterm.type + " { " + preterm.isSorted() + " }");
Expand All @@ -6281,7 +6308,7 @@ else if (activity != null)
newdecs = newdecs + " " + newdec;
prebe.type = actualtyp;
prebe.elementType = preterm.elementType;
System.out.println("Pre variable " + prebe + " type= " + actualtyp +
System.out.println(">> Pre variable " + prebe + " type= " + actualtyp +
" elemtype= " + prebe.elementType);

Attribute preatt =
Expand Down Expand Up @@ -6389,6 +6416,9 @@ public String getOperationCodeCSharp(Entity ent, Vector entities, Vector types)

res = " public " + statc + ts + " " + name + genPars + "(" + pars + ")\n{ ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (ent != null && ent.isInterface())
{ return " public " + ts + " " + name + genPars + "(" + pars + ");\n"; }

Expand Down Expand Up @@ -6434,6 +6464,9 @@ public String getOperationCodeCSharp(Entity ent, Vector entities, Vector types)

res = " public " + header + ts + " " + name + genPars + "(" + pars + ")\n { ";

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (Statement.hasResultDeclaration(activity))
{ }
else if (tp != null && !("void".equals(ts)))
Expand Down Expand Up @@ -6612,6 +6645,9 @@ else if (isVirtual(ent))
res = header + " " + ts + " " + exname + "::" + name + "(" + pars + ")\n { ";
decs.add(opGenPars + " " + isstatic + ts + " " + name + "(" + pars + ");\n");

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

// if (ent.isInterface())
// { return " public " + ts + " " + name + "(" + pars + ");\n"; }

Expand Down Expand Up @@ -6663,6 +6699,9 @@ else if (isVirtual(ent))
res = header + " " + ts + " " + exname + "::" + name + "(" + pars + ")\n { ";
decs.add(opGenPars + " " + isstatic + ts + " " + name + "(" + pars + ");\n");

if (comments != null)
{ res = res + "/* " + comments + " */\n "; }

if (Statement.hasResultDeclaration(activity))
{ }
else if (tp != null && !("void".equals(ts)))
Expand Down Expand Up @@ -6844,6 +6883,9 @@ public String buildQueryOp(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();
if (ent == null || isClassScope() || isStatic()) { }
else
Expand Down Expand Up @@ -7020,6 +7062,9 @@ public String buildQueryOpJava6(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();
if (ent == null || isClassScope() || isStatic()) { }
else
Expand Down Expand Up @@ -7135,6 +7180,9 @@ public String buildQueryOpJava7(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();
if (ent == null || isClassScope() || isStatic()) { }
else
Expand Down Expand Up @@ -7260,6 +7308,9 @@ public String buildQueryOpCSharp(Entity ent, String opname,
header = header + resT + " " +
opname + genPars + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();
if (ent == null || isClassScope() || isStatic()) { }
else
Expand Down Expand Up @@ -7421,6 +7472,9 @@ else if (isVirtual(ent))
header = header + " " + resT + " " + exname + "::" +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

String opdec = "";
if (typeParameters.size() > 0)
{ opdec = opGenPars; }
Expand Down Expand Up @@ -8418,6 +8472,9 @@ public String buildUpdateOp(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();

if (ent == null || isClassScope() || isStatic()) { }
Expand Down Expand Up @@ -8538,6 +8595,9 @@ public String buildUpdateOpJava6(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();

if (ent == null || isClassScope() || isStatic()) { }
Expand Down Expand Up @@ -8664,6 +8724,9 @@ public String buildUpdateOpJava7(Entity ent, String opname,
header = header + genPars + resT + " " +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();

if (ent == null || isClassScope() || isStatic()) { }
Expand Down Expand Up @@ -8799,6 +8862,9 @@ public String buildUpdateOpCSharp(Entity ent, String opname,
opname + genPars +
"(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

java.util.Map env0 = new java.util.HashMap();

if (ent == null || isClassScope() || isStatic()) { }
Expand Down Expand Up @@ -8973,6 +9039,10 @@ else if (isVirtual(ent))
{ header = " " + genPars + "\n"; }
header = header + " " + resT + " " + exname + "::" +
opname + "(" + javaPars + ")\n { ";

if (comments != null)
{ header = header + "/* " + comments + " */\n "; }

decs.add(opGenPars + " " + isstatic + resT + " " + opname + "(" + javaPars + ");\n");

java.util.Map env0 = new java.util.HashMap();
Expand Down
29 changes: 28 additions & 1 deletion Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Entity extends ModelElement implements Comparable
int cardinalityValue = 1; // container is a sequence if > 1
int totalWidth = 0; // sum of attribute widths

String comments = null;


public Entity(String nme)
{ super(nme);
realEntity = this;
Expand All @@ -66,6 +69,9 @@ public Object clone()
return res;
}

public void setComments(String comms)
{ comments = comms; }

public Entity mergeEntity(Entity ent)
{ // Combine features of this with priority over ent

Expand Down Expand Up @@ -5046,6 +5052,8 @@ public void extractOperations()
if (copies != null && copies.size() > 1)
{ Object obj = cdefs.get(clne);
System.out.println(">>> Extracting operation for clone: " + clne + " with copies " + copies);

String opname = (String) copies.get(0);

if (obj instanceof Expression)
{ Expression expr = (Expression) obj;
Expand All @@ -5059,7 +5067,6 @@ public void extractOperations()
Type elemtype = expr.getElementType();
System.out.println(">> Clone expression type: " + etype + " (" + elemtype + ")");

String opname = (String) copies.get(0);
int colonIndex = opname.indexOf("::");
opname =
opname.substring(colonIndex+2,opname.length());
Expand Down Expand Up @@ -5123,6 +5130,8 @@ public void extractOperations()
BehaviouralFeature bf =
new BehaviouralFeature(fname,pars,true,etype);
bf.setPostcondition(eqn);

bf.setComments("Operation for cloned expression of operation " + opname);

BasicExpression selfvar =
BasicExpression.newVariableBasicExpression(
Expand Down Expand Up @@ -5202,6 +5211,7 @@ else if (obj instanceof Statement)
fname,oppars,false,null);
bf.setPostcondition(new BasicExpression(true));
bf.setActivity(stat);
bf.setComments("Operation for cloned statements of operation " + opname);

BasicExpression bfcall =
BasicExpression.newCallBasicExpression(
Expand Down Expand Up @@ -9000,6 +9010,9 @@ else if (isLeaf())
out.println();
out.println("{");

if (comments != null)
{ out.println(" /* " + comments + " */"); }

for (int i = 0; i < attributes.size(); i++)
{ Attribute att = (Attribute) attributes.get(i);
if (isInterface())
Expand Down Expand Up @@ -9110,6 +9123,9 @@ else if (isLeaf())
out.println();
out.println("{");

if (comments != null)
{ out.println(" /* " + comments + " */"); }

for (int i = 0; i < attributes.size(); i++)
{ Attribute att = (Attribute) attributes.get(i);
if (isInterface())
Expand Down Expand Up @@ -9214,9 +9230,13 @@ else if (isLeaf())
if (bf != null && bf.getSm() != null)
{ addRunStates(bf.getSm()); }
}

out.println();
out.println("{");

if (comments != null)
{ out.println(" /* " + comments + " */"); }

for (int i = 0; i < attributes.size(); i++)
{ Attribute att = (Attribute) attributes.get(i);
if (isInterface())
Expand Down Expand Up @@ -9397,6 +9417,9 @@ else if (isLeaf())
out.println();
out.println("{");

if (comments != null)
{ out.println(" /* " + comments + " */"); }

for (int i = 0; i < attributes.size(); i++)
{ Attribute att = (Attribute) attributes.get(i);
if (isInterface())
Expand Down Expand Up @@ -9526,6 +9549,10 @@ public void generateCPP(Vector entities, Vector types, PrintWriter out, PrintWri

out.println();
out.println("{ ");

if (comments != null)
{ out.println(" /* " + comments + " */"); }

if (attributes.size() + associations.size() > 0)
{ if (subclasses.size() > 0)
{ out.println(" protected:"); }
Expand Down
2 changes: 1 addition & 1 deletion UCDArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ public void extractOperation()
}

String cloneLimit =
JOptionPane.showInputDialog("Enter clone size limit (default 10): ");
JOptionPane.showInputDialog("Enter clone size limit (default 10): ");
if (cloneLimit != null)
{ try { CLONE_LIMIT = Integer.parseInt(cloneLimit); }
catch (Exception _ex)
Expand Down
Loading

0 comments on commit a5b685a

Please sign in to comment.