Skip to content

Commit 22bd1e6

Browse files
authored
Improved refactorings
1 parent 50d3f39 commit 22bd1e6

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

ASTTerm.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4768,12 +4768,18 @@ public static Vector powersOf(
47684768
}
47694769

47704770
String v = var.literalForm();
4771+
String elit = expr.literalForm();
47714772

4772-
if (v.equals(expr.literalForm()))
4773+
if (v.equals(elit))
47734774
{ res.add(1);
47744775
return res;
47754776
}
47764777

4778+
if ((v + "^{2}").equals(elit))
4779+
{ res.add(2);
4780+
return res;
4781+
}
4782+
47774783
if (expr instanceof ASTCompositeTerm)
47784784
{ // (factorExpression _1 * _2), etc
47794785

@@ -5563,6 +5569,20 @@ public static String constantTerms(
55635569
return "0";
55645570
}
55655571

5572+
if ("factor2Expression".equals(ct.tag))
5573+
{ if (subterms.size() == 4 &&
5574+
"^{".equals(subterms.get(1) + ""))
5575+
{ // expr^{power}
5576+
ASTTerm tt = (ASTTerm) subterms.get(0);
5577+
ASTTerm power = (ASTTerm) subterms.get(2);
5578+
String powlit = power.literalForm();
5579+
5580+
String coef1 = ASTTerm.constantTerms(vars, tt);
5581+
if ("0".equals(coef1))
5582+
{ return "0"; }
5583+
return "(" + coef1 + ")^{" + powlit + "}";
5584+
}
5585+
}
55665586

55675587
if ("factorExpression".equals(ct.tag))
55685588
{ if (subterms.size() == 2)

Association.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class Association extends ModelElement
3333
private Vector constraints = new Vector(); // those that involve this association
3434
private Attribute qualifier = null; // non-null for qualified associations
3535
private boolean instanceScope = true;
36+
37+
private Expression initialExpression = null;
3638

3739
public Association(Entity e1, Entity e2, int c1,
3840
int c2, String r1, String r2)
@@ -121,6 +123,9 @@ else if ("1".equals(c2))
121123
role2 = r2;
122124
}
123125

126+
public void setInitialExpression(Expression init)
127+
{ initialExpression = init; }
128+
124129
public void setType(Type t) { }
125130

126131
public void addParameter(Attribute att)

CGRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,10 @@ public static String applyMetafeature(String mffeat,
598598
CGSpec cgs, Vector entities)
599599
{ System.out.println(">***> Applying " + mffeat + " to ASTTerm " + term);
600600
System.out.println();
601-
JOptionPane.showMessageDialog(null,
601+
/* JOptionPane.showMessageDialog(null,
602602
"Trying to compute: " + mffeat + " of: " + term +
603603
" in: " + ASTTerm.metafeatures, "",
604-
JOptionPane.INFORMATION_MESSAGE);
604+
JOptionPane.INFORMATION_MESSAGE); */
605605

606606

607607
ASTTerm obj = term;

Compiler2.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8032,6 +8032,15 @@ else if ("Sequence".equals(res.e2name) &&
80328032
res.card2 = ModelElement.MANY;
80338033
res.stereotypes.add("ordered");
80348034
}
8035+
else if (":=".equals(rlex))
8036+
{ Expression init =
8037+
parse_expression(0,reached+1,en-1,entities,types);
8038+
if (init != null)
8039+
{ res.setInitialExpression(init);
8040+
System.out.println(">>> Reference " + res.role2 + ". Initial expression = " + init);
8041+
}
8042+
}
8043+
80358044
return res;
80368045
}
80378046

PreAssociation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.util.Vector;
22

33
/******************************
4-
* Copyright (c) 2003,2019 Kevin Lano
4+
* Copyright (c) 2003-2023 Kevin Lano
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License 2.0 which is available at
77
* http://www.eclipse.org/legal/epl-2.0
@@ -19,6 +19,7 @@ public class PreAssociation
1919
int ys, ye;
2020
String role2;
2121
String role1;
22+
Expression initialExpression;
2223
Vector stereotypes;
2324
Vector wpoints;
2425

@@ -46,6 +47,9 @@ public PreAssociation(String e1n, String e2n, int c1,
4647
wpoints = wps;
4748
}
4849

50+
public void setInitialExpression(Expression expr)
51+
{ initialExpression = expr; }
52+
4953
public boolean isDualTo(PreAssociation pinv)
5054
{ if (pinv.role1 != null && pinv.role1.equals(role2) &&
5155
role1 != null && role1.equals(pinv.role2) &&

UCDArea.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7317,16 +7317,18 @@ public void addEntity(Entity srcent, Entity trgent, int xx)
73177317
private void reconstructAssociation(String ename1,
73187318
String ename2, int xs, int ys, int xe,
73197319
int ye, int c1, int c2, String role2,
7320-
String role1, Vector stereotypes, Vector wpoints)
7320+
String role1, Vector stereotypes, Vector wpoints, Expression initExpr)
73217321
{ Entity e1 =
73227322
(Entity) ModelElement.lookupByName(ename1,entities);
73237323
Entity e2 =
73247324
(Entity) ModelElement.lookupByName(ename2,entities);
7325+
73257326
if (e1 == null || e2 == null)
73267327
{ System.out.println("!! Error in data, no entities " +
73277328
e1 + " " + e2);
73287329
return;
73297330
}
7331+
73307332
if ("null".equals(role1))
73317333
{ role1 = null; }
73327334

@@ -7369,6 +7371,7 @@ else if (stereotypes.contains("qualified"))
73697371
ast.unsetQualifier();
73707372
ast.setQualifier(qatt);
73717373
}
7374+
73727375
if (stereotypes.contains("associationClass"))
73737376
{ int acind = stereotypes.indexOf("associationClass");
73747377
if (acind + 1 < stereotypes.size())
@@ -7387,9 +7390,13 @@ else if (stereotypes.contains("qualified"))
73877390
}
73887391
}
73897392
}
7393+
73907394
System.out.println(">> Reconstructed association class: " + acent + " " + sline);
73917395
}
73927396

7397+
if (initExpr != null)
7398+
{ ast.setInitialExpression(initExpr); }
7399+
73937400
associations.add(ast);
73947401
e1.addAssociation(ast);
73957402
if (role1 != null && role1.length() > 0)
@@ -15892,7 +15899,7 @@ else if (s.equals("Activity:"))
1589215899
(PreAssociation) preassociations.get(i);
1589315900
reconstructAssociation(p.e1name,p.e2name,p.xs,p.ys,
1589415901
p.xe,p.ye,p.card1,p.card2,
15895-
p.role2,p.role1,p.stereotypes, p.wpoints);
15902+
p.role2,p.role1,p.stereotypes, p.wpoints, p.initialExpression);
1589615903
}
1589715904

1589815905
for (int j = 0; j < preentities.size(); j++)
@@ -16143,7 +16150,7 @@ else if (s.equals("Activity:"))
1614316150
(PreAssociation) preassociations.get(i);
1614416151
reconstructAssociation(p.e1name,p.e2name,p.xs,p.ys,
1614516152
p.xe,p.ye,p.card1,p.card2,
16146-
p.role2,p.role1,p.stereotypes, p.wpoints);
16153+
p.role2,p.role1,p.stereotypes, p.wpoints, p.initialExpression);
1614716154
}
1614816155

1614916156
for (int j = 0; j < preentities.size(); j++)
@@ -17849,7 +17856,7 @@ private void loadKM3FromText(String xmlstring)
1784917856
reconstructAssociation(pa.e1name,pa.e2name,xs,ys,
1785017857
xe,ye,pa.card1,pa.card2,
1785117858
pa.role2, pa.role1, pa.stereotypes,
17852-
new Vector());
17859+
new Vector(), pa.initialExpression);
1785317860
}
1785417861
}
1785517862

@@ -18019,7 +18026,7 @@ else if (oldtype instanceof Type)
1801918026

1802018027
reconstructAssociation(pa.e1name,pa.e2name,xs,ys,
1802118028
xe,ye,pa.card1,pa.card2,
18022-
pa.role2, pa.role1, pa.stereotypes, new Vector());
18029+
pa.role2, pa.role1, pa.stereotypes, new Vector(), pa.initialExpression);
1802318030
}
1802418031
}
1802518032
}

UmlTool.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ public UmlTool()
363363
"Creates UML/OCL from AST produced by Antlr Python parser, in output/ast.txt");
364364
fileMenu.add(fromPython);
365365

366+
JMenuItem fromPascal =
367+
new JMenuItem("From Pascal AST",openIcon);
368+
fromPascal.addActionListener(this);
369+
fromPascal.setToolTipText(
370+
"Creates UML/OCL from AST produced by Antlr pascal parser, in output/ast.txt");
371+
fileMenu.add(fromPascal);
372+
366373
JMenuItem fromSQL =
367374
new JMenuItem("From SQL AST",openIcon);
368375
fromSQL.addActionListener(this);
@@ -1773,6 +1780,10 @@ else if (label.equals("From Python AST"))
17731780
{ ucdArea.loadFromPython();
17741781
saved = true;
17751782
}
1783+
else if (label.equals("From Pascal AST"))
1784+
{ ucdArea.loadFromPascal();
1785+
saved = true;
1786+
}
17761787
else if (label.equals("From SQL AST"))
17771788
{ ucdArea.loadFromSQL();
17781789
saved = true;

0 commit comments

Comments
 (0)