-
Notifications
You must be signed in to change notification settings - Fork 8
/
Binding.java
96 lines (76 loc) · 3.01 KB
/
Binding.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Vector;
/******************************
* Copyright (c) 2003,2020 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
/* Package: ATL */
public class Binding
{ String propertyName;
Expression expression;
Expression oclExpression = null;
public Binding(String att, Expression exp)
{ propertyName = att;
expression = exp;
}
public String getPropertyName()
{ return propertyName; }
public String toString()
{ return propertyName + " <- " + expression; }
public Statement toStatement()
{ return new AssignStatement(propertyName,expression); }
public Expression toExpression(String nme, Type typ, Vector types, Vector ents, Vector env,
java.util.Map interp, UseCase uc)
{ // nme.propertyName = expression, with conversions of thisModule
Type propType = null; // Target type of the output variable being instantiated.
Type propElemType = null;
BasicExpression lhs = new BasicExpression(propertyName);
lhs.objectRef = new BasicExpression(nme);
Vector contexts = new Vector();
expression.typeCheck(types,ents,contexts,env);
if (typ.isEntity())
{ Entity e = typ.getEntity();
propType = e.getDefinedFeatureType(propertyName);
propElemType = e.getDefinedFeatureElementType(propertyName);
// System.out.println("DEFINED FEATURE TYPE OF " + propertyName + " IS " + propType + "(" +
// propElemType + ")");
}
Expression replacedModule = expression.replaceModuleReferences(uc);
oclExpression = replacedModule.checkConversions(propType,propElemType,interp);
ModelElement met = ModelElement.lookupByName(nme, env);
if (met != null)
{ oclExpression = oclExpression.addPreForms(nme); }
return new BinaryExpression("=",lhs,oclExpression);
}
public Vector sourceTypesRead()
{ Vector res = new Vector();
if (oclExpression != null)
{ res = oclExpression.allReadFrame(); }
System.out.println("Read frame of " + oclExpression + " is " + res);
return res;
}
public boolean isAssociationUpdate(Entity ent)
{ if (ent.hasRole(propertyName))
{ return true; }
return false;
}
public int complexity()
{ int result = 2 + expression.syntacticComplexity();
return result;
}
public int cyclomaticComplexity()
{ int result = expression.cyclomaticComplexity();
return result;
}
public Vector operationsUsedIn()
{ return expression.allOperationsUsedIn(); }
public Vector getUses(String data)
{ return expression.getUses(data); }
public Binding substitute(String v, Expression expr)
{ Expression newexpr = expression.substituteEq(v,expr);
return new Binding(propertyName,newexpr);
}
}