Skip to content

Commit 5e72325

Browse files
authored
Merge pull request #595 from Systems-Modeling/ST6RI-796
ST6RI-796 Leftover caches in InvocationDelegates
2 parents 8615527 + 9831f74 commit 5e72325

4 files changed

Lines changed: 82 additions & 73 deletions

File tree

org.omg.sysml/src/org/omg/sysml/adapter/FeatureAdapter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ public boolean redefinesAnyOf(Collection<Feature> features, Set<Feature> visited
107107
// Caching
108108

109109
EList<Type> types = null;
110+
String storedEffectiveName = null;
111+
String storedEffectiveShortName = null;
112+
113+
public void storeEffectiveName(String effectiveName) {
114+
storedEffectiveName = effectiveName;
115+
}
116+
117+
public String getEffectiveName() {
118+
return storedEffectiveName;
119+
}
120+
121+
public void storeEffectiveShortName(String effectiveShortName) {
122+
storedEffectiveShortName = effectiveShortName;
123+
}
124+
125+
public String getEffectiveShortName() {
126+
return storedEffectiveShortName;
127+
}
110128

111129
public EList<Type> getTypes() {
112130
return types;
@@ -124,6 +142,8 @@ public void clearCaches() {
124142
super.clearCaches();
125143
types = null;
126144
redefinedFeatures.clear();
145+
storedEffectiveName = null;
146+
storedEffectiveShortName = null;
127147
}
128148

129149
// Implicit Elements

org.omg.sysml/src/org/omg/sysml/delegate/invocation/Feature_effectiveName_InvocationDelegate.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,58 +22,23 @@
2222
package org.omg.sysml.delegate.invocation;
2323

2424
import java.lang.reflect.InvocationTargetException;
25-
import java.util.HashMap;
26-
import java.util.HashSet;
27-
import java.util.Map;
28-
import java.util.Set;
2925

3026
import org.eclipse.emf.common.util.EList;
3127
import org.eclipse.emf.ecore.EOperation;
3228
import org.eclipse.emf.ecore.InternalEObject;
3329
import org.eclipse.emf.ecore.util.BasicInvocationDelegate;
3430
import org.omg.sysml.lang.sysml.Feature;
35-
import org.omg.sysml.lang.sysml.impl.FeatureImpl;
31+
import org.omg.sysml.util.FeatureUtil;
3632

3733
public class Feature_effectiveName_InvocationDelegate extends BasicInvocationDelegate {
3834

3935
public Feature_effectiveName_InvocationDelegate(EOperation operation) {
4036
super(operation);
4137
}
4238

43-
private final Map<Feature, String> nameCache = new HashMap<>();
44-
4539
@Override
4640
public Object dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
4741
Feature self = (Feature) target;
48-
49-
return computeEffectiveName(self, new HashSet<>());
50-
}
51-
52-
private boolean isNameDefinite(Feature self) {
53-
return self.getDeclaredName() != null || self.getDeclaredShortName() != null;
54-
}
55-
56-
57-
public String computeEffectiveName(Feature self, Set<Feature> visited) {
58-
if (isNameDefinite(self)) {
59-
return self.getDeclaredName();
60-
}
61-
62-
String effectiveName = nameCache.get(self);
63-
64-
if (effectiveName != null) {
65-
return effectiveName;
66-
}
67-
68-
visited.add(self);
69-
FeatureImpl namingFeature = (FeatureImpl) self.namingFeature();
70-
71-
if (namingFeature != null && !visited.contains(namingFeature)) {
72-
effectiveName = computeEffectiveName(namingFeature, visited);
73-
nameCache.put(self, effectiveName);
74-
}
75-
76-
return effectiveName;
42+
return FeatureUtil.computeEffectiveName(self);
7743
}
78-
7944
}

org.omg.sysml/src/org/omg/sysml/delegate/invocation/Feature_effectiveShortName_InvocationDelegate.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,23 @@
2222
package org.omg.sysml.delegate.invocation;
2323

2424
import java.lang.reflect.InvocationTargetException;
25-
import java.util.HashMap;
26-
import java.util.HashSet;
27-
import java.util.Map;
28-
import java.util.Set;
2925

3026
import org.eclipse.emf.common.util.EList;
3127
import org.eclipse.emf.ecore.EOperation;
3228
import org.eclipse.emf.ecore.InternalEObject;
3329
import org.eclipse.emf.ecore.util.BasicInvocationDelegate;
3430
import org.omg.sysml.lang.sysml.Feature;
35-
import org.omg.sysml.lang.sysml.impl.FeatureImpl;
31+
import org.omg.sysml.util.FeatureUtil;
3632

3733
public class Feature_effectiveShortName_InvocationDelegate extends BasicInvocationDelegate {
3834

3935
public Feature_effectiveShortName_InvocationDelegate(EOperation operation) {
4036
super(operation);
4137
}
4238

43-
private final Map<Feature, String> nameCache = new HashMap<>();
44-
4539
@Override
4640
public Object dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
4741
Feature self = (Feature) target;
48-
49-
return computeEffectiveShortName(self, new HashSet<>());
50-
}
51-
52-
private boolean isNameSet(Feature self) {
53-
return self.getDeclaredName() != null || self.getDeclaredShortName() != null;
42+
return FeatureUtil.computeEffectiveShortName(self);
5443
}
55-
56-
public String computeEffectiveShortName(Feature self, Set<Feature> visited) {
57-
if (isNameSet(self)) {
58-
return self.getDeclaredShortName();
59-
}
60-
61-
String effectiveShortName = nameCache.get(self);
62-
63-
if (effectiveShortName != null) {
64-
return effectiveShortName;
65-
}
66-
67-
visited.add(self);
68-
FeatureImpl namingFeature = (FeatureImpl) self.namingFeature();
69-
70-
if (namingFeature != null && !visited.contains(namingFeature)) {
71-
effectiveShortName = computeEffectiveShortName(namingFeature, visited);
72-
nameCache.put(self, effectiveShortName);
73-
}
74-
75-
return effectiveShortName;
76-
}
77-
7844
}

org.omg.sysml/src/org/omg/sysml/util/FeatureUtil.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,62 @@ public static Multiplicity getMultiplicityOf(Type type, Set<Type> visited) {
439439
}
440440
return multiplicity;
441441
}
442+
443+
//Naming
444+
445+
public static String computeEffectiveName(Feature self) {
446+
return computeEffectiveName(self, new HashSet<>());
447+
}
448+
449+
private static String computeEffectiveName(Feature self, Set<Feature> visited) {
450+
if (isNameSet(self)) {
451+
return self.getDeclaredName();
452+
}
453+
454+
String effectiveName = getFeatureAdapter(self).getEffectiveName();
455+
456+
if (effectiveName != null) {
457+
return effectiveName;
458+
}
459+
460+
visited.add(self);
461+
Feature namingFeature = self.namingFeature();
462+
463+
if (namingFeature != null && !visited.contains(namingFeature)) {
464+
effectiveName = computeEffectiveName(namingFeature, visited);
465+
getFeatureAdapter(self).storeEffectiveName(effectiveName);
466+
}
467+
468+
return effectiveName;
469+
}
470+
471+
public static String computeEffectiveShortName(Feature self) {
472+
return computeEffectiveShortName(self, new HashSet<>());
473+
}
474+
475+
private static String computeEffectiveShortName(Feature self, Set<Feature> visited) {
476+
if (isNameSet(self)) {
477+
return self.getDeclaredShortName();
478+
}
479+
480+
String effectiveShortName = getFeatureAdapter(self).getEffectiveShortName();
481+
482+
if (effectiveShortName != null) {
483+
return effectiveShortName;
484+
}
485+
486+
visited.add(self);
487+
Feature namingFeature = self.namingFeature();
488+
489+
if (namingFeature != null && !visited.contains(namingFeature)) {
490+
effectiveShortName = computeEffectiveShortName(namingFeature, visited);
491+
getFeatureAdapter(self).storeEffectiveShortName(effectiveShortName);
492+
}
493+
494+
return effectiveShortName;
495+
}
496+
497+
private static boolean isNameSet(Feature self) {
498+
return self.getDeclaredName() != null || self.getDeclaredShortName() != null;
499+
}
442500
}

0 commit comments

Comments
 (0)