Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2016-01-14 11:39:28 +0000
committerCamille Letavernier2016-01-18 12:43:44 +0000
commit85d6ec3fa77fb0f9c1b847ed5b4d6d5632d99685 (patch)
treea32bad556a8b7ead11557ae746070a8577621db4 /plugins/facet
parentf22f9045b39f31d578db43b5a55a381b12829b47 (diff)
downloadorg.eclipse.papyrus-85d6ec3fa77fb0f9c1b847ed5b4d6d5632d99685.tar.gz
org.eclipse.papyrus-85d6ec3fa77fb0f9c1b847ed5b4d6d5632d99685.tar.xz
org.eclipse.papyrus-85d6ec3fa77fb0f9c1b847ed5b4d6d5632d99685.zip
485539: [Performances - Facet Manager] FacetManager recomputes the
Facets for a given element too many times https://bugs.eclipse.org/bugs/show_bug.cgi?id=485539 - Move some methods from FacetUtils to FacetManager and use a cache for meta-elements (Facets) - Avoid checking facet conformance when the Facet doesn't contain any useful typed element (Operation or Feature) Change-Id: If8837433b876385a77b67cf04d5b7792ae018338 Signed-off-by: Camille Letavernier <camille.letavernier@cea.fr>
Diffstat (limited to 'plugins/facet')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java16
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/FacetUtils.java144
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/IFacetManager.java9
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/FacetManager.java222
4 files changed, 169 insertions, 222 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
index 73052bca244..f66e76bb384 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
@@ -219,7 +219,7 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
Logger.logError(e, Activator.getDefault());
}
- final Collection<Object> children = new ArrayList<Object>();
+ final Collection<TreeElement> children = new ArrayList<TreeElement>();
createAttributes(treeElement, facetFeatures, children);
createReferences(treeElement, facetFeatures, children);
return children.toArray();
@@ -378,7 +378,7 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
- private void createReferences(final EObjectTreeElement treeElement, Collection<EStructuralFeature> facetFeatures, Collection<Object> children) {
+ private void createReferences(final EObjectTreeElement treeElement, Collection<EStructuralFeature> facetFeatures, Collection<TreeElement> children) {
final EObject eObject = treeElement.getEObject();
for (EReference next : getVisibleReferences(eObject)) {
@@ -391,12 +391,12 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
}
}
- private void createReference(EObjectTreeElement treeElement, EObject eObject, EReference eReference, Collection<Object> children) {
+ private void createReference(EObjectTreeElement treeElement, EObject eObject, EReference eReference, Collection<TreeElement> children) {
if (collapseLink(eObject, eReference)) {
if (eReference.getUpperBound() != 1) {
collectMultiValuedReferenceChildren(eReference, eObject, treeElement, children);
} else {
- Object child = getSingleValuedReferenceChild(eReference, eObject, treeElement);
+ EObjectTreeElement child = getSingleValuedReferenceChild(eReference, eObject, treeElement);
if (child != null) {
children.add(child);
}
@@ -406,7 +406,7 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
}
}
- private void createAttributes(final EObjectTreeElement treeElement, Collection<EStructuralFeature> facetFeatures, Collection<? super TreeElement> children) {
+ private void createAttributes(final EObjectTreeElement treeElement, Collection<EStructuralFeature> facetFeatures, Collection<TreeElement> children) {
final EObject eObject = treeElement.getEObject();
for (EAttribute next : getVisibleAttributes(eObject)) {
@@ -463,8 +463,8 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
return attributeProxy;
}
- private Object getSingleValuedReferenceChild(final EReference eReference, final EObject eObject, final TreeElement parent) {
- Object child = null;
+ private EObjectTreeElement getSingleValuedReferenceChild(final EReference eReference, final EObject eObject, final TreeElement parent) {
+ EObjectTreeElement child = null;
try {
final IFacetManager facetManager = this.customManager.getFacetManager();
final Object result = facetManager.getOrInvoke(eObject, eReference, null);
@@ -478,7 +478,7 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
return child;
}
- private void collectMultiValuedReferenceChildren(final EReference eReference, final EObject eObject, final TreeElement parent, Collection<Object> children) {
+ private void collectMultiValuedReferenceChildren(final EReference eReference, final EObject eObject, final TreeElement parent, Collection<TreeElement> children) {
try {
final IFacetManager facetManager = this.customManager.getFacetManager();
final List<Object> result = facetManager.getOrInvokeMultiValued(eObject, eReference, null);
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/FacetUtils.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/FacetUtils.java
index 26ab814aba8..6c802e8dc87 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/FacetUtils.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/FacetUtils.java
@@ -283,78 +283,6 @@ public final class FacetUtils {
return result;
}
- /**
- * This methods returns all the known (registered) eTypedElements.
- *
- * @param resourceSet
- * the eTypedElement search will be done in/using this resourceSet
- * @return all the known (registered) eTypedElements
- */
- public static Set<? extends ETypedElement> getETypedElements(
- final ResourceSet resourceSet) {
- final Set<ETypedElement> result = new HashSet<ETypedElement>();
- final Collection<Object> ePackages = EPackage.Registry.INSTANCE
- .values();
- for (Object object : ePackages) {
- EPackage ePackage = null;
- if (object instanceof EPackage) {
- ePackage = (EPackage) object;
- } else if (object instanceof EPackage.Descriptor) {
- final EPackage.Descriptor descriptor = (EPackage.Descriptor) object;
- ePackage = descriptor.getEPackage();
- }
- if (ePackage != null) {
- result.addAll(getETypedElements(ePackage));
- }
- }
- result.addAll(getFacetETypedElements(resourceSet));
- return result;
- }
-
- /**
- * @since 0.3
- */
- public static Set<? extends ETypedElement> getFacetETypedElements(
- final ResourceSet resourceSet) {
- final Set<ETypedElement> result = new HashSet<ETypedElement>();
- final Collection<FacetSet> facetSets = IFacetSetCatalogManagerFactory.DEFAULT
- .getOrCreateFacetSetCatalogManager(resourceSet)
- .getRegisteredFacetSets();
- for (FacetSet facetSet : facetSets) {
- result.addAll(getETypedElements(facetSet));
- }
- return result;
- }
-
- public static List<ETypedElement> getETypedElements(final EPackage ePackage) {
- final List<ETypedElement> result = new ArrayList<ETypedElement>();
- for (EClassifier eClassifier : ePackage.getEClassifiers()) {
- result.addAll(getETypedElements(eClassifier));
- }
- for (EPackage subPackage : ePackage.getESubpackages()) {
- result.addAll(getETypedElements(subPackage));
- }
- return result;
- }
-
- /**
- * @since 0.3
- */
- public static List<ETypedElement> getETypedElements(
- final EClassifier eClassifier) {
- final List<ETypedElement> result = new ArrayList<ETypedElement>();
- if (eClassifier instanceof Facet) {
- final Facet facet = (Facet) eClassifier;
- result.addAll(facet.getFacetElements());
- result.addAll(facet.getFacetOperations());
- } else if (eClassifier instanceof EClass) {
- final EClass eClass = (EClass) eClassifier;
- result.addAll(eClass.getEAllStructuralFeatures());
- result.addAll(eClass.getEAllOperations());
- }
- return result;
- }
-
public static List<Facet> getFacets(final FacetSet facetSet) {
final List<Facet> result = new ArrayList<Facet>();
for (EClassifier eClassifier : facetSet.getEClassifiers()) {
@@ -399,77 +327,7 @@ public final class FacetUtils {
public static <T extends ETypedElement> List<T> getETypedElements(
final EObject eObject, final Class<T> classs,
final IFacetManager facetManager) throws FacetManagerException {
- final List<T> result = new ArrayList<T>();
- for (FacetSet facetSet : facetManager.getManagedFacetSets()) {
- result.addAll(getETypedElements(eObject, facetSet, classs,
- facetManager));
- }
- return result;
- }
-
- // Copied (and refactored) from
- // org.eclipse.papyrus.emf.facet.efacet.core.internal.FacetManager
- private static <T extends ETypedElement> List<T> getETypedElements(
- final EObject eObject, final FacetSet facetSet,
- final Class<T> classs, final IFacetManager manager)
- throws FacetManagerException {
- final List<T> result = new ArrayList<T>();
- for (EClassifier eClassifier : facetSet.getEClassifiers()) {
- if (eClassifier instanceof Facet) {
- final Facet facet = (Facet) eClassifier;
- if (manager.isConforming(eObject, facet)) {
- result.addAll(getETypedElement(classs, facet));
- }
- }
- }
- // hierarchical FacetSets
- for (EPackage ePackage : facetSet.getESubpackages()) {
- if (ePackage instanceof FacetSet) {
- final FacetSet subFacetSet = (FacetSet) ePackage;
- result.addAll(getETypedElements(eObject, subFacetSet, classs,
- manager));
- }
- }
- // aggregates
- for (FacetSet subFacetSet : facetSet.getFacetSets()) {
- result.addAll(getETypedElements(eObject, subFacetSet, classs,
- manager));
- }
- return result;
- }
-
- private static <T> List<T> getETypedElement(final Class<T> classs,
- final Facet facet) {
- final List<T> result = new ArrayList<T>();
- for (ETypedElement eTypedElement : getAllETypedElements(facet)) {
- if (classs.isInstance(eTypedElement)) {
- @SuppressWarnings("unchecked")
- // @SuppressWarnings("unchecked") This type has been
- // checked using isInstance
- final T typedSF = (T) eTypedElement;
- final T resolvedTE = IResolverManager.DEFAULT
- .resolve(typedSF, classs);
- if (resolvedTE == null) {
- result.add(typedSF);
- } else {
- result.add(resolvedTE);
- }
- }
- }
- return result;
- }
-
- // Copied (and refactored) from
- // org.eclipse.papyrus.emf.facet.efacet.core.internal.FacetManager
- private static List<ETypedElement> getAllETypedElements(
- final Facet facet) {
- final List<ETypedElement> structFeatures = new ArrayList<ETypedElement>();
- structFeatures.addAll(facet.getFacetElements());
- structFeatures.addAll(facet.getFacetOperations());
- for (Facet extFacet : facet.getExtendedFacets()) {
- structFeatures.addAll(getAllETypedElements(extFacet));
- }
- return structFeatures;
+ return facetManager.getETypedElements(eObject, classs);
}
/**
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/IFacetManager.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/IFacetManager.java
index 5852f655db0..e31d68eac11 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/IFacetManager.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/IFacetManager.java
@@ -224,4 +224,13 @@ public interface IFacetManager {
*/
void removeListener(IFacetManagerListener listener);
+ /**
+ * @param eObject
+ * @param classs
+ * @return
+ */
+ <T extends ETypedElement> List<T> getETypedElements(EObject eObject, Class<T> classs) throws FacetManagerException;
+
+
+
}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/FacetManager.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/FacetManager.java
index 01fcaea72aa..542bb43fa1f 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/FacetManager.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.core/src/org/eclipse/papyrus/emf/facet/efacet/core/internal/FacetManager.java
@@ -23,10 +23,13 @@
package org.eclipse.papyrus.emf.facet.efacet.core.internal;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.notify.Adapter;
@@ -56,6 +59,7 @@ import org.eclipse.papyrus.emf.facet.efacet.core.internal.exception.FacetConform
import org.eclipse.papyrus.emf.facet.efacet.core.internal.exception.NonApplicableFacetException;
import org.eclipse.papyrus.emf.facet.efacet.core.internal.exception.NonConformingEObjectException;
import org.eclipse.papyrus.emf.facet.efacet.core.internal.exception.UnmatchingExpectedTypeException;
+import org.eclipse.papyrus.emf.facet.efacet.core.internal.exported.IResolverManager;
import org.eclipse.papyrus.emf.facet.efacet.core.internal.serialization.SerializationManager;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
@@ -78,6 +82,8 @@ public class FacetManager implements IFacetManager, Adapter {
private final FacetManagerContext context;
private final SerializationManager serializationMgr;
private final ResourceSet resourceSet;
+ private final Map<Facet, EClass> extendedMetaclass = new HashMap<>();
+ private final Map<Facet, Map<Class<?>, List<? extends ETypedElement>>> typedElements = new HashMap<>();
public FacetManager(final Resource resource) {
this.serializationMgr = new SerializationManager(resource);
@@ -91,6 +97,7 @@ public class FacetManager implements IFacetManager, Adapter {
this.resourceSet = resourceSet;
}
+ @Override
public void saveStructuralFeatureInstanceModel()
throws FacetManagerException {
this.serializationMgr.saveStructuralFeatureInstanceModel();
@@ -105,6 +112,7 @@ public class FacetManager implements IFacetManager, Adapter {
* the Facet the applicability of which is being tested
* @return whether the given model element should be seen as an instance of the given Facet
*/
+ @Override
public boolean isConforming(final EObject eObject, final Facet facet)
throws FacetManagerException {
return getConformanceState(eObject, facet) == FacetManager.ConformanceState.Conformant;
@@ -135,8 +143,9 @@ public class FacetManager implements IFacetManager, Adapter {
throw new IllegalArgumentException("facet cannot be null"); //$NON-NLS-1$
}
// End of precondition section
+
ConformanceState result;
- final EClass extendedMetaclass = FacetUtils.getExtendedMetaclass(facet);
+ final EClass extendedMetaclass = getExtendedMetaclass(facet);
if (extendedMetaclass != null
&& (extendedMetaclass.isSuperTypeOf(eObject.eClass()) || extendedMetaclass == EcorePackage.eINSTANCE.getEObject())) {
final ETypedElement typeElement = facet.getConformanceTypedElement();
@@ -165,6 +174,13 @@ public class FacetManager implements IFacetManager, Adapter {
return result;
}
+ private final EClass getExtendedMetaclass(Facet facet) {
+ if (!extendedMetaclass.containsKey(facet)) {
+ extendedMetaclass.put(facet, FacetUtils.getExtendedMetaclass(facet));
+ }
+ return extendedMetaclass.get(facet);
+ }
+
private Boolean getConformanceValue(final EObject eObject,
final ETypedElement typeElement) throws FacetManagerException {
// Begin precondition checking
@@ -201,6 +217,7 @@ public class FacetManager implements IFacetManager, Adapter {
return result;
}
+ @Override
public void set(final EObject eObject,
final EStructuralFeature structuralFeature, final Object newValue,
final EditingDomain editingDomain) throws FacetManagerException {
@@ -248,7 +265,7 @@ public class FacetManager implements IFacetManager, Adapter {
private <T> T internalGet(final EObject eObject,
final EStructuralFeature structuralFeature,
final Class<T> expectedType, final boolean basicGet)
- throws FacetManagerException {
+ throws FacetManagerException {
try {
Object value;
if (structuralFeature.eContainer() instanceof Facet) {
@@ -295,9 +312,10 @@ public class FacetManager implements IFacetManager, Adapter {
}
}
+ @Override
public <T> T invoke(final EObject eObject, final EOperation operation,
final Class<T> expectedType, final EditingDomain editingDomain, final Object... arguments)
- throws FacetManagerException {
+ throws FacetManagerException {
try {
return internalInvoke(eObject, operation, expectedType, false, arguments);
} catch (Exception e) {
@@ -307,7 +325,7 @@ public class FacetManager implements IFacetManager, Adapter {
public <T> List<T> invokeMultiValued(final EObject eObject, final EOperation operation,
final Class<T> expectedType, final Object... arguments)
- throws FacetManagerException {
+ throws FacetManagerException {
Object result;
try {
result = internalInvoke(eObject, operation, null, false, arguments);
@@ -319,9 +337,9 @@ public class FacetManager implements IFacetManager, Adapter {
private <T> T internalInvoke(final EObject eObject, final EOperation operation, final Class<T> expectedType,
final boolean basicInvoke, final Object... arguments)
- throws DerivedTypedElementException, InvocationTargetException,
- FacetConformanceEvaluationException, NonApplicableFacetException,
- NonConformingEObjectException, FacetManagerException {
+ throws DerivedTypedElementException, InvocationTargetException,
+ FacetConformanceEvaluationException, NonApplicableFacetException,
+ NonConformingEObjectException, FacetManagerException {
Object result;
if (operation.eContainer() instanceof Facet) {
final Facet facet = (Facet) operation.eContainer();
@@ -354,6 +372,7 @@ public class FacetManager implements IFacetManager, Adapter {
throw new UnsupportedOperationException("not implemented yet"); //$NON-NLS-1$
}
+ @Override
public List<ETypedElementResult> batchInvoke(
final Collection<EObject> eObjects, final EOperation operation,
final Object... arguments) throws FacetManagerException {
@@ -361,18 +380,24 @@ public class FacetManager implements IFacetManager, Adapter {
throw new UnsupportedOperationException("not implemented yet"); //$NON-NLS-1$
}
+ @Override
public List<FacetSet> getManagedFacetSets() {
return this.context;
}
public void setManagedFacetSets(final List<FacetSet> facetSets) {
+ extendedMetaclass.clear();
+ typedElements.clear();
this.context.setManagedFacetSets(facetSets);
}
public void removeFacetSet(final FacetSet facetSet) {
+ extendedMetaclass.clear();
+ typedElements.clear();
this.context.removeFacetSet(facetSet);
}
+ @Override
public ResourceSet getResourceSet() {
return this.resourceSet;
}
@@ -382,78 +407,22 @@ public class FacetManager implements IFacetManager, Adapter {
throw new UnsupportedOperationException("not implemented yet"); //$NON-NLS-1$
}
+ @Override
public Set<EAttribute> getAttributes(final EObject eObject)
throws FacetManagerException {
- return getEStructuralFeatures(eObject, EAttribute.class);
+ return new HashSet<>(getETypedElements(eObject, EAttribute.class));
}
+ @Override
public Set<EStructuralFeature> getStructuralFeature(final EObject eObject)
throws FacetManagerException {
- return getEStructuralFeatures(eObject, EStructuralFeature.class);
- }
-
- public <T extends ETypedElement> Set<T> getEStructuralFeatures(
- final EObject eObject, final Class<T> classs)
- throws FacetManagerException {
- final Set<T> result = new HashSet<T>();
- for (FacetSet facetSet : this.context.getManagedFacetSets()) {
- result.addAll(getETypedElements(eObject, facetSet, classs));
- }
- return result;
- }
-
- private <T extends ETypedElement> Collection<T> getETypedElements(
- final EObject eObject, final FacetSet facetSet,
- final Class<T> classs) throws FacetManagerException {
- final Set<T> result = new HashSet<T>();
- for (EClassifier eClassifier : facetSet.getEClassifiers()) {
- if (eClassifier instanceof Facet) {
- final Facet facet = (Facet) eClassifier;
- if (isConforming(eObject, facet)) {
- for (EStructuralFeature eStructuralFeature : getAllEStructuralFeatures(facet)) {
- if (classs.isInstance(eStructuralFeature)) {
- @SuppressWarnings("unchecked")
- // @SuppressWarnings("unchecked") This type has been
- // checked using isInstance
- final T typedSF = (T) eStructuralFeature;
- result.add(typedSF);
- }
- }
- }
- }
- }
- // hierarchical FacetSets
- for (EPackage ePackage : facetSet.getESubpackages()) {
- if (ePackage instanceof FacetSet) {
- final FacetSet subFacetSet = (FacetSet) ePackage;
- result.addAll(getETypedElements(eObject,
- subFacetSet, classs));
- }
- }
- // aggregates
- for (FacetSet subFacetSet : facetSet.getFacetSets()) {
- result.addAll(getETypedElements(eObject, subFacetSet, classs));
- }
- return result;
- }
-
- private List<EStructuralFeature> getAllEStructuralFeatures(final Facet facet) {
- final List<EStructuralFeature> structFeatures = new LinkedList<EStructuralFeature>();
- structFeatures.addAll(facet.getFacetElements());
- for (Facet extFacet : facet.getExtendedFacets()) {
- structFeatures.addAll(getAllEStructuralFeatures(extFacet));
- }
- return structFeatures;
+ return new HashSet<>(getETypedElements(eObject, EStructuralFeature.class));
}
+ @Override
public Set<EReference> getReferences(final EObject eObject)
throws FacetManagerException {
- return getEStructuralFeatures(eObject, EReference.class);
- }
-
- public Collection<? extends EStructuralFeature> getSF(final EObject eObject)
- throws FacetManagerException {
- return getEStructuralFeatures(eObject, EStructuralFeature.class);
+ return new HashSet<>(getETypedElements(eObject, EReference.class));
}
@Deprecated
@@ -462,6 +431,8 @@ public class FacetManager implements IFacetManager, Adapter {
this.context.addFrontManagedFacetSet((FacetSet) facetToLoad
.getEPackage());
}
+ extendedMetaclass.clear();
+ typedElements.clear();
}
@Deprecated
@@ -471,11 +442,14 @@ public class FacetManager implements IFacetManager, Adapter {
public void removeAllManagedFacetSets() {
this.context.clear();
+ extendedMetaclass.clear();
+ typedElements.clear();
}
+ @Override
public <T> List<T> getOrInvokeMultiValued(final EObject eObject,
final ETypedElement eTypedElement, final Class<T> classs)
- throws FacetManagerException {
+ throws FacetManagerException {
List<T> result = null;
if (eTypedElement instanceof EStructuralFeature) {
final EStructuralFeature structuralFeature = (EStructuralFeature) eTypedElement;
@@ -487,9 +461,10 @@ public class FacetManager implements IFacetManager, Adapter {
return result;
}
+ @Override
public <T> T getOrInvoke(final EObject eObject,
final ETypedElement eTypedElement, final Class<T> classs)
- throws FacetManagerException {
+ throws FacetManagerException {
T result = null;
if (eTypedElement instanceof EStructuralFeature) {
final EStructuralFeature structuralFeature = (EStructuralFeature) eTypedElement;
@@ -505,6 +480,7 @@ public class FacetManager implements IFacetManager, Adapter {
throw new IllegalStateException("Not implemented, and never will since it's deprecated"); //$NON-NLS-1$
}
+ @Override
public <T> List<ETypedElementResult> batchGetOrInvoke(final Collection<EObject> sources, final ETypedElement query, final Class<T> classs)
throws FacetManagerException {
final List<ETypedElementResult> results = new LinkedList<ETypedElementResult>();
@@ -557,34 +533,138 @@ public class FacetManager implements IFacetManager, Adapter {
public void addBackManagedFacetSet(final FacetSet facetSet) {
this.context.addBackManagedFacetSet(facetSet);
+ extendedMetaclass.clear();
+ typedElements.clear();
}
public void addFrontManagedFacetSet(final FacetSet facetSet) {
this.context.addFrontManagedFacetSet(facetSet);
+ extendedMetaclass.clear();
+ typedElements.clear();
}
+ @Override
public void notifyChanged(final Notification notification) {
// Nothing to do
}
+ @Override
public Notifier getTarget() {
return null;
}
+ @Override
public void setTarget(final Notifier newTarget) {
// Nothing to do
}
+ @Override
public boolean isAdapterForType(final Object type) {
return false;
}
+ @Override
public void addListener(final IFacetManagerListener listener) {
this.context.addListener(listener);
}
+ @Override
public void removeListener(final IFacetManagerListener listener) {
this.context.removeListener(listener);
}
+
+
+
+
+ /**
+ * @see org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager#getETypedElements(org.eclipse.emf.ecore.EObject, java.lang.Class)
+ *
+ * @param eObject
+ * @param classs
+ * @return
+ * @throws FacetManagerException
+ */
+ @Override
+ public <T extends ETypedElement> List<T> getETypedElements(EObject eObject, Class<T> classs) throws FacetManagerException {
+ final List<T> result = new ArrayList<T>();
+ for (FacetSet facetSet : getManagedFacetSets()) {
+ result.addAll(getETypedElements(eObject, facetSet, classs));
+ }
+ return result;
+ }
+
+ private <T extends ETypedElement> List<T> getETypedElements(final EObject eObject, final FacetSet facetSet, final Class<T> classs)
+ throws FacetManagerException {
+ final List<T> result = new ArrayList<T>();
+ for (EClassifier eClassifier : facetSet.getEClassifiers()) {
+ if (eClassifier instanceof Facet) {
+ final Facet facet = (Facet) eClassifier;
+
+ // Before checking conformance, verify that the facet contains at least one element in the returned list.
+ // Do no compute conformance if the list will be empty anyway
+ if (EStructuralFeature.class.isAssignableFrom(classs)) {
+ if (!facet.getAllFacetElements().isEmpty()) {
+ if (isConforming(eObject, facet)) {
+ result.addAll(getETypedElement(classs, facet));
+ }
+ }
+ } else if (EOperation.class.isAssignableFrom(classs)) {
+ if (!facet.getAllFacetOperations().isEmpty()) {
+ if (isConforming(eObject, facet)) {
+ result.addAll(getETypedElement(classs, facet));
+ }
+ }
+ } else {
+ if (isConforming(eObject, facet)) {
+ result.addAll(getETypedElement(classs, facet));
+ }
+ }
+
+ }
+ }
+ // hierarchical FacetSets
+ for (EPackage ePackage : facetSet.getESubpackages()) {
+ if (ePackage instanceof FacetSet) {
+ final FacetSet subFacetSet = (FacetSet) ePackage;
+ result.addAll(getETypedElements(eObject, subFacetSet, classs));
+ }
+ }
+ // aggregates
+ for (FacetSet subFacetSet : facetSet.getFacetSets()) {
+ result.addAll(getETypedElements(eObject, subFacetSet, classs));
+ }
+ return result;
+ }
+
+ private <T extends ETypedElement> List<T> getETypedElement(final Class<T> classs, final Facet facet) {
+ if (!typedElements.containsKey(facet)) {
+ typedElements.put(facet, new HashMap<>());
+ }
+
+ Map<Class<?>, List<? extends ETypedElement>> cache = typedElements.get(facet);
+ if (!cache.containsKey(classs)) {
+ final List<ETypedElement> result = new ArrayList<ETypedElement>();
+ for (ETypedElement eTypedElement : facet.getAllTypedElements()) {
+ if (classs.isInstance(eTypedElement)) {
+ @SuppressWarnings("unchecked")
+ // @SuppressWarnings("unchecked") This type has been
+ // checked using isInstance
+ final T typedSF = (T) eTypedElement;
+ final T resolvedTE = IResolverManager.DEFAULT
+ .resolve(typedSF, classs);
+ if (resolvedTE == null) {
+ result.add(typedSF);
+ } else {
+ result.add(resolvedTE);
+ }
+ }
+ }
+
+ cache.put(classs, result);
+ }
+
+ return (List<T>) cache.get(classs);
+ }
+
}

Back to the top