Skip to content

Commit effff7b

Browse files
committed
ST6RI-796 Move effectiveName and effectiveShortName caching to
FeatureAdapter
1 parent d20a563 commit effff7b

4 files changed

Lines changed: 83 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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.omg.sysml.lang.sysml.SysMLPackage;
5656
import org.omg.sysml.lang.sysml.Type;
5757
import org.omg.sysml.lang.sysml.TypeFeaturing;
58+
import org.omg.sysml.lang.sysml.impl.FeatureImpl;
5859

5960
public class FeatureUtil {
6061

@@ -439,4 +440,62 @@ public static Multiplicity getMultiplicityOf(Type type, Set<Type> visited) {
439440
}
440441
return multiplicity;
441442
}
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+
}
442501
}

0 commit comments

Comments
 (0)