diff options
author | Ansgar Radermacher | 2014-03-07 15:36:43 +0000 |
---|---|---|
committer | Ansgar Radermacher | 2014-03-07 15:39:38 +0000 |
commit | 8812639e3fcf949d67e43f9a53182ff241c329a5 (patch) | |
tree | fafff952bb3258327e5782778944aadf3fb4d032 /plugins | |
parent | 0ec296da99df678daac12c38adef223f39167b31 (diff) | |
download | org.eclipse.papyrus-8812639e3fcf949d67e43f9a53182ff241c329a5.tar.gz org.eclipse.papyrus-8812639e3fcf949d67e43f9a53182ff241c329a5.tar.xz org.eclipse.papyrus-8812639e3fcf949d67e43f9a53182ff241c329a5.zip |
Bug 413512 - [OCL for Papyrus] Papyrus does does not validate OCL constraints in Profiles for well formnedness
Diffstat (limited to 'plugins')
12 files changed, 136 insertions, 16 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EcoreDiagnostician.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EcoreDiagnostician.java index 25c89b5c292..0a06f3af747 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EcoreDiagnostician.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EcoreDiagnostician.java @@ -32,7 +32,16 @@ public class EcoreDiagnostician extends Diagnostician implements IPapyrusDiagnos protected AdapterFactory adapterFactory;
protected IProgressMonitor progressMonitor;
+ /**
+ * Create diagnostician with custom validator (that must subclass ECore validator)
+ * @param validatorAdapter custom validator adapter
+ */
+ public EcoreDiagnostician(EValidatorAdapter validatorAdapter) {
+ this.validatorAdapter = validatorAdapter;
+ }
+
public EcoreDiagnostician() {
+ validatorAdapter = new EValidatorAdapter();
}
public void initialize (final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor) {
@@ -40,7 +49,7 @@ public class EcoreDiagnostician extends Diagnostician implements IPapyrusDiagnos this.progressMonitor=progressMonitor;
}
- protected EValidatorAdapter validatorAdapter = new EValidatorAdapter();
+ protected EValidatorAdapter validatorAdapter;
@Override
public String getObjectLabel(EObject eObject) {
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/ValidationFunctions.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/ValidationFunctions.java index 553d5dfc013..efa81b4be64 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/ValidationFunctions.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/ValidationFunctions.java @@ -29,11 +29,11 @@ import org.eclipse.ui.PlatformUI; public class ValidationFunctions implements IDecorationSpecificFunctions { - public static final String error_co = "icons/etool16/error_co.gif"; + public static final String error_co = "icons/etool16/error_co.gif"; //$NON-NLS-1$ - public static final String warning_co = "icons/etool16/warning_co.gif"; + public static final String warning_co = "icons/etool16/warning_co.gif"; //$NON-NLS-1$ - public static final String info_co = "icons/etool16/info_co.gif"; + public static final String info_co = "icons/etool16/info_co.gif"; //$NON-NLS-1$ /** * Return the image descriptor associated with an validation marker @@ -104,7 +104,7 @@ public class ValidationFunctions implements IDecorationSpecificFunctions { public String getMessage(IPapyrusMarker marker) { // message is stored within marker - return marker.getAttribute(IPapyrusMarker.MESSAGE, ""); + return marker.getAttribute(IPapyrusMarker.MESSAGE, ""); //$NON-NLS-1$ } public int getPriority(IPapyrusMarker marker) { diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/commands/AbstractValidateCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/commands/AbstractValidateCommand.java index 33eadfffb1f..22358c24cc4 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/commands/AbstractValidateCommand.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/commands/AbstractValidateCommand.java @@ -96,7 +96,7 @@ abstract public class AbstractValidateCommand extends AbstractTransactionalComma super(domain, label, Collections.EMPTY_LIST); this.domain = domain; this.selectedElement = selectedElement; - this.diagnostician= diagnostician; + this.diagnostician = diagnostician; this.showUIfeedback = true; // default is true; } 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 da1ee1994bd..24f961c3cd2 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 @@ -5,8 +5,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.emf;bundle-version="2.6.0",
org.eclipse.uml2.uml;bundle-version="4.1.0",
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0"
-Export-Package: org.eclipse.papyrus.uml.service.validation.handler
+ org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
+ org.eclipse.ocl.examples.pivot;bundle-version="3.4.0"
+Export-Package: org.eclipse.papyrus.uml.service.validation,
+ org.eclipse.papyrus.uml.service.validation.handler
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0.qualifier
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/OCLEValidatorAdapter.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/OCLEValidatorAdapter.java new file mode 100644 index 00000000000..b12c5dd3b15 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/OCLEValidatorAdapter.java @@ -0,0 +1,83 @@ +/***************************************************************************** + * Copyright (c) 2005, 2013 IBM Corporation, 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: + * IBM - Initial API and implementation + * Christian W. Damus (CEA) - Target EObject must be the diagnostic's first data element + * + *****************************************************************************/ + + +package org.eclipse.papyrus.uml.service.validation; + +import java.util.Map; + +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.DiagnosticChain; +import org.eclipse.emf.validation.model.IConstraintStatus; +import org.eclipse.ocl.examples.pivot.uml.UMLOCLEValidator; +import org.eclipse.papyrus.infra.services.validation.EValidatorAdapter; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.OpaqueAction; +import org.eclipse.uml2.uml.OpaqueBehavior; +import org.eclipse.uml2.uml.OpaqueExpression; + + +/** + * An adapter that plugs the EMF Model Validation Service API into the + * {@link org.eclipse.emf.ecore.EValidator} API. + * <p> + * <strong>NOTE</strong> that this class was copied from the EMF Validation + * "Validation Adapter" example project as created by the EMF Validation SDK, + * and modified only to ensure that the {@link Diagnostic} created from an + * {@link IConstraintStatus} has the original validation target element as the + * first element of the {@linkplain Diagnostic#getData() data list} because the + * {@linkplain IConstraintStatus#getResultLocus() result locus} of a constraint + * status is an unordered set. + * </p> + * + * bug 405160 - avoid "false" errors by using the UMLValidator instead of EObjectValidator as base class + */ +public class OCLEValidatorAdapter + extends EValidatorAdapter { + + @Override + public boolean validateInstanceSpecification(InstanceSpecification instanceSpecification, + DiagnosticChain diagnostics, Map<Object, Object> context) { + if (!super.validateInstanceSpecification(instanceSpecification, diagnostics, context)) { + return false; + } + return UMLOCLEValidator.INSTANCE.validateInstanceSpecification(instanceSpecification, diagnostics, context); + } + + @Override + public boolean validateOpaqueAction(OpaqueAction opaqueAction, + DiagnosticChain diagnostics, Map<Object, Object> context) { + if (!super.validateOpaqueAction(opaqueAction, diagnostics, context)) { + return false; + } + return UMLOCLEValidator.INSTANCE.validateOpaqueAction(opaqueAction, diagnostics, context); + } + + @Override + public boolean validateOpaqueBehavior(OpaqueBehavior opaqueBehavior, + DiagnosticChain diagnostics, Map<Object, Object> context) { + if (!super.validateOpaqueBehavior(opaqueBehavior, diagnostics, context)) { + return false; + } + return UMLOCLEValidator.INSTANCE.validateOpaqueBehavior(opaqueBehavior, diagnostics, context); + } + + @Override + public boolean validateOpaqueExpression(OpaqueExpression opaqueExpression, + DiagnosticChain diagnostics, Map<Object, Object> context) { + if (!super.validateOpaqueExpression(opaqueExpression, diagnostics, context)) { + return false; + } + return UMLOCLEValidator.INSTANCE.validateOpaqueExpression(opaqueExpression, diagnostics, context); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/UMLDiagnostician.java b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/UMLDiagnostician.java index 3ebc492a721..407a2cdbc3d 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/UMLDiagnostician.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.validation/src/org/eclipse/papyrus/uml/service/validation/UMLDiagnostician.java @@ -33,9 +33,10 @@ import org.eclipse.uml2.uml.util.UMLUtil; public class UMLDiagnostician extends EcoreDiagnostician {
public UMLDiagnostician() {
+ super(new OCLEValidatorAdapter());
validateStereotype = false;
}
-
+
protected boolean doValidateStereotypeApplications(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
if (validateStereotype) {
// this function is called recursively. Avoid trying to obtain stereotype applications, if we are
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/META-INF/MANIFEST.MF b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/META-INF/MANIFEST.MF index bca18dbab5b..8fab5fb51f0 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/META-INF/MANIFEST.MF +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.7.0",
org.apache.log4j;bundle-version="1.2.15",
org.eclipse.papyrus.uml.xtext.integration.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0"
+ org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.service.validation;bundle-version="1.0.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0.qualifier
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/src/org/eclipse/papyrus/uml/textedit/constraintwithessentialocl/xtext/EssentialOCLEditorConfiguration.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/src/org/eclipse/papyrus/uml/textedit/constraintwithessentialocl/xtext/EssentialOCLEditorConfiguration.java index 72e34337304..7793c52791f 100644 --- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/src/org/eclipse/papyrus/uml/textedit/constraintwithessentialocl/xtext/EssentialOCLEditorConfiguration.java +++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.constraintwithessentialocl.xtext/src/org/eclipse/papyrus/uml/textedit/constraintwithessentialocl/xtext/EssentialOCLEditorConfiguration.java @@ -34,9 +34,9 @@ import org.eclipse.ocl.examples.pivot.ParserException; import org.eclipse.ocl.examples.pivot.utilities.BaseResource;
import org.eclipse.ocl.examples.pivot.utilities.PivotUtil;
import org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLRuntimeModule;
-import org.eclipse.papyrus.infra.services.validation.EcoreDiagnostician;
import org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand;
import org.eclipse.papyrus.infra.services.validation.commands.AsyncValidateSubtreeCommand;
+import org.eclipse.papyrus.uml.service.validation.UMLDiagnostician;
import org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration;
import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProvider;
import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProviderWithInit;
@@ -183,7 +183,7 @@ public class EssentialOCLEditorConfiguration extends DefaultXtextDirectEditorCon TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(semanticObject);
if (semanticObject instanceof Constraint) {
result.add(new UpdateConstraintCommand(editingDomain, (Constraint) semanticObject, newString));
- final AbstractValidateCommand validationCommand = new AsyncValidateSubtreeCommand(semanticObject, new EcoreDiagnostician());
+ final AbstractValidateCommand validationCommand = new AsyncValidateSubtreeCommand(semanticObject, new UMLDiagnostician());
validationCommand.disableUIFeedback();
result.add(validationCommand);
}
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF index 4cb1b462ab4..f1ac78167c2 100644 --- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF +++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.gef;bundle-version="3.9.0", org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0"
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.service.validation;bundle-version="1.0.0"
Export-Package: org.eclipse.papyrus.uml.xtext.integration
Bundle-Vendor: Eclipse Modeling Project
Bundle-Version: 1.0.0.qualifier
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java index 7afbf7b7436..e94d70bf73b 100644 --- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java +++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/DefaultXtextDirectEditorConfiguration.java @@ -36,9 +36,9 @@ import org.eclipse.jface.viewers.CellEditor; import org.eclipse.papyrus.extensionpoints.editors.configuration.DefaultDirectEditorConfiguration; import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration; import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration; -import org.eclipse.papyrus.infra.services.validation.EcoreDiagnostician; import org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand; import org.eclipse.papyrus.infra.services.validation.commands.AsyncValidateSubtreeCommand; +import org.eclipse.papyrus.uml.service.validation.UMLDiagnostician; import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter; import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProvider; import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementAdapter.IContextElementProviderWithInit; @@ -164,7 +164,7 @@ public abstract class DefaultXtextDirectEditorConfiguration extends DefaultDirec } else { result.add(createInvalidStringCommand(newString, semanticObject)); } - AbstractValidateCommand validationCommand = new AsyncValidateSubtreeCommand(semanticObject, new EcoreDiagnostician()); + AbstractValidateCommand validationCommand = new AsyncValidateSubtreeCommand(semanticObject, new UMLDiagnostician()); validationCommand.disableUIFeedback(); result.add(validationCommand); return result; diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/META-INF/MANIFEST.MF b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/META-INF/MANIFEST.MF index 146e6bf4cdd..94bb0359b93 100644 --- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/META-INF/MANIFEST.MF +++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/META-INF/MANIFEST.MF @@ -3,7 +3,11 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.9.0", org.eclipse.emf.ecore;bundle-version="2.9.0",
org.eclipse.emf.validation;bundle-version="1.7.0",
org.eclipse.uml2.uml;bundle-version="4.1.0",
- org.eclipse.papyrus.uml.xtext.integration.ui;bundle-version="1.0.0"
+ org.eclipse.papyrus.uml.xtext.integration.ui;bundle-version="1.0.0",
+ com.google.inject;bundle-version="3.0.0",
+ org.eclipse.xtext;bundle-version="2.5.1",
+ org.eclipse.jface;bundle-version="3.10.0",
+ org.eclipse.ui;bundle-version="3.106.0"
Export-Package: org.eclipse.papyrus.uml.xtext.integration.validation
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/plugin.xml b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/plugin.xml index 3b7c5bf747a..fecdb0836e0 100644 --- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/plugin.xml +++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.validation/plugin.xml @@ -33,6 +33,25 @@ class="uml.Element">
</target>
</constraint>
+ <constraint
+ class="org.eclipse.papyrus.uml.xtext.integration.validation.ValidateOCLViaXtext"
+ id="org.eclipse.papyrus.uml.xtext.integration.validation.ValidateOCLViaXtext"
+ isEnabledByDefault="true"
+ lang="Java"
+ mode="Batch"
+ name="Validate OCL constraints via xtext"
+ severity="ERROR"
+ statusCode="0">
+ <message>
+ A {0} OCL validation problems found
+ </message>
+ <description>
+ If xtext finds validation errors within a UML constraint
+ </description>
+ <target
+ class="uml.Element">
+ </target>
+ </constraint>
</constraints>
</constraintProvider>
</extension>
|