Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2017-09-06 15:30:11 +0000
committerShuai Li2017-09-08 08:17:27 +0000
commit29cc608e498866ba98da1d66b5f451e64dc202cb (patch)
treead01644d8707338c21bf9fabd3f911bad7e5e71a
parenta19b14e596cbd8f2a6cac3e4bf5b7d05caa4b643 (diff)
downloadorg.eclipse.papyrus-29cc608e498866ba98da1d66b5f451e64dc202cb.tar.gz
org.eclipse.papyrus-29cc608e498866ba98da1d66b5f451e64dc202cb.tar.xz
org.eclipse.papyrus-29cc608e498866ba98da1d66b5f451e64dc202cb.zip
Bug 519446: [ElementTypes] The AdviceComparator is incorrect
https://bugs.eclipse.org/bugs/show_bug.cgi?id=519446 - Fix the Map collector issue - Use a Multimap to allow several advices sharing the same ID - Add a FIXME for the Advice-ID issue Change-Id: I21d9a94c460aec690421243ce6965228991a5749 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/infra/types/org.eclipse.papyrus.infra.types.core/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceUtil.java30
2 files changed, 23 insertions, 8 deletions
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/META-INF/MANIFEST.MF b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/META-INF/MANIFEST.MF
index 06c9661c5ac..ac6292b479b 100644
--- a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/META-INF/MANIFEST.MF
+++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/META-INF/MANIFEST.MF
@@ -23,3 +23,4 @@ Bundle-Activator: org.eclipse.papyrus.infra.types.core.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.infra.types.core;singleton:=true
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Import-Package: com.google.common.collect;version="21.0.0"
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceUtil.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceUtil.java
index 8f58841c5fb..223ff3e9672 100644
--- a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceUtil.java
+++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceUtil.java
@@ -19,12 +19,14 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurationRegistry;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
/**
* @since 3.1
*/
@@ -32,6 +34,7 @@ public class AdviceUtil {
/**
* Sorts the advices, taking dependencies of the specified element types into account
+ *
* @param advices
* @param types
* @param contextId
@@ -61,26 +64,37 @@ public class AdviceUtil {
}
LinkedHashSet<IEditHelperAdvice> sortedAdvices = new LinkedHashSet<>();
- Map<String, IEditHelperAdvice> idToAdvice = Arrays.stream(advices).collect(Collectors.toMap(a -> a.getClass().getName(), a -> a));
+ Multimap<String, IEditHelperAdvice> idToAdvice = HashMultimap.create();
+ for (IEditHelperAdvice advice : advices) {
+ idToAdvice.put(getId(advice), advice);
+ }
for (IEditHelperAdvice advice : advices) {
- collectSortedDependencies(advice.getClass().getName(), graph, idToAdvice, sortedAdvices);
+ collectSortedDependencies(advice, graph, idToAdvice, sortedAdvices);
}
return sortedAdvices.toArray(advices);
}
- private static void collectSortedDependencies(String adviceName, OrientedGraph<String> dependencies, Map<String, IEditHelperAdvice> idToAdvice,
- LinkedHashSet<IEditHelperAdvice> result) {
+ private static String getId(IEditHelperAdvice advice) {
+ // FIXME Bug 519446: In some cases, an advice class can be instantiated several times, so ID is not unique
+ // This also needs to be consistent with IDs returned by ElementTypeSetConfigurationRegistry.getInstance().getAdvicesDeps()
+ return advice == null ? null : advice.getClass().getName();
+ }
- IEditHelperAdvice advice = idToAdvice.get(adviceName);
+ private static void collectSortedDependencies(IEditHelperAdvice advice, OrientedGraph<String> dependencies, Multimap<String, IEditHelperAdvice> idToAdvice,
+ LinkedHashSet<IEditHelperAdvice> result) {
if (advice != null && result.contains(advice)) {
return;
}
+
+ String adviceName = getId(advice);
Set<String> allDependencies = dependencies.getAllConnex(adviceName);
- for (String dependency : allDependencies) {
- collectSortedDependencies(dependency, dependencies, idToAdvice, result);
+ for (String dependencyID : allDependencies) {
+ for (IEditHelperAdvice dependency : idToAdvice.get(dependencyID)) {
+ collectSortedDependencies(dependency, dependencies, idToAdvice, result);
+ }
}
if (advice != null) {

Back to the top