Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-07-23 16:28:20 +0000
committerChristian W. Damus2014-07-23 17:28:38 +0000
commita13e6218401a3fb253d73be037339e7a3ac5dcdd (patch)
treed6bd02cd4880259de37c12265def05bdf4fe8975
parentb478cf0d527b251b205240b8c649538433b76fac (diff)
downloadorg.eclipse.papyrus-a13e6218401a3fb253d73be037339e7a3ac5dcdd.tar.gz
org.eclipse.papyrus-a13e6218401a3fb253d73be037339e7a3ac5dcdd.tar.xz
org.eclipse.papyrus-a13e6218401a3fb253d73be037339e7a3ac5dcdd.zip
440108: [Properties] Warning decoration for name clash shown on nameless element
https://bugs.eclipse.org/bugs/show_bug.cgi?id=440108 Use the UML2 API for distinguishability of named elements to validate a prospective new element name. Includes JUnit tests for cases that were spurious warnings (different metaclass, not accounting for operation signature). Also unset names of elements instead of setting their names to empty strings. This uses a new UnsetRequest supported by the UML edit-helpers.
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/UnsetValueCommand.java62
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/requests/UnsetRequest.java74
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/DefaultEditHelper.java51
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java7
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/NamedElementValidator.java34
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/PapyrusObservableValue.java11
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/UnsettableStringValue.java48
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ResourceSetFixture.java34
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/uml/operations.uml14
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java7
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/NamedElementValidatorTest.java123
12 files changed, 422 insertions, 44 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
index 32781e6aa47..40d544625ea 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
@@ -7,6 +7,7 @@ Export-Package: org.eclipse.papyrus.infra.emf,
org.eclipse.papyrus.infra.emf.dialog,
org.eclipse.papyrus.infra.emf.providers,
org.eclipse.papyrus.infra.emf.providers.strategy,
+ org.eclipse.papyrus.infra.emf.requests,
org.eclipse.papyrus.infra.emf.resource,
org.eclipse.papyrus.infra.emf.utils
Require-Bundle: org.eclipse.ui,
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/UnsetValueCommand.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/UnsetValueCommand.java
new file mode 100644
index 00000000000..34f85125915
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/UnsetValueCommand.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.emf.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
+import org.eclipse.papyrus.infra.emf.requests.UnsetRequest;
+
+
+/**
+ * A command that unsets the value of a feature. Especially useful for explicitly {@link EStructuralFeature#isUnsettable() unsettable} features.
+ */
+public class UnsetValueCommand extends EditElementCommand {
+
+ private final EStructuralFeature feature;
+
+ /**
+ * Constructs a new command to set the value of a feature of a model
+ * element.
+ *
+ * @param request
+ * the set value request
+ */
+ public UnsetValueCommand(UnsetRequest request) {
+ super(request.getLabel(), request.getElementToEdit(), request);
+
+ this.feature = request.getFeature();
+ }
+
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ EObject elementToEdit = getElementToEdit();
+ if(elementToEdit == null) {
+ throw new ExecutionException("No element to edit"); //$NON-NLS-1$
+ }
+
+ elementToEdit.eUnset(feature);
+
+ return CommandResult.newOKCommandResult();
+ }
+
+ public boolean canExecute() {
+ EObject elementToEdit = getElementToEdit();
+ return (elementToEdit != null) && super.canExecute();
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/requests/UnsetRequest.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/requests/UnsetRequest.java
new file mode 100644
index 00000000000..0e74f95e99e
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/requests/UnsetRequest.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.emf.requests;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.emf.type.core.EditHelperContext;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
+
+
+/**
+ * A request to unset the value of a feature. Especially useful for explicitly {@link EStructuralFeature#isUnsettable() unsettable} features.
+ */
+public class UnsetRequest extends AbstractEditCommandRequest {
+
+ private final EObject elementToEdit;
+
+ private final EStructuralFeature feature;
+
+ public UnsetRequest(TransactionalEditingDomain editingDomain, EObject elementToEdit, EStructuralFeature feature) {
+ super(editingDomain);
+
+ this.elementToEdit = elementToEdit;
+ this.feature = feature;
+ }
+
+ public UnsetRequest(EObject elementToEdit, EStructuralFeature feature) {
+ this(TransactionUtil.getEditingDomain(elementToEdit), elementToEdit, feature);
+ }
+
+ public Object getEditHelperContext() {
+ IClientContext context = getClientContext();
+
+ if(context == null) {
+ return elementToEdit;
+ } else {
+ return new EditHelperContext(elementToEdit, context);
+ }
+ }
+
+ public EStructuralFeature getFeature() {
+ return feature;
+ }
+
+ public EObject getElementToEdit() {
+ return elementToEdit;
+ }
+
+ public List<? extends EObject> getElementsToEdit() {
+ if(elementToEdit != null) {
+ return Collections.singletonList(elementToEdit);
+ }
+
+ return Collections.emptyList();
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/DefaultEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/DefaultEditHelper.java
index 9db45b9f915..ce7e04ae4e6 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/DefaultEditHelper.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/DefaultEditHelper.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
+ * Copyright (c) 2010, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,56 +8,29 @@
*
* Contributors:
*
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
+ * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 440108
*
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.AbstractOperation;
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.edit.command.CommandParameter;
-import org.eclipse.emf.edit.command.CreateChildCommand;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-import org.eclipse.emf.workspace.CompositeEMFOperation;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
-import org.eclipse.gmf.runtime.emf.type.core.internal.EMFTypePlugin;
-import org.eclipse.gmf.runtime.emf.type.core.internal.l10n.EMFTypeCoreMessages;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.papyrus.commands.DestroyElementPapyrusCommand;
-import org.eclipse.papyrus.uml.service.types.Activator;
+import org.eclipse.papyrus.infra.emf.commands.UnsetValueCommand;
+import org.eclipse.papyrus.infra.emf.requests.UnsetRequest;
import org.eclipse.papyrus.uml.service.types.command.CreateEditBasedElementCommand;
/**
@@ -299,5 +271,16 @@ public class DefaultEditHelper extends AbstractEditHelper {
return result;
}
-
+ @Override
+ protected ICommand getInsteadCommand(IEditCommandRequest req) {
+ ICommand result = null;
+
+ if(req instanceof UnsetRequest) {
+ result = new UnsetValueCommand((UnsetRequest)req);
+ } else {
+ result = super.getInsteadCommand(req);
+ }
+
+ return result;
+ }
}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java
index 9d55be029ab..3405051dc38 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/UMLModelElement.java
@@ -9,6 +9,7 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 323802
+ * Christian W. Damus (CEA) - bug 440108
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.modelelement;
@@ -52,6 +53,7 @@ import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList;
import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue;
import org.eclipse.papyrus.uml.tools.databinding.ProvidedInterfaceObservableList;
import org.eclipse.papyrus.uml.tools.databinding.RequiredInterfaceObservableList;
+import org.eclipse.papyrus.uml.tools.databinding.UnsettableStringValue;
import org.eclipse.papyrus.uml.tools.providers.ConstrainedElementContentProvider;
import org.eclipse.papyrus.uml.tools.providers.UMLContainerContentProvider;
import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider;
@@ -127,6 +129,11 @@ public class UMLModelElement extends EMFModelElement {
return list;
}
+ if((feature == UMLPackage.Literals.NAMED_ELEMENT__NAME) && (domain != null)) {
+ // Empty string as a name is not useful, so we unset instead
+ return new UnsettableStringValue(getSource(featurePath), feature, domain);
+ }
+
IObservableValue value = domain == null ? EMFProperties.value(featurePath).observe(source) : new PapyrusObservableValue(getSource(featurePath), feature, domain);
return value;
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/NamedElementValidator.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/NamedElementValidator.java
index 69b1c09d70a..0799cd690eb 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/NamedElementValidator.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/NamedElementValidator.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -7,6 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 440108
*
*****************************************************************************/
@@ -49,13 +51,33 @@ public class NamedElementValidator extends AbstractUMLValidator {
}
if(this.source instanceof NamedElement) {
- Namespace ns = ((NamedElement)this.source).getNamespace();
+ final NamedElement self = (NamedElement)this.source;
+ final Namespace ns = self.getNamespace();
+
if(ns != null) {
- EList<NamedElement> listElement = ns.getMembers();
- for(NamedElement namedElement : listElement) {
- if(this.source != namedElement && string.equals(namedElement.getName())) {
- return warning("A NamedElement with the same name exists in the Namespace");
+ final boolean deliver = self.eDeliver();
+ final boolean wasSet = self.isSetName();
+ final String oldName = self.getName();
+
+ try {
+ // Set up the prospective name
+ self.eSetDeliver(false);
+ self.setName(string);
+
+ EList<NamedElement> listElement = ns.getMembers();
+ for(NamedElement namedElement : listElement) {
+ if((self != namedElement) && !self.isDistinguishableFrom(namedElement, ns)) {
+ return warning("Name is indistinguishable from another element in the Namespace");
+ }
}
+ } finally {
+ // Restore the current name
+ if(wasSet) {
+ self.setName(oldName);
+ } else {
+ self.unsetName();
+ }
+ self.eSetDeliver(deliver);
}
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/PapyrusObservableValue.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/PapyrusObservableValue.java
index 257cb87b64c..6ae25d3cfbf 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/PapyrusObservableValue.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/PapyrusObservableValue.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,8 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Thibault Le Ouay t.leouay@sherpa-eng.com - Add binding implementation
+ * Christian W. Damus (CEA) - bug 440108
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.databinding;
@@ -23,6 +25,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.databinding.EMFObservableValue;
@@ -106,7 +109,7 @@ public class PapyrusObservableValue extends EMFObservableValue implements Aggreg
cc.add(provider.getEditCommand(new DestroyElementRequest((TransactionalEditingDomain)domain, (EObject)oldValue, false)));
}
- cc.add(provider.getEditCommand(new SetRequest((TransactionalEditingDomain)domain, eObject, eStructuralFeature, value)));
+ cc.add(provider.getEditCommand(createSetRequest((TransactionalEditingDomain)domain, eObject, eStructuralFeature, value)));
return new GMFtoEMFCommandWrapper(cc);
}
@@ -116,6 +119,10 @@ public class PapyrusObservableValue extends EMFObservableValue implements Aggreg
return UnexecutableCommand.INSTANCE;
}
+
+ protected IEditCommandRequest createSetRequest(TransactionalEditingDomain domain, EObject owner, EStructuralFeature feature, Object value) {
+ return new SetRequest(domain, owner, feature, value);
+ }
/**
*
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/UnsettableStringValue.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/UnsettableStringValue.java
new file mode 100644
index 00000000000..f08a1e2138c
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/UnsettableStringValue.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.databinding;
+
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.infra.emf.requests.UnsetRequest;
+
+
+/**
+ * A specialized observable for string-valued attributes that are "unsettable" in the EMF sense, having a distinct unset state.
+ * For string features that have a {@code null} default, instead of accepting the empty string, the feature is simply unset so
+ * that it will be {@code null}.
+ */
+public class UnsettableStringValue extends PapyrusObservableValue {
+
+ public UnsettableStringValue(EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
+ super(eObject, eStructuralFeature, domain);
+ }
+
+ public UnsettableStringValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
+ super(realm, eObject, eStructuralFeature, domain);
+ }
+
+ @Override
+ protected IEditCommandRequest createSetRequest(TransactionalEditingDomain domain, EObject owner, EStructuralFeature feature, Object value) {
+ if("".equals(value) && (feature.getDefaultValue() == null)) { //$NON-NLS-1$
+ // Unset the string attribute instead of making it an empty string
+ return new UnsetRequest(owner, feature);
+ }
+ return super.createSetRequest(domain, owner, feature, value);
+ }
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ResourceSetFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ResourceSetFixture.java
new file mode 100644
index 00000000000..23b14c2a334
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ResourceSetFixture.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2014 CEA and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.junit.utils.rules;
+
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+
+
+/**
+ * A simple non-transactional {@link ResourceSet} fixture.
+ */
+public class ResourceSetFixture extends AbstractModelFixture<EditingDomain> {
+
+ public ResourceSetFixture() {
+ super();
+ }
+
+ protected EditingDomain createEditingDomain() {
+ return new AdapterFactoryEditingDomain(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE), new BasicCommandStack());
+ }
+}
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/uml/operations.uml b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/uml/operations.uml
new file mode 100644
index 00000000000..1a1c5af6a7d
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/uml/operations.uml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_KDi_EBKHEeShYZf612l-_w" name="operations">
+ <packageImport xmi:id="_cxcooBKHEeShYZf612l-_w">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
+ </packageImport>
+ <packagedElement xmi:type="uml:Class" xmi:id="_MubQ8BKHEeShYZf612l-_w" name="Foo">
+ <ownedOperation xmi:id="_PQtAcBKHEeShYZf612l-_w" name="nameMe"/>
+ <ownedOperation xmi:id="_RBIcQBKHEeShYZf612l-_w" name="doIt">
+ <ownedParameter xmi:id="_SPFdIBKHEeShYZf612l-_w" name="now">
+ <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolean"/>
+ </ownedParameter>
+ </ownedOperation>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
index 07105c0d3ce..8060dc4c426 100644
--- a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,8 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 440108
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.tests.tests;
@@ -17,7 +19,8 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({ ContentProviderTest.class, UMLStereotypePropertyContentProviderTest.class, DependencyManagementTest.class
+@SuiteClasses({ ContentProviderTest.class, UMLStereotypePropertyContentProviderTest.class, DependencyManagementTest.class, //
+NamedElementValidatorTest.class
})
public class AllTests {
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/NamedElementValidatorTest.java b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/NamedElementValidatorTest.java
new file mode 100644
index 00000000000..3960d530abe
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/NamedElementValidatorTest.java
@@ -0,0 +1,123 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.tools.tests.tests;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
+import org.eclipse.papyrus.junit.utils.rules.PluginResource;
+import org.eclipse.papyrus.junit.utils.rules.ResourceSetFixture;
+import org.eclipse.papyrus.junit.utils.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.uml.tools.databinding.NamedElementValidator;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.OperationOwner;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+
+/**
+ * Tests the {@link NamedElementValidator} class.
+ */
+@PluginResource("resources/uml/operations.uml")
+public class NamedElementValidatorTest extends AbstractPapyrusTest {
+
+ private static final String DOIT = "doIt";
+
+ @Rule
+ public final HouseKeeper houseKeeper = new HouseKeeper();
+
+ @Rule
+ public final ResourceSetFixture model = new ResourceSetFixture();
+
+ private Operation toBeNamed;
+
+ private NamedElementValidator fixture;
+
+ public NamedElementValidatorTest() {
+ super();
+ }
+
+ /**
+ * Tests that the validator detects indistinguishable elements.
+ */
+ @Test
+ public void testNameClash() {
+ Class foo = toBeNamed.getClass_();
+
+ // Create another just like it with the target name
+ Operation copy = EcoreUtil.copy(toBeNamed);
+ copy.setName("doIt");
+ foo.getOwnedOperations().add(copy);
+
+ // The validator detects it
+ assertValidationFails();
+ }
+
+ /**
+ * Tests that the validator correctly discriminates overloaded operations with different signatures.
+ */
+ @Test
+ public void testElementOfDifferentKindDoesNotClash() {
+ Class foo = toBeNamed.getClass_();
+
+ // Create an attribute named "doIt"
+ foo.createOwnedAttribute(DOIT, getPrimitiveType("Boolean"));
+
+ assertValidationPasses();
+ }
+
+ /**
+ * Tests that the validator correctly discriminates overloaded operations with different signatures.
+ */
+ @Test
+ public void testOverloadDoesNotClash() {
+ assertValidationPasses();
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void createFixture() {
+ toBeNamed = getOperation("nameMe");
+ houseKeeper.setField("fixture", new NamedElementValidator(toBeNamed));
+ }
+
+ Operation getOperation(String name) {
+ return ((OperationOwner)model.getModel().getOwnedType("Foo")).getOwnedOperation(name, null, null);
+ }
+
+ Type getPrimitiveType(String name) {
+ return (Type)model.getModel().getMember(name, false, UMLPackage.Literals.TYPE);
+ }
+
+ void assertValidationFails() {
+ IStatus status = fixture.validate(DOIT);
+ assertThat(status.getSeverity(), not(IStatus.OK));
+ }
+
+ void assertValidationPasses() {
+ IStatus status = fixture.validate(DOIT);
+ assertThat(status.getSeverity(), is(IStatus.OK));
+ }
+}

Back to the top