Skip to content

Commit 1525f8c

Browse files
authored
Add files via upload
1 parent 1efde04 commit 1525f8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+15799
-0
lines changed

Identifier.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/******************************
2+
* Copyright (c) 2003,2019 Kevin Lano
3+
* This program and the accompanying materials are made available under the
4+
* terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
* *****************************/
9+
/* Package: Utilities */
10+
11+
public class Identifier
12+
{ private static int count = 0;
13+
14+
public static String nextIdentifier(String pfx)
15+
{ String res = pfx + count;
16+
count++;
17+
return res;
18+
}
19+
}
20+

InPattern.java

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import java.util.Vector;
2+
3+
/******************************
4+
* Copyright (c) 2003,2019 Kevin Lano
5+
* This program and the accompanying materials are made available under the
6+
* terms of the Eclipse Public License 2.0 which is available at
7+
* http://www.eclipse.org/legal/epl-2.0
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
* *****************************/
11+
/* Package: ATL */
12+
13+
public class InPattern
14+
{ Vector elements; // of InPatternElement
15+
16+
public InPattern()
17+
{ elements = new Vector(); }
18+
19+
public void setElements(Vector elems)
20+
{ elements = elems; }
21+
22+
public void addElement(InPatternElement ipe)
23+
{ elements.add(ipe); }
24+
25+
public int size()
26+
{ return elements.size(); }
27+
28+
public String toString()
29+
{ String res = "from ";
30+
for (int i = 0; i < elements.size(); i++)
31+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
32+
res = res + " " + ipe;
33+
if (i < elements.size() - 1)
34+
{ res = res + ",\n"; }
35+
}
36+
return res;
37+
}
38+
39+
public String firstType() // Will become the owner of the constraint of the rule
40+
{ if (elements.size() > 0)
41+
{ InPatternElement ipe = (InPatternElement) elements.get(0);
42+
return ipe.getType();
43+
}
44+
return null;
45+
}
46+
47+
public Entity firstEntity()
48+
{ if (elements.size() > 0)
49+
{ InPatternElement ipe = (InPatternElement) elements.get(0);
50+
Type typ = ipe.variable.getType();
51+
if (typ.isEntity())
52+
{ return typ.getEntity(); }
53+
}
54+
return null;
55+
}
56+
57+
public boolean hasType(String typ)
58+
{ // typ occurs as a type of the pattern, or superclass of such a type
59+
60+
for (int i = 0; i < elements.size(); i++)
61+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
62+
if (typ.equals(ipe.variable.getType() + ""))
63+
{ return true; }
64+
}
65+
return false;
66+
}
67+
68+
public Expression toExpression(UseCase uc)
69+
{ // pre: elements.size() > 0
70+
if (elements.size() == 0)
71+
{ return new BasicExpression(true); }
72+
73+
InPatternElement ipe0 = (InPatternElement) elements.get(0);
74+
Expression res = ipe0.condition;
75+
for (int i = 1; i < elements.size(); i++)
76+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
77+
res = Expression.simplify("&",res,ipe.getFullCondition(uc),null);
78+
}
79+
return res;
80+
}
81+
82+
public Vector allVariables()
83+
{ Vector res = new Vector();
84+
for (int i = 0; i < elements.size(); i++)
85+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
86+
if (ipe.variable != null)
87+
{ res.add(ipe.variable); }
88+
}
89+
return res;
90+
}
91+
92+
public int complexity()
93+
{ int result = 0;
94+
for (int i = 0; i < elements.size(); i++)
95+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
96+
result = result + ipe.complexity();
97+
}
98+
return result;
99+
}
100+
101+
public int cyclomaticComplexity()
102+
{ int result = 0;
103+
for (int i = 0; i < elements.size(); i++)
104+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
105+
result = result + ipe.cyclomaticComplexity();
106+
}
107+
return result;
108+
}
109+
110+
public Vector operationsUsedIn()
111+
{ Vector res = new Vector();
112+
for (int i = 0; i < elements.size(); i++)
113+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
114+
if (ipe.condition != null)
115+
{ res.addAll(ipe.condition.allOperationsUsedIn()); }
116+
}
117+
return res;
118+
}
119+
120+
public Vector getUses(String data)
121+
{ Vector res = new Vector();
122+
for (int i = 0; i < elements.size(); i++)
123+
{ InPatternElement ipe = (InPatternElement) elements.get(i);
124+
if (ipe.condition != null)
125+
{ res.addAll(ipe.condition.getUses(data)); }
126+
}
127+
return res;
128+
}
129+
130+
}

InPatternElement.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import java.util.Vector;
2+
3+
/******************************
4+
* Copyright (c) 2003,2019 Kevin Lano
5+
* This program and the accompanying materials are made available under the
6+
* terms of the Eclipse Public License 2.0 which is available at
7+
* http://www.eclipse.org/legal/epl-2.0
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
* *****************************/
11+
/* Package: ATL */
12+
13+
14+
public class InPatternElement
15+
{ Attribute variable;
16+
Expression condition;
17+
18+
public InPatternElement(Attribute att, Expression exp)
19+
{ variable = att;
20+
condition = exp;
21+
}
22+
23+
public String toString()
24+
{ String res = variable.getName() + " : MM1!" + variable.getType();
25+
if (condition == null || "true".equals(condition + ""))
26+
{ return res; }
27+
return res + " ( " + condition + " )";
28+
}
29+
30+
public void setCondition(Expression cond)
31+
{ condition = cond; }
32+
33+
public Expression getFullCondition(UseCase uc)
34+
{ BasicExpression be = new BasicExpression(variable.getName());
35+
be.setType(variable.getType());
36+
BasicExpression betype = new BasicExpression(variable.getType() + "");
37+
Expression res = new BinaryExpression(":", be, betype);
38+
Expression newcond = condition.replaceModuleReferences(uc);
39+
return Expression.simplify("&", res, newcond, null);
40+
} // need to convert the condition to remove "thisModule"
41+
42+
public String getType()
43+
{ return variable.getType() + ""; }
44+
45+
public int complexity()
46+
{ int result = 2 + variable.getType().complexity();
47+
if (condition != null)
48+
{ result = result + condition.syntacticComplexity(); }
49+
return result;
50+
}
51+
52+
public int cyclomaticComplexity()
53+
{ int result = 0;
54+
if (condition != null)
55+
{ result = result + condition.cyclomaticComplexity(); }
56+
return result;
57+
}
58+
}

Include.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
/* package: UseCase */
5+
/******************************
6+
* Copyright (c) 2003,2019 Kevin Lano
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
* *****************************/
13+
14+
public class Include extends ModelElement
15+
{ UseCase includingCase;
16+
UseCase addition;
17+
18+
public Include(UseCase base, UseCase subusecase)
19+
{ super("");
20+
includingCase = base;
21+
addition = subusecase;
22+
}
23+
24+
public UseCase getInclusion()
25+
{ return addition; }
26+
27+
public static String displayInclusions(List incls)
28+
{ String res = "";
29+
for (int i = 0; i < incls.size(); i++)
30+
{ Include ex = (Include) incls.get(i);
31+
res = res + ex.includingCase.getName() + " --includes--> " +
32+
ex.addition.getName() + "\n";
33+
}
34+
return res;
35+
}
36+
37+
public UseCase insertIntoBase()
38+
{ UseCase result = includingCase; // (UseCase) includingCase.clone();
39+
Vector extcons = addition.getPostconditions();
40+
Vector extstats = addition.getCode().getStatements();
41+
42+
for (int i = 0; i < extcons.size(); i++)
43+
{ Constraint extpost = (Constraint) extcons.get(i);
44+
result.addPostcondition(extpost);
45+
result.addStatement((Statement) extstats.get(i));
46+
}
47+
// result.setName(includingCase.getName());
48+
return result;
49+
}
50+
// also add extension preconditions to result preconditions
51+
52+
public static UseCase insertIntoBase(UseCase uc, UseCase inc)
53+
{ Vector extcons = inc.getPostconditions();
54+
Vector extstats = inc.getCode().getStatements();
55+
56+
for (int i = 0; i < extcons.size(); i++)
57+
{ Constraint extpost = (Constraint) extcons.get(i);
58+
uc.addPostcondition(extpost);
59+
uc.addStatement((Statement) extstats.get(i));
60+
}
61+
// result.setName(includingCase.getName());
62+
return uc;
63+
}
64+
65+
public void generateJava(java.io.PrintWriter out) { }
66+
}

0 commit comments

Comments
 (0)