2424
2525package org .omg .sysml .plantuml ;
2626
27+ import java .util .HashSet ;
2728import java .util .List ;
29+ import java .util .Set ;
2830
31+ import org .omg .sysml .lang .sysml .Element ;
2932import org .omg .sysml .lang .sysml .Feature ;
3033import org .omg .sysml .lang .sysml .Membership ;
3134import org .omg .sysml .lang .sysml .Namespace ;
35+ import org .omg .sysml .lang .sysml .Redefinition ;
3236import org .omg .sysml .lang .sysml .Type ;
3337
3438class 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
0 commit comments