Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-01-18 12:25:10 -0500
committervincent lorenzo2019-01-21 04:00:15 -0500
commitc022864a86c36b495cf76c2f67eb165464b46720 (patch)
tree31c6381832df53d77dc2fce8487e3428588e67c0
parent5e61a5490724d2ddf52caf45af21744482e8ada8 (diff)
downloadorg.eclipse.papyrus-c022864a86c36b495cf76c2f67eb165464b46720.tar.gz
org.eclipse.papyrus-c022864a86c36b495cf76c2f67eb165464b46720.tar.xz
org.eclipse.papyrus-c022864a86c36b495cf76c2f67eb165464b46720.zip
Bug 543494 - InternationalizationUMLItemProviderAdapterFactory fails to
find existing adapters To avoid possible performance issues, we implement an internationalization condition in the adapt method. + Test for the fix NB: An error with the MANIFEST version was detected, but i cannot do something nowadays. I enter a bug for the next release. Change-Id: I1044139e40b0b45d57c18be4821a6486df7e9aec Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/pom.xml2
-rw-r--r--plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/src/org/eclipse/papyrus/uml/internationalization/edit/providers/InternationalizationUMLItemProviderAdapterFactory.java31
-rw-r--r--tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/AllTests.java20
-rw-r--r--tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationAdapterTest.java69
5 files changed, 105 insertions, 19 deletions
diff --git a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/META-INF/MANIFEST.MF b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/META-INF/MANIFEST.MF
index 1cc4255dd14..6268ae158c9 100644
--- a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/META-INF/MANIFEST.MF
+++ b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.papyrus.uml.internationalization.edit;singleton:=true
-Bundle-Version: 1.100.0.qualifier
+Bundle-Version: 1.100.100.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/pom.xml b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/pom.xml
index 1184e521ed7..0a3350579ba 100644
--- a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/pom.xml
+++ b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/pom.xml
@@ -8,6 +8,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.internationalization.edit</artifactId>
- <version>1.100.0-SNAPSHOT</version>
+ <version>1.100.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/src/org/eclipse/papyrus/uml/internationalization/edit/providers/InternationalizationUMLItemProviderAdapterFactory.java b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/src/org/eclipse/papyrus/uml/internationalization/edit/providers/InternationalizationUMLItemProviderAdapterFactory.java
index 7288dfa0e55..564300fe087 100644
--- a/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/src/org/eclipse/papyrus/uml/internationalization/edit/providers/InternationalizationUMLItemProviderAdapterFactory.java
+++ b/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.edit/src/org/eclipse/papyrus/uml/internationalization/edit/providers/InternationalizationUMLItemProviderAdapterFactory.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2017 Christian W. Damus and others.
- *
+ * Copyright (c) 2017, 2019 CEA LIST, Christian W. Damus and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,8 @@
*
* Contributors:
* Christian W. Damus - Initial API and implementation
- *
+ * Nicolas FAUVERGUE (CEA LIST) - Bug 543494
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.internationalization.edit.providers;
@@ -82,7 +83,7 @@ public class InternationalizationUMLItemProviderAdapterFactory
/**
* Creates a listener on the internationalization preferences utility that will
* be notified when the settings for any resource change.
- *
+ *
* @return the preference listener
*/
private InternationalizationPreferenceListener createPreferenceListener() {
@@ -120,7 +121,7 @@ public class InternationalizationUMLItemProviderAdapterFactory
/**
* Create an adapter that will check the internationalization status of
* resources as they are added to any of my contextual resource sets.
- *
+ *
* @return the resource-set adapter
*/
private Adapter createResourceSetAdapter() {
@@ -172,7 +173,7 @@ public class InternationalizationUMLItemProviderAdapterFactory
/**
* Queries whether an {@code object} requires i18n support.
- *
+ *
* @param object
* an object
* @return whether it needs i18n
@@ -193,7 +194,7 @@ public class InternationalizationUMLItemProviderAdapterFactory
/**
* Discover the internationalization status of a newly encountered resource set.
- *
+ *
* @param resourceSet
* a resource set now encountered
*/
@@ -213,7 +214,7 @@ public class InternationalizationUMLItemProviderAdapterFactory
/**
* Discover the internationalization status of a newly encountered resource.
- *
+ *
* @param resource
* a resource now encountered
*/
@@ -251,4 +252,18 @@ public class InternationalizationUMLItemProviderAdapterFactory
uml.setParentAdapterFactory(parentAdapterFactory);
}
+ /**
+ * We implement this method to avoid possible performance issues to adapt elements when it is not needed.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory#adapt(org.eclipse.emf.common.notify.Notifier, java.lang.Object)
+ */
+ @Override
+ public Adapter adapt(final Notifier notifier, final Object type) {
+ if (notifier instanceof EObject && !needsInterationalization((EObject) notifier)) {
+ return uml.adapt(notifier, type);
+ }
+ return super.adapt(notifier, this);
+ }
+
}
diff --git a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/AllTests.java b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/AllTests.java
index 6229677c149..39fcb40abb1 100644
--- a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/AllTests.java
+++ b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/AllTests.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2016, 2017 CEA LIST, Christian W. Damus, and others.
- *
+ * Copyright (c) 2016-2017, 2019 CEA LIST, Christian W. Damus, and others.
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -11,21 +11,23 @@
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
* Christian W. Damus - bug 528343
- *
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 543494
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.internationalization.tests.tests;
-import org.junit.runner.RunWith;
import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
+import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(ClassificationSuite.class)
-@SuiteClasses({
- UMLInternationalizationChangePreferencesTest.class,
- UMLInternationalizationChangeLanguageTest.class,
- InternationalizationUMLItemProviderAdapterFactoryTest.class,
+@SuiteClasses({
+ UMLInternationalizationChangePreferencesTest.class,
+ UMLInternationalizationChangeLanguageTest.class,
+ InternationalizationUMLItemProviderAdapterFactoryTest.class,
+ InternationalizationAdapterTest.class,
})
public class AllTests {
-
+
}
diff --git a/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationAdapterTest.java b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationAdapterTest.java
new file mode 100644
index 00000000000..5361cf3de18
--- /dev/null
+++ b/tests/junit/plugins/uml/internationalization/org.eclipse.papyrus.uml.internationalization.tests/src/org/eclipse/papyrus/uml/internationalization/tests/tests/InternationalizationAdapterTest.java
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST, and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.internationalization.tests.tests;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.uml.internationalization.edit.providers.InternationalizationUMLItemProviderAdapterFactory;
+import org.eclipse.uml2.uml.Abstraction;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class allows to test the uml internationalization adapter validation.
+ */
+public class InternationalizationAdapterTest {
+
+ /**
+ * This test allows to test the label provider adapter for UML element (here abstraction for example).
+ */
+ @Test
+ public void testLabelProviderAdapter() {
+
+ final Abstraction abstraction = UMLFactory.eINSTANCE.createAbstraction();
+
+ // Add abstraction to a resource and a resourceSet. By default this configuration leads to not needsInterationalization
+ final Resource resource = new ResourceImpl();
+ resource.getContents().add(abstraction);
+
+ final ResourceSet resourceSet = new ModelSet();
+ resourceSet.getResources().add(resource);
+
+ // There should be a CacheAdapter
+ Assert.assertEquals(1, abstraction.eAdapters().size());
+
+ final ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ composedAdapterFactory.insertAdapterFactory(new InternationalizationUMLItemProviderAdapterFactory());
+
+ // Successive adaptations to IItemLabelProvider should always reveal the same provider
+ Adapter labelProviderAdapter1 = composedAdapterFactory.adapt(abstraction, IItemLabelProvider.class);
+ Assert.assertTrue(labelProviderAdapter1 instanceof IItemLabelProvider);
+ Assert.assertEquals(2, abstraction.eAdapters().size());
+ Adapter labelProviderAdapter2 = composedAdapterFactory.adapt(abstraction, IItemLabelProvider.class);
+ Assert.assertTrue(labelProviderAdapter2 instanceof IItemLabelProvider);
+ Assert.assertEquals(labelProviderAdapter1, labelProviderAdapter2);
+
+ Assert.assertEquals(2, abstraction.eAdapters().size());
+
+ }
+
+} \ No newline at end of file

Back to the top