|
55 | 55 | import org.omg.sysml.lang.sysml.SysMLPackage; |
56 | 56 | import org.omg.sysml.lang.sysml.Type; |
57 | 57 | import org.omg.sysml.lang.sysml.TypeFeaturing; |
| 58 | +import org.omg.sysml.lang.sysml.impl.FeatureImpl; |
58 | 59 |
|
59 | 60 | public class FeatureUtil { |
60 | 61 |
|
@@ -439,4 +440,62 @@ public static Multiplicity getMultiplicityOf(Type type, Set<Type> visited) { |
439 | 440 | } |
440 | 441 | return multiplicity; |
441 | 442 | } |
| 443 | + |
| 444 | + //Naming |
| 445 | + |
| 446 | + public static String computeEffectiveName(Feature self) { |
| 447 | + return computeEffectiveName(self, new HashSet<>()); |
| 448 | + } |
| 449 | + |
| 450 | + private static String computeEffectiveName(Feature self, Set<Feature> visited) { |
| 451 | + if (isNameSet(self)) { |
| 452 | + return self.getDeclaredName(); |
| 453 | + } |
| 454 | + |
| 455 | + String effectiveName = getFeatureAdapter(self).getEffectiveName(); |
| 456 | + |
| 457 | + if (effectiveName != null) { |
| 458 | + return effectiveName; |
| 459 | + } |
| 460 | + |
| 461 | + visited.add(self); |
| 462 | + FeatureImpl namingFeature = (FeatureImpl) self.namingFeature(); |
| 463 | + |
| 464 | + if (namingFeature != null && !visited.contains(namingFeature)) { |
| 465 | + effectiveName = computeEffectiveName(namingFeature, visited); |
| 466 | + getFeatureAdapter(self).storeEffectiveName(effectiveName); |
| 467 | + } |
| 468 | + |
| 469 | + return effectiveName; |
| 470 | + } |
| 471 | + |
| 472 | + public static String computeEffectiveShortName(Feature self) { |
| 473 | + return computeEffectiveShortName(self, new HashSet<>()); |
| 474 | + } |
| 475 | + |
| 476 | + private static String computeEffectiveShortName(Feature self, Set<Feature> visited) { |
| 477 | + if (isNameSet(self)) { |
| 478 | + return self.getDeclaredShortName(); |
| 479 | + } |
| 480 | + |
| 481 | + String effectiveShortName = getFeatureAdapter(self).getEffectiveShortName(); |
| 482 | + |
| 483 | + if (effectiveShortName != null) { |
| 484 | + return effectiveShortName; |
| 485 | + } |
| 486 | + |
| 487 | + visited.add(self); |
| 488 | + FeatureImpl namingFeature = (FeatureImpl) self.namingFeature(); |
| 489 | + |
| 490 | + if (namingFeature != null && !visited.contains(namingFeature)) { |
| 491 | + effectiveShortName = computeEffectiveShortName(namingFeature, visited); |
| 492 | + getFeatureAdapter(self).storeEffectiveShortName(effectiveShortName); |
| 493 | + } |
| 494 | + |
| 495 | + return effectiveShortName; |
| 496 | + } |
| 497 | + |
| 498 | + private static boolean isNameSet(Feature self) { |
| 499 | + return self.getDeclaredName() != null || self.getDeclaredShortName() != null; |
| 500 | + } |
442 | 501 | } |
0 commit comments