Skip to content

Commit fbb3f98

Browse files
authored
Merge pull request #570 from Systems-Modeling/ST6RI-752
ST6RI-752 Reimplement Xtext workarounds using Xtext parse postprocessing
2 parents c2f26cd + 0d27360 commit fbb3f98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1283
-703
lines changed

kerml/src/examples/Simple Tests/Dependencies.kerml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package Dependencies {
88

99
import System::*;
1010

11-
// dependency Use from 'Application Layer' to 'Service Layer';
12-
// dependency from 'Service Layer' to 'Data Layer';
11+
dependency Use from 'Application Layer' to 'Service Layer';
12+
dependency from 'Service Layer' to 'Data Layer';
1313

1414
feature x;
1515
feature y;
Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2020-2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2020-2021, 2024 Model Driven Solutions, Inc.
4+
* Copyright (c) 2024 Budapest University of Technology and Economics
45
*
56
* This program is free software: you can redistribute it and/or modify
67
* it under the terms of the GNU Lesser General Public License as published by
@@ -20,23 +21,32 @@
2021
* Contributors:
2122
* Zoltan Ujhelyi, MDS
2223
* Ed Seidewitz, MDS
24+
* Kristóf Marussy, BME
2325
*
2426
*****************************************************************************/
2527
package org.omg.kerml.xtext.scoping;
2628

2729
import java.util.Objects;
2830

31+
import org.eclipse.emf.common.util.TreeIterator;
2932
import org.eclipse.emf.ecore.EObject;
3033
import org.eclipse.emf.ecore.EReference;
34+
import org.eclipse.emf.ecore.resource.Resource;
35+
import org.eclipse.xtext.diagnostics.IDiagnosticConsumer;
3136
import org.eclipse.xtext.linking.lazy.LazyLinker;
32-
import org.omg.sysml.lang.sysml.Comment;
33-
import org.omg.sysml.lang.sysml.Documentation;
34-
import org.omg.sysml.lang.sysml.SysMLPackage;
37+
import org.eclipse.xtext.util.OnChangeEvictingCache;
38+
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
3539
import org.omg.sysml.lang.sysml.Element;
40+
import org.omg.sysml.lang.sysml.SysMLPackage;
3641
import org.omg.sysml.util.ElementUtil;
3742

43+
import com.google.inject.Inject;
44+
3845
public class KerMLLinker extends LazyLinker {
3946

47+
@Inject
48+
private OnChangeEvictingCache cache;
49+
4050
@Override
4151
protected void clearReferences(EObject obj) {
4252
super.clearReferences(obj);
@@ -50,30 +60,33 @@ protected void clearReference(EObject obj, EReference ref) {
5060
if (
5161
// The Relationship#source and #target features are overridden
5262
// in each subtype to provide specific derived implementations that
53-
// are regenerated each time they are accessed so there is no need to
54-
// delete them; and as of May 2020, generic references are not supported
55-
// in concrete syntax, making it a safe to not clear them during linking.
63+
// are recomputed when accessed so they should not be cleared.
5664
Objects.equals(ref, SysMLPackage.Literals.RELATIONSHIP__SOURCE) ||
57-
Objects.equals(ref, SysMLPackage.Literals.RELATIONSHIP__TARGET) ||
58-
59-
// The Relationship#relatedElement feature is a derived union in the
60-
// abstract syntax model, but it is implemented as a manual derivation,
61-
// which is overridden as necessary in subtypes, so there is no need to
62-
// delete it.
63-
Objects.equals(ref, SysMLPackage.Literals.RELATIONSHIP__RELATED_ELEMENT) ||
64-
65-
// The Annotation#annotatingElement feature, which is not composite, is
66-
// redefined by Documentation#documentingComment, which is composite.
67-
// Clearing annotedElement spuriously clears the documentedElement, which
68-
// then does not get a proxy because it is composite (containment).
69-
// Annotation#annotatingElement has the opposite feature
70-
// AnnotatingElement#Annotation, which also should not be cleared.
71-
obj instanceof Documentation && Objects.equals(ref, SysMLPackage.Literals.ANNOTATION__ANNOTATING_ELEMENT) ||
72-
obj instanceof Comment && obj.eContainer() instanceof Documentation &&
73-
Objects.equals(ref, SysMLPackage.Literals.ANNOTATING_ELEMENT__ANNOTATION)
65+
Objects.equals(ref, SysMLPackage.Literals.RELATIONSHIP__TARGET)
7466
) {
7567
return;
7668
}
7769
super.clearReference(obj, ref);
7870
}
71+
72+
@Override
73+
protected void doLinkModel(EObject model, IDiagnosticConsumer consumer) {
74+
super.doLinkModel(model, consumer);
75+
postProcessAllCrossReferences(model);
76+
}
77+
78+
protected void postProcessAllCrossReferences(EObject model) {
79+
cache.execWithoutCacheClear(model.eResource(), new IUnitOfWork.Void<Resource>() {
80+
@Override
81+
public void process(Resource state) throws Exception {
82+
TreeIterator<EObject> iterator = getAllLinkableContents(model);
83+
while (iterator.hasNext()) {
84+
EObject obj = iterator.next();
85+
if (obj instanceof Element) {
86+
ElementUtil.postProcess((Element)obj);
87+
}
88+
}
89+
}
90+
});
91+
}
7992
}

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/ExpressionEvaluator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ protected InvocationExpression instantiateInvocation(InvocationExpression expres
8181
for (FeatureTyping typing: expression.getOwnedTyping()) {
8282
FeatureTyping newTyping = SysMLFactory.eINSTANCE.createFeatureTyping();
8383
newTyping.setType(typing.getType());
84+
newTyping.setTypedFeature(instantiation);
8485
instantiation.getOwnedRelationship().add(newTyping);
8586
}
8687

@@ -99,6 +100,7 @@ protected InvocationExpression instantiateInvocation(InvocationExpression expres
99100
for (Feature redefinedFeature: FeatureUtil.getRedefinedFeaturesWithComputedOf(parameter, null)) {
100101
Redefinition newRedefinition = SysMLFactory.eINSTANCE.createRedefinition();
101102
newRedefinition.setRedefinedFeature(redefinedFeature);
103+
newRedefinition.setRedefiningFeature(newParameter);
102104
newParameter.getOwnedRelationship().add(newRedefinition);
103105
}
104106

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
* Copyright (c) 2024 Budapest University of Technology and Economics
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of theGNU Lesser General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*
19+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
20+
*
21+
*******************************************************************************/
22+
23+
package org.omg.sysml.adapter;
24+
25+
import org.omg.sysml.lang.sysml.AnnotatingElement;
26+
import org.omg.sysml.lang.sysml.Annotation;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.SysMLPackage;
29+
30+
public class AnnotationAdapter extends RelationshipAdapter {
31+
32+
public AnnotationAdapter(Annotation element) {
33+
super(element);
34+
}
35+
36+
@Override
37+
public Annotation getTarget() {
38+
return (Annotation)super.getTarget();
39+
}
40+
41+
@Override
42+
public void postProcess() {
43+
Annotation obj = getTarget();
44+
45+
// If the Annotation is not owned by an AnnotatingElement, then the annotatedElement is the owningRelatedElement.
46+
Object annotatedElement = obj.eGet(SysMLPackage.Literals.ANNOTATION__ANNOTATED_ELEMENT, false);
47+
if (annotatedElement == null) {
48+
Element owningRelatedElement = obj.getOwningRelatedElement();
49+
if (!(owningRelatedElement instanceof AnnotatingElement)) {
50+
obj.setAnnotatedElement(owningRelatedElement);
51+
}
52+
}
53+
54+
// If there is no annotatingElement set, then set the AnnotatingElement to the owningRelatedElement,
55+
// if it is an AnnotatingElement, otherwise set it to the first ownedRelatedElement that is an
56+
// AnnotatingElement (if any).
57+
Object annotatingElement = obj.eGet(SysMLPackage.Literals.ANNOTATION__ANNOTATING_ELEMENT, false);
58+
if (annotatingElement == null) {
59+
Element owner = obj.getOwningRelatedElement();
60+
obj.setAnnotatingElement((AnnotatingElement)
61+
(owner instanceof AnnotatingElement? owner:
62+
obj.getOwnedRelatedElement().stream().
63+
filter(AnnotatingElement.class::isInstance).
64+
findFirst().orElse(null)));
65+
}
66+
}
67+
68+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
* Copyright (c) 2024 Budapest University of Technology and Economics
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of theGNU Lesser General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*
19+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
20+
*
21+
*******************************************************************************/
22+
23+
package org.omg.sysml.adapter;
24+
25+
import org.eclipse.emf.common.util.EList;
26+
import org.omg.sysml.lang.sysml.Conjugation;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.SysMLPackage;
29+
import org.omg.sysml.lang.sysml.Type;
30+
31+
public class ConjugationAdapter extends RelationshipAdapter {
32+
33+
public ConjugationAdapter(Conjugation element) {
34+
super(element);
35+
}
36+
37+
@Override
38+
public Conjugation getTarget() {
39+
return (Conjugation)super.getTarget();
40+
}
41+
42+
@Override
43+
public void postProcess() {
44+
Conjugation obj = getTarget();
45+
46+
// If the conjugatedType is not set, then set it to the owningRelatedElement, if this is a Type,
47+
// otherwise set it to the first ownedRelatedElement.
48+
Object conjugatedType = obj.eGet(SysMLPackage.Literals.CONJUGATION__CONJUGATED_TYPE, false);
49+
if (conjugatedType == null) {
50+
Element owner = obj.getOwningRelatedElement();
51+
if (owner instanceof Type) {
52+
obj.setConjugatedType((Type)owner);
53+
} else {
54+
EList<Element> ownedRelatedElements = obj.getOwnedRelatedElement();
55+
if (!ownedRelatedElements.isEmpty()) {
56+
obj.setConjugatedType((Type)ownedRelatedElements.get(0));
57+
}
58+
}
59+
}
60+
61+
// If the originalType is not set, set it to the last ownedRelatedElement.
62+
Object originalType = obj.eGet(SysMLPackage.Literals.CONJUGATION__ORIGINAL_TYPE, false);
63+
if (originalType == null) {
64+
EList<Element> ownedRelatedElements = obj.getOwnedRelatedElement();
65+
if (!ownedRelatedElements.isEmpty()) {
66+
obj.setOriginalType((Type)ownedRelatedElements.get(ownedRelatedElements.size() - 1));
67+
}
68+
}
69+
}
70+
71+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.adapter;
23+
24+
import org.eclipse.emf.common.util.EList;
25+
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
26+
import org.omg.sysml.lang.sysml.Dependency;
27+
import org.omg.sysml.lang.sysml.Element;
28+
29+
public class DependencyAdapter extends RelationshipAdapter {
30+
31+
public DependencyAdapter(Dependency element) {
32+
super(element);
33+
}
34+
35+
public Dependency getTarget() {
36+
return (Dependency)super.getTarget();
37+
}
38+
39+
public void postProcess() {
40+
Dependency target = getTarget();
41+
42+
// Add all ownedRelatedElements to supplier.
43+
EObjectResolvingEList<Element> suppliers = (EObjectResolvingEList<Element>)target.getSupplier();
44+
EList<Element> ownedRelatedElements = target.getOwnedRelatedElement();
45+
ownedRelatedElements.stream().forEachOrdered(suppliers::addUnique);
46+
}
47+
48+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
* Copyright (c) 2024 Budapest University of Technology and Economics
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of theGNU Lesser General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*
19+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
20+
*
21+
*******************************************************************************/
22+
23+
package org.omg.sysml.adapter;
24+
25+
import org.eclipse.emf.common.util.EList;
26+
import org.omg.sysml.lang.sysml.Differencing;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.Feature;
29+
import org.omg.sysml.lang.sysml.SysMLPackage;
30+
31+
public class DifferencingAdapter extends RelationshipAdapter {
32+
33+
public DifferencingAdapter(Differencing element) {
34+
super(element);
35+
}
36+
37+
@Override
38+
public Differencing getTarget() {
39+
return (Differencing)super.getTarget();
40+
}
41+
42+
@Override
43+
public void postProcess() {
44+
Differencing obj = getTarget();
45+
46+
// If a Differencing is parsed targeting a Feature chain, then the differencingType will be empty,
47+
// but the Differencing will own the differencingType. So, in this case, the differencingType should
48+
// be set to the (last) ownedRelatedelement.
49+
Object differencingType = obj.eGet(SysMLPackage.Literals.DIFFERENCING__DIFFERENCING_TYPE, false);
50+
if (differencingType == null) {
51+
// Handle a differencingType that is a Feature chain.
52+
EList<Element> ownedRelatedElements = obj.getOwnedRelatedElement();
53+
if (!ownedRelatedElements.isEmpty()) {
54+
obj.setDifferencingType((Feature)ownedRelatedElements.get(ownedRelatedElements.size() - 1));
55+
}
56+
}
57+
}
58+
59+
}

0 commit comments

Comments
 (0)