Skip to content

Commit 9e64389

Browse files
committed
* InheritKey (containsWithRedefined, matchRedefined, matchElement): Added.
(match): Use matchElement() instead of equals() to match features. * VPath.PC (match): Ditto.
1 parent 8e58963 commit 9e64389

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

org.omg.sysml.plantuml/src/org/omg/sysml/plantuml/InheritKey.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,34 @@
2424

2525
package org.omg.sysml.plantuml;
2626

27+
import java.util.HashSet;
2728
import java.util.List;
29+
import java.util.Set;
2830

31+
import org.omg.sysml.lang.sysml.Element;
2932
import org.omg.sysml.lang.sysml.Feature;
3033
import org.omg.sysml.lang.sysml.Membership;
3134
import org.omg.sysml.lang.sysml.Namespace;
35+
import org.omg.sysml.lang.sysml.Redefinition;
3236
import org.omg.sysml.lang.sysml.Type;
3337

3438
class InheritKey {
3539
public final Type[] keys;
3640
private final boolean isDirect;
3741

42+
private static boolean containsWithRedefined(List<Feature> fs, Feature ft) {
43+
for (Feature f : fs) {
44+
if (f.equals(ft)) return true;
45+
if (matchRedefined(f, ft)) return true;
46+
}
47+
return false;
48+
}
49+
3850
private static boolean isBelonging(Type typ, Feature f) {
39-
if (typ.getOwnedFeature().contains(f)) return true;
40-
if (typ.getInheritedFeature().contains(f)) return true;
51+
if (containsWithRedefined(typ.getOwnedFeature(), f)) return true;
52+
// if (typ.getOwnedFeature().contains(f)) return true;
53+
if (containsWithRedefined(typ.getInheritedFeature(), f)) return true;
54+
// if (typ.getInheritedFeature().contains(f)) return true;
4155
return false;
4256
}
4357

@@ -164,6 +178,29 @@ public static InheritKey construct(List<Namespace> ctx, List<Integer> inheritIdi
164178
return constructInternal(ctx, inheritIdices, idx);
165179
}
166180

181+
private static boolean matchRedefined(Feature f, Feature ft, Set<Feature> visited) {
182+
if (visited.contains(f)) return false;
183+
visited.add(f);
184+
for (Redefinition rd: f.getOwnedRedefinition()) {
185+
Feature rf = rd.getRedefinedFeature();
186+
if (ft.equals(rf)) return true;
187+
return matchRedefined(rf, ft, visited);
188+
}
189+
return false;
190+
}
191+
192+
private static boolean matchRedefined(Feature f, Feature ft) {
193+
return matchRedefined(f, ft, new HashSet<Feature>());
194+
}
195+
196+
public static boolean matchElement(Element e, Element et) {
197+
if (e.equals(et)) return true;
198+
if ((e instanceof Feature) && (et instanceof Feature)) {
199+
return matchRedefined((Feature) e, (Feature) et);
200+
}
201+
return false;
202+
}
203+
167204
public static boolean match(InheritKey ik, List<Namespace> ctx, List<Integer> inheritIdices) {
168205
if (ik == null) {
169206
return inheritIdices.isEmpty();
@@ -179,11 +216,11 @@ public static boolean match(InheritKey ik, List<Namespace> ctx, List<Integer> in
179216
for (int i = 0; i < iSize; i++) {
180217
int idx = inheritIdices.get(i);
181218
Namespace ns = ctx.get(idx);
182-
if (!ik.keys[i].equals(ns)) return false;
219+
if (!matchElement(ns, ik.keys[i])) return false;
183220
}
184221
if (diff == 0) return true;
185222
// In the case that ik is in the form of [..., ^ow]
186-
return ik.keys[kLen - 1].equals(ctx.get(ctxSize - 1));
223+
return matchElement(ctx.get(ctxSize - 1), ik.keys[kLen - 1]);
187224
}
188225
}
189226

org.omg.sysml.plantuml/src/org/omg/sysml/plantuml/VPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void setId(InheritKey ik, Element e, Integer id) {
112112
private boolean match(Element e) {
113113
if (isTerminal()) return false;
114114
Element et = getTarget();
115-
return e.equals(et);
115+
return InheritKey.matchElement(e, et);
116116
}
117117

118118
public Element requiredElement() {

0 commit comments

Comments
 (0)