Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremie.tatibouet2020-04-27 13:56:47 +0000
committerJeremie Tatibouet2020-04-29 13:53:23 +0000
commit733818a64a99f824e70bd986f841726ba245215f (patch)
tree00f5f348aa96d4e032bdfdad47d8c8c6b818d193 /plugins
parentaf08594c53cb788d72a85efde41a2a567a61062b (diff)
downloadorg.eclipse.papyrus-733818a64a99f824e70bd986f841726ba245215f.tar.gz
org.eclipse.papyrus-733818a64a99f824e70bd986f841726ba245215f.tar.xz
org.eclipse.papyrus-733818a64a99f824e70bd986f841726ba245215f.zip
Bug 562363 - Constraints are evaluated only in a specific context
Change-Id: I33a266b011bf615ab6b9c69c40b4656a2432bde3 Signed-off-by: ptessier <patrick.tessier@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/META-INF/MANIFEST.MF7
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/pom.xml2
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/AbstractPapyrusValidationFilter.java87
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/UMLDiagnostician.java124
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLDiagnostician.java25
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLFilter.java34
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.validation/umlservicevalidation.usecases18
7 files changed, 271 insertions, 26 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.service.validation/META-INF/MANIFEST.MF
index e65a470cbea..fccd5e087bb 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.validation/META-INF/MANIFEST.MF
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/META-INF/MANIFEST.MF
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.uml.service.validation,
+ org.eclipse.papyrus.uml.service.validation.api,
org.eclipse.papyrus.uml.service.validation.internal;x-internal:=true,
org.eclipse.papyrus.uml.service.validation.oclpivot
Require-Bundle: org.eclipse.papyrus.infra.services.validation;bundle-version="[3.0.0,4.0.0)",
@@ -7,10 +8,12 @@ Require-Bundle: org.eclipse.papyrus.infra.services.validation;bundle-version="[3
org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="[3.0.0,4.0.0)",
org.eclipse.ocl.pivot.uml;bundle-version="[1.1.0,2.0.0)",
- org.eclipse.ocl.xtext.completeocl;bundle-version="1.1.0"
+ org.eclipse.ocl.xtext.completeocl;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.architecture;bundle-version="[2.1.0,3.0.0)",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="[3.2.0,4.0.0)"
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
-Bundle-Version: 2.1.0.qualifier
+Bundle-Version: 2.1.1.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.eclipse.papyrus.uml.service.validation.Activator
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/pom.xml b/plugins/uml/org.eclipse.papyrus.uml.service.validation/pom.xml
index 58cb74f3cb7..9a3e6109f34 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.validation/pom.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.service.validation</artifactId>
- <version>2.1.0-SNAPSHOT</version>
+ <version>2.1.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/AbstractPapyrusValidationFilter.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/AbstractPapyrusValidationFilter.java
new file mode 100644
index 00000000000..66678cd4c5a
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/AbstractPapyrusValidationFilter.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2020 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
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Tessie (CEA LIST) - Initial API and implementation
+ * Jeremie TATIBOUET (CEA LIST) jeremie.tatibouet@cea.fr
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.service.validation.api;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.services.validation.IValidationFilter;
+
+/**
+ * A Papyrus validation filter defines the conditions that must hold in order
+ * to enable a diagnostician. In particular, the Papyrus validation filter
+ * checks if the architecture enabled at validation time is the one expected
+ * by the diagnostician.
+ */
+public abstract class AbstractPapyrusValidationFilter implements IValidationFilter {
+
+ public AbstractPapyrusValidationFilter() {
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.validation.IValidationFilter#isApplicable(org.eclipse.emf.ecore.EObject)
+ *
+ * @param an
+ * element of the model to validate
+ *
+ * @return true if (1) the model element is not null, (2) contained in a resource that is itsel in a model set and (3) the current architecture is the expected one.
+ */
+ public boolean isApplicable(EObject element) {
+ boolean applicable = false;
+ if (element != null && element.eResource() != null && element.eResource().getResourceSet() instanceof ModelSet) {
+ Iterator<String> contextIt = getExpectedValidationContext().iterator();
+ while (!applicable && contextIt.hasNext()) {
+ applicable = checkContext(element, contextIt.next());
+ }
+ }
+ return applicable;
+ }
+
+ /**
+ * Check if the context is the one expected by the diagnotician owning this filter
+ *
+ * @param element
+ * - the context model element
+ *
+ * @param expectedContextID
+ *
+ * @return true if the context is the expected one and false otherwise
+ */
+ private boolean checkContext(final EObject element, final String expectedContextID) {
+ boolean applicable = false;
+ ArchitectureDescriptionUtils adUtils = new ArchitectureDescriptionUtils((ModelSet) element.eResource().getResourceSet());
+ MergedArchitectureContext architectureContext = adUtils.getArchitectureContext();
+ if (architectureContext != null) {
+ applicable = architectureContext.getId().equals(expectedContextID);
+ }
+ return applicable;
+ }
+
+ /**
+ * Get the expected context ID
+ *
+ * I this method add context where the filter shall be applied.
+ *
+ * @return context ID
+ */
+ public abstract List<String> getExpectedValidationContext();
+
+} \ No newline at end of file
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/UMLDiagnostician.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/UMLDiagnostician.java
new file mode 100644
index 00000000000..afa9738ad18
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/api/UMLDiagnostician.java
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2013, 2020 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
+ * Jeremie TATIBOUET (CEA LIST) jeremie.tatibouet@cea.fr
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.service.validation.api;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.papyrus.infra.services.validation.IPapyrusDiagnostician;
+import org.eclipse.papyrus.uml.service.validation.internal.OCLEValidatorAdapter;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * UML diagnostician is in charge on validating UML models.
+ */
+public class UMLDiagnostician implements IPapyrusDiagnostician {
+
+ /**
+ * Delegate diagnostician (not API)
+ */
+ private org.eclipse.papyrus.uml.service.validation.internal.UMLDiagnostician delegate;
+
+ /**
+ * When instantiated using this constructor, this diagnostician relies on the classic UML Validator provided by the UML implementation
+ */
+ public UMLDiagnostician() {
+ delegate = new org.eclipse.papyrus.uml.service.validation.internal.UMLDiagnostician(new OCLEValidatorAdapter((EValidator) EValidator.Registry.INSTANCE.get(UMLPackage.eINSTANCE)));
+ }
+
+ /**
+ *
+ * When instantiated using this constructor, the diagnostician relies on a user defined validator.
+ *
+ * @param validator
+ * - the validator to be used
+ */
+ public UMLDiagnostician(EValidator validator) {
+ delegate = new org.eclipse.papyrus.uml.service.validation.internal.UMLDiagnostician(new OCLEValidatorAdapter(validator));
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.validation.IPapyrusDiagnostician#initialize(org.eclipse.emf.common.notify.AdapterFactory, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void initialize(AdapterFactory adapterFactory, IProgressMonitor progressMonitor) {
+ delegate.initialize(adapterFactory, progressMonitor);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.validation.IPapyrusDiagnostician#createDefaultContext()
+ */
+ public Map<Object, Object> createDefaultContext() {
+ return delegate.createDefaultContext();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.services.validation.IPapyrusDiagnostician#createDefaultDiagnostic(org.eclipse.emf.ecore.EObject)
+ */
+ public BasicDiagnostic createDefaultDiagnostic(EObject eObject) {
+ return delegate.createDefaultDiagnostic(eObject);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
+ */
+ public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ return delegate.validate(eObject, diagnostics, context);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider#getObjectLabel(org.eclipse.emf.ecore.EObject)
+ */
+ public String getObjectLabel(EObject eObject) {
+ return delegate.getObjectLabel(eObject);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider#getFeatureLabel(org.eclipse.emf.ecore.EStructuralFeature)
+ */
+ public String getFeatureLabel(EStructuralFeature eStructuralFeature) {
+ return delegate.getFeatureLabel(eStructuralFeature);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider#getValueLabel(org.eclipse.emf.ecore.EDataType, java.lang.Object)
+ */
+ public String getValueLabel(EDataType eDataType, Object value) {
+ return delegate.getValueLabel(eDataType, value);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EClass, org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
+ */
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ return delegate.validate(eClass, eObject, diagnostics, context);
+ }
+
+ /**
+ * @see org.eclipse.emf.ecore.EValidator#validate(org.eclipse.emf.ecore.EDataType, java.lang.Object, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
+ */
+ public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ return delegate.validate(eDataType, value, diagnostics, context);
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLDiagnostician.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLDiagnostician.java
index 9a771bf41c6..8d59dfe2939 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLDiagnostician.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLDiagnostician.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010, 2013 CEA LIST.
+ * Copyright (c) 2010, 2013, 2020 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,6 +11,7 @@
*
* Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
* Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Contribution related to bug 410457, 410119 and 410059
+ * Jeremie TATIBOUET (CEA LIST) jeremie.tatibouet@cea.fr
*
*****************************************************************************/
package org.eclipse.papyrus.uml.service.validation.internal;
@@ -27,6 +28,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.ocl.pivot.internal.delegate.OCLDelegateDomain;
+import org.eclipse.papyrus.infra.services.validation.internal.EValidatorAdapter;
import org.eclipse.papyrus.infra.services.validation.internal.EcoreDiagnostician;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.UMLPackage;
@@ -43,6 +45,11 @@ public class UMLDiagnostician extends EcoreDiagnostician {
validateStereotype = false;
}
+ public UMLDiagnostician(EValidatorAdapter validatorAdapter) {
+ super(validatorAdapter);
+ validateStereotype = false;
+ }
+
@Override
public Map<Object, Object> createDefaultContext() {
Map<Object, Object> context = super.createDefaultContext();
@@ -54,7 +61,7 @@ public class UMLDiagnostician extends EcoreDiagnostician {
@Override
public BasicDiagnostic createDefaultDiagnostic(EObject eObject) {
- if (eObject == null || eObject.eResource() == null){
+ if (eObject == null || eObject.eResource() == null) {
return super.createDefaultDiagnostic(eObject);
}
ResourceSet resourceSet = eObject.eResource().getResourceSet();
@@ -66,10 +73,13 @@ public class UMLDiagnostician extends EcoreDiagnostician {
/**
* Explicitly validate stereotype applications.
- *
- * @param eObject the eObject to validate
- * @param diagnostics the diagnostic chain
- * @param context the context
+ *
+ * @param eObject
+ * the eObject to validate
+ * @param diagnostics
+ * the diagnostic chain
+ * @param context
+ * the context
* @return
*/
protected boolean doValidateStereotypeApplications(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
@@ -129,8 +139,7 @@ public class UMLDiagnostician extends EcoreDiagnostician {
d.getSeverity(), d.getSource(), d.getCode(), d.getMessage(), data));
}
return ok;
- }
- else {
+ } else {
return super.validate(eObject, diagnostics, context);
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLFilter.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLFilter.java
index cbf2fd5cc4f..60ad9f3e465 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLFilter.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/internal/UMLFilter.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
- *
+ * Copyright (c) 2016, 2020 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
@@ -10,29 +10,33 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ * Jeremie TATIBOUET (CEA LIST) jeremie.tatibouet@cea.fr
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.service.validation.internal;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.services.validation.IValidationFilter;
-import org.eclipse.uml2.uml.Element;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.infra.services.edit.context.TypeContext;
+import org.eclipse.papyrus.uml.service.validation.api.AbstractPapyrusValidationFilter;
/**
- * A filter that associates UML models with the UMLDiagnotician (it is
- * referenced from the plugin.xml)
+ * The UML filter enables a diagnotician to triggered on a UML Papyrus model using the UML architecture
*/
-public class UMLFilter implements IValidationFilter {
+public class UMLFilter extends AbstractPapyrusValidationFilter {
/**
- * @see org.eclipse.papyrus.infra.services.validation.IValidationFilter#isApplicable(org.eclipse.emf.ecore.EObject)
+ * Get the expected context ID
*
- * @param an
- * element of the model to validate
- * @return true, iff the element is a UML element
+ * @return context ID
*/
- public boolean isApplicable(EObject element) {
- return element instanceof Element;
+ @Override
+ public List<String> getExpectedValidationContext() {
+ List<String> architectureContext = new ArrayList<String>();
+ architectureContext.add(TypeContext.getDefaultContextId());
+ return architectureContext;
}
+
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/umlservicevalidation.usecases b/plugins/uml/org.eclipse.papyrus.uml.service.validation/umlservicevalidation.usecases
new file mode 100644
index 00000000000..082d7ab26ad
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/umlservicevalidation.usecases
@@ -0,0 +1,18 @@
+# Requirements defined for the uml.service.validation plug-in
+
+This plugin provides a base diagnostician for UML models.
+
+# General Requirements
+-----------------------
+Requirement: Req_001: Papyrus shall provide developers with the possibility to develop domain specific diagnosticians that may be based on the UML one.
+
+Code instructions:
+- Contribute a new diagnostician through the org.eclipse.papyrus.infra.services.validation.diagnosticians extension point
+ - Provide a new diagnostician (one should extend UMLDiagnostician)
+ - Provide a new filter for this diagnostician (one should extend AbstractPapyrusValidationFilter)
+
+
+Requirement: Req_002: Domain specific diagnosticians shall have the possibility to rely on a specific validator .
+
+Code instructions:
+- Proceed exactly as for Req_001 and in addition make sure that your diagnostician is instanciated using the constructor enabling to provide a specific EValidator

Back to the top