Skip to content

Commit 43cb1d1

Browse files
committed
DataType Bugfix
- Free variables of arguments where not added to the set of free variables when used in a data type constructor - Applied IntelliJ source fixes
1 parent 8a2fbf6 commit 43cb1d1

File tree

4 files changed

+56
-56
lines changed

4 files changed

+56
-56
lines changed

use-core/src/main/java/org/tzi/use/parser/ocl/ASTExpression.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String getStringRep() {
7070
}
7171

7272
public void setStringRep(String stringRep) {
73-
fStringRep = stringRep.trim().replaceAll(" ", " ");
73+
fStringRep = stringRep.trim().replaceAll(" {2}", " ");
7474
}
7575

7676
public void setIsPre() {
@@ -93,7 +93,7 @@ public Token getStartToken() {
9393
public abstract Expression gen(Context ctx) throws SemanticException;
9494

9595
/**
96-
* Used by template method {@link getFreeVariables()} to create
96+
* Used by template method {@link #getFreeVariables()} to create
9797
* a set of all free variables of an expression by asking its
9898
* sub-expressions.
9999
* <p>Implementors need to add all free variables to the provided set <code>freeVars</code>.</p>
@@ -107,7 +107,7 @@ public Token getStartToken() {
107107
* @return A <code>Set</code> of all free variables.
108108
*/
109109
public Set<String> getFreeVariables() {
110-
Set<String> result = new HashSet<String>();
110+
Set<String> result = new HashSet<>();
111111
getFreeVariables(result);
112112
return result;
113113
}
@@ -122,7 +122,7 @@ protected Expression genStdOperation(Context ctx,
122122
Expression[] args)
123123
throws SemanticException
124124
{
125-
Expression res = null;
125+
Expression res;
126126
try {
127127
// lookup operation
128128
res = ExpStdOp.create(opname, args);
@@ -166,7 +166,7 @@ protected Expression genNavigation( Token rolenameToken,
166166
Expression srcExpr,
167167
MNavigableElement dst )
168168
throws SemanticException {
169-
return genNavigation( null, rolenameToken, srcClass, srcExpr, dst, Collections.<ASTExpression>emptyList(), Collections.<ASTExpression>emptyList() );
169+
return genNavigation( null, rolenameToken, srcClass, srcExpr, dst, Collections.emptyList(), Collections.emptyList() );
170170
}
171171

172172
protected Expression genNavigation(Context ctx, Token rolenameToken,
@@ -177,17 +177,17 @@ protected Expression genNavigation(Context ctx, Token rolenameToken,
177177
List<ASTExpression> qualifiers )
178178
throws SemanticException
179179
{
180-
Expression res = null;
180+
Expression res;
181181

182182
// find source end
183-
MNavigableElement src = null;
183+
MNavigableElement src;
184184

185185
if (srcClass.equals(dst.association())) {
186186
return new ExpNavigationClassifierSource(dst.cls(), srcExpr, dst);
187187
}
188188

189189
if (navigationNeedsExplicitRolename(srcClass, dst)) {
190-
if (explicitRolenameOrQualifiers.size() == 0) {
190+
if (explicitRolenameOrQualifiers.isEmpty()) {
191191
// an explicit rolename is needed, but not provided
192192
throw new SemanticException(
193193
rolenameToken,
@@ -211,16 +211,15 @@ protected Expression genNavigation(Context ctx, Token rolenameToken,
211211
+ " was given. May be you interchanged it with qualifier values?");
212212
}
213213

214-
ASTExpression explicitRolenameExp = explicitRolenameOrQualifiers.get(0);
214+
ASTExpression explicitRolenameExp = explicitRolenameOrQualifiers.getFirst();
215215

216-
if (!(explicitRolenameExp instanceof ASTOperationExpression)) {
216+
if (!(explicitRolenameExp instanceof ASTOperationExpression explicitRolenameOpExp)) {
217217
// Must be a OperationExpression which encapsulates an IDENT
218218
throw new SemanticException(rolenameToken,
219219
"Invalid qualification given");
220220
}
221-
222-
ASTOperationExpression explicitRolenameOpExp = (ASTOperationExpression)explicitRolenameExp;
223-
Token explicitRolenameToken = explicitRolenameOpExp.getOpToken();
221+
222+
Token explicitRolenameToken = explicitRolenameOpExp.getOpToken();
224223

225224
src = dst.association().getSourceEnd(srcClass, dst, explicitRolenameToken.getText());
226225

@@ -250,7 +249,7 @@ protected Expression genNavigation(Context ctx, Token rolenameToken,
250249
if (qualifiers.isEmpty()) {
251250
qualifierExpressions = Collections.emptyList();
252251
} else {
253-
qualifierExpressions = new ArrayList<Expression>();
252+
qualifierExpressions = new ArrayList<>();
254253
for (ASTExpression qualifierExp : qualifiers) {
255254
qualifierExpressions.add(qualifierExp.gen(ctx));
256255
}
@@ -269,11 +268,11 @@ protected Expression genNavigation(Context ctx, Token rolenameToken,
269268
}
270269

271270
/**
272-
* True if a navigation from an object of class <code>srcClass</code> to
273-
* the association end <code>dst</code> needs an explicit rolename.
271+
* <p>True if a navigation from an object of class <code>srcClass</code> to
272+
* the association end <code>dst</code> needs an explicit rolename.</p>
274273
*
275-
* Only reflexive associations with more then two reachable ends
276-
* can have an ambiguous path.
274+
* <p>Only reflexive associations with more then two reachable ends
275+
* can have an ambiguous path.</p>
277276
* @param srcClass The <code>MClass</code> to navigate from
278277
* @param dst The <code>MNavigableElement</code> to navigate to.
279278
* @return <code>true</code> if the navigation needs a rolename, otherwise <code>false</code>.
@@ -304,7 +303,7 @@ protected boolean navigationNeedsExplicitRolename(MClassifier srcClass, MNavigab
304303
* @param srcExpr the source collection
305304
* @param expr the argument expression for collect
306305
* @param elemType type of elements of the source collection
307-
* @throws SemanticException
306+
* @throws SemanticException If the internal used instance of <code>ExpCollect</code> could not be created.
308307
*/
309308
protected Expression genImplicitCollect(Expression srcExpr,
310309
Expression expr,

use-core/src/main/java/org/tzi/use/parser/ocl/ASTOperationExpression.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919

2020
package org.tzi.use.parser.ocl;
2121

22-
import java.util.ArrayList;
23-
import java.util.Collections;
24-
import java.util.Iterator;
25-
import java.util.List;
26-
import java.util.Set;
27-
2822
import org.antlr.runtime.Token;
2923
import org.tzi.use.config.Options;
3024
import org.tzi.use.parser.Context;
@@ -40,10 +34,15 @@
4034
import org.tzi.use.util.StringUtil;
4135
import org.tzi.use.util.collections.CollectionUtil;
4236

37+
import java.util.ArrayList;
38+
import java.util.Collections;
39+
import java.util.List;
40+
import java.util.Set;
41+
4342
/**
44-
* Node of the abstract syntax tree constructed by the parser.
43+
* <p>Node of the abstract syntax tree constructed by the parser.</p>
4544
*
46-
* This AST class generates different expressions, depending
45+
* <p>This AST class generates different expressions, depending
4746
* on the context:
4847
*
4948
* <ol>
@@ -56,13 +55,14 @@
5655
* navigation over associations with multiplicity zero or one (p. 7-13 of OMG UML 1.3)</li>
5756
* <li>variable</li>
5857
* </ol>
58+
* </p>
5959
* @author Mark Richters
6060
* @author Lars Hamann
6161
*/
6262
public class ASTOperationExpression extends ASTExpression {
63-
private Token fOp;
64-
private ASTExpression fSrcExpr;
65-
private List<ASTExpression> fArgs;
63+
private final Token fOp;
64+
private final ASTExpression fSrcExpr;
65+
private final List<ASTExpression> fArgs;
6666
private boolean fHasParentheses;
6767
private boolean fFollowsArrow;
6868
private Expression[] fArgExprs;
@@ -83,7 +83,7 @@ public ASTOperationExpression(Token op,
8383
boolean followsArrow) {
8484
fOp = op;
8585
fSrcExpr = source;
86-
fArgs = new ArrayList<ASTExpression>();
86+
fArgs = new ArrayList<>();
8787
fHasParentheses = false;
8888
fFollowsArrow = followsArrow;
8989
}
@@ -167,7 +167,7 @@ public void addQualifier( ASTExpression qualifier ) {
167167

168168
public Expression gen(Context ctx) throws SemanticException {
169169
Expression res = null;
170-
Expression srcExpr = null;
170+
Expression srcExpr;
171171
String opname = fOp.getText();
172172

173173
if (fSrcExpr != null ) {
@@ -230,7 +230,7 @@ public Expression gen(Context ctx) throws SemanticException {
230230
private Expression gen1(Context ctx, Expression srcExpr)
231231
throws SemanticException
232232
{
233-
Expression res = null;
233+
Expression res;
234234
String opname = fOp.getText();
235235
Type srcType = srcExpr.type();
236236

@@ -283,7 +283,7 @@ else if (srcType.isKindOfTupleType(VoidHandling.EXCLUDE_VOID) )
283283

284284
opcase += fFollowsArrow ? ARROW : DOT;
285285
opcase += fHasParentheses ? PARENTHESES : NO_PARENTHESES;
286-
opcase += fExplicitRolenameOrQualifiers.size() > 0 ? EXPLICIT_ROLENAME : NO_EXPLICIT_ROLENAME;
286+
opcase += !fExplicitRolenameOrQualifiers.isEmpty() ? EXPLICIT_ROLENAME : NO_EXPLICIT_ROLENAME;
287287

288288
switch ( opcase ) {
289289
case SRC_SIMPLE_TYPE + DOT + NO_PARENTHESES:
@@ -300,7 +300,7 @@ else if (srcType.isKindOfTupleType(VoidHandling.EXCLUDE_VOID) )
300300
if (fArgExprs[0].type().isTypeOfVoidType()) {
301301
try {
302302
fArgExprs[0] = new ExpBagLiteral(new Expression[0]);
303-
} catch (ExpInvalidException e) { }
303+
} catch (ExpInvalidException ignored) { }
304304
} else {
305305
ctx.reportWarning(fOp, "application of `" + opname +
306306
"' to a single value should be done with `.' " +
@@ -553,7 +553,7 @@ private Expression collectShorthandStdOp(String opname,
553553
Type elemType)
554554
throws SemanticException
555555
{
556-
Expression res = null;
556+
Expression res;
557557
// (1) predefined OCL operation
558558

559559
// find operation on element type
@@ -589,7 +589,7 @@ private Expression collectShorthandStdOp(String opname,
589589

590590
// checks (3) and (1)
591591
private Expression genObjOperation(Context ctx, MClassifier srcClassifier, Expression srcExpr) throws SemanticException {
592-
Expression res = null;
592+
Expression res;
593593

594594
// find operation
595595
String opname = fOp.getText();
@@ -654,12 +654,12 @@ public String toString() {
654654

655655
@Override
656656
public void getFreeVariables(Set<String> freeVars) {
657+
for (ASTExpression fArg : fArgs) {
658+
fArg.getFreeVariables(freeVars);
659+
}
660+
657661
if (fSrcExpr != null) {
658662
fSrcExpr.getFreeVariables(freeVars);
659-
Iterator<ASTExpression> it = fArgs.iterator();
660-
while (it.hasNext()) {
661-
it.next().getFreeVariables(freeVars);
662-
}
663663
} else {
664664
if (!fHasParentheses) {
665665
freeVars.add(fOp.getText());

use-core/src/main/java/org/tzi/use/util/soil/VariableEnvironment.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class VariableEnvironment {
6666
/** reference to the current frame */
6767
private Map<String, Value> fCurrentFrame;
6868
/** the system state this variable environment is defined for. */
69-
private MSystemState fSystemState;
69+
private final MSystemState fSystemState;
7070

7171

7272
/**
@@ -88,21 +88,22 @@ public VariableEnvironment(MSystemState systemState) {
8888
*/
8989
public VariableEnvironment(VariableEnvironment other) {
9090
fSystemState = other.fSystemState;
91-
fFrames = new ArrayDeque<Map<String, Value>>();
91+
fFrames = new ArrayDeque<>();
92+
9293
for (Map<String,Value> b : other.fFrames) {
93-
Map<String, Value> b1 = new HashMap<String,Value>();
94-
b1.putAll(b);
94+
Map<String, Value> b1 = new HashMap<>(b);
9595
fFrames.add(b1);
9696
}
97+
9798
fCurrentFrame = fFrames.peek();
98-
fObjectVisibility = new ArrayDeque<Boolean>(other.fObjectVisibility);
99+
fObjectVisibility = new ArrayDeque<>(other.fObjectVisibility);
99100
}
100101

101102
public VariableEnvironment(VariableEnvironment other, MSystemState systemState) {
102103
fSystemState = systemState;
103-
fFrames = new ArrayDeque<Map<String, Value>>(other.fFrames);
104+
fFrames = new ArrayDeque<>(other.fFrames);
104105
fCurrentFrame = fFrames.peek();
105-
fObjectVisibility = new ArrayDeque<Boolean>(other.fObjectVisibility);
106+
fObjectVisibility = new ArrayDeque<>(other.fObjectVisibility);
106107
}
107108

108109
/**
@@ -111,8 +112,8 @@ public VariableEnvironment(VariableEnvironment other, MSystemState systemState)
111112
*/
112113
public void clear() {
113114

114-
fFrames = new ArrayDeque<Map<String, Value>>();
115-
fObjectVisibility = new ArrayDeque<Boolean>();
115+
fFrames = new ArrayDeque<>();
116+
fObjectVisibility = new ArrayDeque<>();
116117

117118
pushFrame(true);
118119
}
@@ -140,7 +141,7 @@ public boolean isEmpty() {
140141
* @see #popFrame()
141142
*/
142143
public void pushFrame(boolean objectsVisible) {
143-
fFrames.push(new HashMap<String,Value>());
144+
fFrames.push(new HashMap<>());
144145
fCurrentFrame = fFrames.peek();
145146
fObjectVisibility.push(objectsVisible);
146147
}
@@ -284,7 +285,7 @@ public void undefineReferencesTo(MObject object) {
284285
*/
285286
public List<String> getTopLevelReferencesTo(MObject object) {
286287

287-
List<String> result = new ArrayList<String>();
288+
List<String> result = new ArrayList<>();
288289

289290
for (Entry<String, Value> entry : fFrames.peekFirst().entrySet()) {
290291
Value value = entry.getValue();
@@ -366,7 +367,7 @@ public String toString() {
366367

367368
final String COLON = " : ";
368369
final String EQUAL = " = ";
369-
final String NEWLN = System.getProperty("line.separator");
370+
final String NEWLN = System.lineSeparator();
370371
final String FRPRE = "[frame ";
371372
final String FRPST = "]" + NEWLN;
372373
final String EMPTY = "empty" + NEWLN;
@@ -410,8 +411,8 @@ public String toString() {
410411
sb.append("[object variables]");
411412
sb.append(NEWLN);
412413

413-
List<String> objectNames =
414-
new LinkedList<String>(fSystemState.allObjectNames());
414+
List<String> objectNames =
415+
new LinkedList<>(fSystemState.allObjectNames());
415416
Collections.sort(objectNames);
416417

417418
for (String objectName : objectNames) {

use-core/src/main/resources/examples/Documentation/Datatypes/invoice_books.soil

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
!insert (i1,li1_1) into Invoice_LineItem
99
!insert (i1,li1_3) into Invoice_LineItem
1010
!i1.nr := 2001
11-
!i1.date := Date(2024, 1, 15)
11+
!i1.date := Date(15, 1, 2024)
1212
!new Currency('eur')
1313
!new Currency('usd')
1414
!usd.name := 'US Dollar'

0 commit comments

Comments
 (0)