Skip to content

Commit 44b8e67

Browse files
authored
Merge pull request #538 from Systems-Modeling/ST6RI-745
ST6RI-745 Inherited references are not properly rendered (PlantUML)
2 parents fc56a41 + b849868 commit 44b8e67

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ private InheritKey(Type tail) {
140140
this.isDirect = false;
141141
}
142142

143+
private InheritKey(InheritKey base, boolean isDirect) {
144+
this.keys = base.keys;
145+
this.isDirect = isDirect;
146+
}
147+
148+
// Create an indirect InheritKey so that redefined elements can be referred by
149+
// inherited connectors
150+
public static InheritKey makeIndirect(InheritKey ik) {
151+
if (ik == null) return null;
152+
return new InheritKey(ik, false);
153+
}
154+
143155
@Override
144156
public String toString() {
145157
StringBuilder sb = new StringBuilder();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public PRelation(InheritKey ik, Element src, Element dest, Element rel, String d
115115
}
116116

117117
public PRelation(InheritKey ik, Object src, Object dest, Element rel, String description) {
118-
this.ik = null;
118+
this.ik = ik;
119119
this.src = src;
120120
this.dest = dest;
121121
this.rel = rel;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ private Integer lookupId(Element e) {
515515

516516
Integer newId(Element e) {
517517
Integer ii = idCounter++;
518-
idMap.put(e, ii);
518+
if (!isInherited()) {
519+
idMap.put(e, ii);
520+
}
519521
if (vpath != null) {
520522
vpath.setId(e, ii);
521523
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.omg.sysml.lang.sysml.MetadataFeature;
5353
import org.omg.sysml.lang.sysml.Namespace;
5454
import org.omg.sysml.lang.sysml.OwningMembership;
55+
import org.omg.sysml.lang.sysml.Redefinition;
5556
import org.omg.sysml.lang.sysml.Relationship;
5657
import org.omg.sysml.lang.sysml.Specialization;
5758
import org.omg.sysml.lang.sysml.Subsetting;
@@ -119,8 +120,18 @@ protected void addSpecializations(int typId, Type typ) {
119120
for (Specialization s: typ.getOwnedSpecialization()) {
120121
Type gt = s.getGeneral();
121122
if (gt == null) continue;
122-
if (ik != null && typ instanceof Feature) {
123-
ik = makeInheritKey((Feature) typ);
123+
if (ik == null && gt instanceof Feature) {
124+
if (s instanceof Redefinition) {
125+
// If we just create an inherit key for redefinition target, always create a cyclic reference
126+
// because redefining feature can be a target in this sense. So we must create an inherit key
127+
// for the membership owning the target since the redefined target always exists.
128+
Membership ms = gt.getOwningMembership();
129+
if (ms != null) {
130+
ik = makeInheritKey(ms);
131+
}
132+
} else {
133+
ik = makeInheritKey((Feature) gt);
134+
}
124135
}
125136
PRelation pr = new PRelation(ik, typId, gt, s, null);
126137
addPRelation(pr);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private RefPC createRefPC(InheritKey ik, PC pc) {
474474

475475
private String addContextForFeature(Feature f) {
476476
PC pc = makeFeaturePC(f, f);
477-
InheritKey ik = makeInheritKeyOfOwner(f);
477+
InheritKey ik = makeInheritKey(f);
478478
if (createRefPC(ik, pc) == null) return null;
479479
return "";
480480
}
@@ -485,7 +485,8 @@ private String addContextForEnd(Feature f) {
485485
}
486486
PC pc = makeEndFeaturePC(f);
487487
InheritKey ik = makeInheritKeyOfOwner(f);
488-
if (createRefPC(ik, pc) == null) return null;
488+
// Make the inherit key indirect in order to refer to redefined targets as well as inherited ones.
489+
if (createRefPC(InheritKey.makeIndirect(ik), pc) == null) return null;
489490
return "";
490491
}
491492

@@ -502,7 +503,8 @@ private String addContextForItemFlowEnd(ItemFlowEnd ife) {
502503
Feature ioTarget = getIOTarget(ife);
503504
pc = new PCItemFlowEnd(ife, pc, ioTarget);
504505
InheritKey ik = makeInheritKeyOfOwner(ife);
505-
if (createRefPC(ik, pc) == null) return null;
506+
// Make the inherit key indirect in order to refer to redefined targets as well as inherited ones.
507+
if (createRefPC(InheritKey.makeIndirect(ik), pc) == null) return null;
506508
return "";
507509
}
508510

@@ -588,10 +590,10 @@ public String caseType(Type typ) {
588590
Type g = sp.getGeneral();
589591
// Type s = sp.getSpecific();
590592
if (g == null) continue;
591-
if (checkVisited(g)) continue;
592593
if (g instanceof Feature) {
593594
addContextForFeature((Feature) g);
594595
}
596+
if (checkVisited(g)) continue;
595597
visit(g);
596598
traverse(g);
597599
// visit(s); // Typically this will cause double traverse but checkVisit() stops it..

0 commit comments

Comments
 (0)