Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-12-15 12:29:32 +0000
committerAnsgar Radermacher2015-12-15 12:31:36 +0000
commit0011d5cbd8f0fd5a7f3edca3466e477b0f65a9ca (patch)
treebdb6332c0f149c511496e38ffa2bb1e07094aaf1 /plugins/infra/services/org.eclipse.papyrus.infra.services.validation
parent7750db682e6076f054470dcce56da2a3d1116a84 (diff)
downloadorg.eclipse.papyrus-0011d5cbd8f0fd5a7f3edca3466e477b0f65a9ca.tar.gz
org.eclipse.papyrus-0011d5cbd8f0fd5a7f3edca3466e477b0f65a9ca.tar.xz
org.eclipse.papyrus-0011d5cbd8f0fd5a7f3edca3466e477b0f65a9ca.zip
Bug 408215 - [OCL] Loaded Complete OCL resource does not contribute to validation
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.validation')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.validation/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java70
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EcoreDiagnostician.java170
3 files changed, 107 insertions, 136 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/META-INF/MANIFEST.MF
index d18112c3ed5..1d8d33f339c 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/META-INF/MANIFEST.MF
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/META-INF/MANIFEST.MF
@@ -17,8 +17,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.2.0",
org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.2.0",
- org.eclipse.uml2.uml;bundle-version="4.1.0"
+ org.eclipse.papyrus.infra.services.markerlistener;bundle-version="1.2.0"
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.2.0.qualifier
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
index 7fababa7de9..d5c4f2fc060 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/EValidatorAdapter.java
@@ -10,6 +10,7 @@
* Christian W. Damus (CEA) - Target EObject must be the diagnostic's first data element
* Benoit Maggi (CEA LIST) - Add an unique id as source for diagnostic
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 446865
+ * Ed Willink, Klaas Gadeyne, A. Radermacher - Remove hard-coded UML dependency - Bug 408215
*****************************************************************************/
@@ -28,17 +29,14 @@ 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.EValidator;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.validation.model.EvaluationMode;
import org.eclipse.emf.validation.model.IConstraintStatus;
import org.eclipse.emf.validation.model.IModelConstraint;
import org.eclipse.emf.validation.service.IBatchValidator;
import org.eclipse.emf.validation.service.IConstraintDescriptor;
import org.eclipse.emf.validation.service.ModelValidationService;
-import org.eclipse.uml2.uml.LiteralInteger;
-import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
-import org.eclipse.uml2.uml.MultiplicityElement;
-import org.eclipse.uml2.uml.ValueSpecification;
-import org.eclipse.uml2.uml.util.UMLValidator;
/**
@@ -51,7 +49,12 @@ import org.eclipse.uml2.uml.util.UMLValidator;
* bug 405160 - avoid "false" errors by using the UMLValidator instead of EObjectValidator as base class
*/
public class EValidatorAdapter
- extends UMLValidator {
+ implements EValidator {
+
+ /**
+ * The eValidator from the EMF EValidator Registry.
+ */
+ protected final EValidator registeredValidator;
/**
* Model Validation Service interface for batch validation of EMF elements.
@@ -62,15 +65,23 @@ public class EValidatorAdapter
* Initializes me.
*/
public EValidatorAdapter() {
+ this((EValidator) EValidator.Registry.INSTANCE.get(EcorePackage.eINSTANCE));
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param registeredValidator a validator to which the adapter will delegate validation requests
+ */
+ public EValidatorAdapter(EValidator registeredValidator) {
super();
-
+ this.registeredValidator = registeredValidator;
batchValidator = ModelValidationService.getInstance().newValidator(
EvaluationMode.BATCH);
batchValidator.setIncludeLiveConstraints(true);
batchValidator.setReportSuccesses(false);
}
- @Override
public boolean validate(EObject eObject, DiagnosticChain diagnostics,
Map<Object, Object> context) {
return validate(eObject.eClass(), eObject, diagnostics, context);
@@ -79,11 +90,10 @@ public class EValidatorAdapter
/**
* Implements validation by delegation to the EMF validation framework.
*/
- @Override
public boolean validate(EClass eClass, EObject eObject,
DiagnosticChain diagnostics, Map<Object, Object> context) {
// first, do whatever the basic EcoreValidator does
- super.validate(eClass, eObject, diagnostics, context);
+ registeredValidator.validate(eClass, eObject, diagnostics, context);
return batchValidate(eObject, diagnostics, context);
}
@@ -110,7 +120,6 @@ public class EValidatorAdapter
appendDiagnostics(status, diagnostics);
}
}
-
return status.isOK();
}
@@ -118,46 +127,9 @@ public class EValidatorAdapter
* Direct validation of {@link EDataType}s is not supported by the EMF
* validation framework; they are validated indirectly via the {@link EObject}s that hold their values.
*/
- @Override
public boolean validate(EDataType eDataType, Object value,
DiagnosticChain diagnostics, Map<Object, Object> context) {
- return super.validate(eDataType, value, diagnostics, context);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.uml2.uml.util.UMLValidator#validateMultiplicityElement_validateUpperGeLower(org.eclipse.uml2.uml.MultiplicityElement, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map)
- */
- @Override
- public boolean validateMultiplicityElement_validateUpperGeLower(MultiplicityElement multiplicityElement, DiagnosticChain diagnostics, Map<Object, Object> context) {
- boolean result = false;
- if (canCompareUpperGeLower(multiplicityElement)) {
- result = super.validateMultiplicityElement_validateUpperGeLower(multiplicityElement, diagnostics, context);
- }
-
- return result;
- }
-
- /**
- * This allows to define if the multiplicity element can compare the lower and the upper values (depending to the type of ValueSpecifications).
- *
- * @param eObject
- * The {@link EObject} to check.
- * @return <code>true</code> if the lower and upper can be compared (or if this is not a MultiplicityElement), <code>false</code> otherwise.
- */
- protected boolean canCompareUpperGeLower(final EObject eObject) {
- boolean result = true;
- if (eObject instanceof MultiplicityElement) {
- final MultiplicityElement multiplicityElement = (MultiplicityElement) eObject;
- ValueSpecification lower = multiplicityElement.getLowerValue();
- ValueSpecification upper = multiplicityElement.getUpperValue();
- if (!((lower instanceof LiteralInteger || lower instanceof LiteralUnlimitedNatural || lower == null)
- && (upper instanceof LiteralInteger || upper instanceof LiteralUnlimitedNatural || upper == null))) {
- result = false;
- }
- }
- return result;
+ return registeredValidator.validate(eDataType, value, diagnostics, context);
}
/**
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 8331962860d..5338d5e6edf 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
@@ -1,86 +1,86 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 CEA LIST.
- *
- *
- * 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
- *
- * CoPatrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.validation;
-
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.DiagnosticChain;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.Diagnostician;
-import org.eclipse.emf.ecore.util.EObjectValidator;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-
-/**
- * this is a generic diagnostician to validate Ecore model in papyrus
- *
- */
-public class EcoreDiagnostician extends Diagnostician implements IPapyrusDiagnostician {
-
- 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) {
- this.adapterFactory = adapterFactory;
- this.progressMonitor = progressMonitor;
- }
-
- protected EValidatorAdapter validatorAdapter;
-
- @Override
- public String getObjectLabel(EObject eObject) {
- if (adapterFactory != null && !eObject.eIsProxy())
- {
- IItemLabelProvider itemLabelProvider = (IItemLabelProvider) adapterFactory.adapt(eObject, IItemLabelProvider.class);
- if (itemLabelProvider != null) {
- return itemLabelProvider.getText(eObject);
- }
- }
- return super.getObjectLabel(eObject);
- }
-
- @Override
- public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
- assert (progressMonitor != null);
- progressMonitor.worked(1);
-
- // copied from superclass, difference: use EValidatorAdapter instead of first value from eValidatorRegistry
- // fix of bug 397518
-
- boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject;
- boolean result = validatorAdapter.validate(eClass, eObject, diagnostics, context);
- if ((result || diagnostics != null) && !circular)
- {
- result &= doValidateContents(eObject, diagnostics, context);
- }
- return result;
- }
-
-
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 CEA LIST.
+ *
+ *
+ * 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
+ *
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
+ * Ed Willink, Klaas Gadeyne, A. Radermacher - Remove hard-coded UML dependency - Bug 408215
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.validation;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.ecore.util.EObjectValidator;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+
+/**
+ * This is a generic diagnostician to validate Ecore model in Papyrus
+ *
+ */
+public class EcoreDiagnostician extends Diagnostician implements IPapyrusDiagnostician {
+
+ protected AdapterFactory adapterFactory;
+ protected IProgressMonitor progressMonitor;
+ protected EValidatorAdapter validatorAdapter;
+
+ /**
+ * 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((EValidator) EValidator.Registry.INSTANCE.get(EcorePackage.eINSTANCE));
+ }
+
+ public void initialize(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor) {
+ this.adapterFactory = adapterFactory;
+ this.progressMonitor = progressMonitor;
+ }
+
+ @Override
+ public String getObjectLabel(EObject eObject) {
+ if (adapterFactory != null && !eObject.eIsProxy())
+ {
+ IItemLabelProvider itemLabelProvider = (IItemLabelProvider) adapterFactory.adapt(eObject, IItemLabelProvider.class);
+ if (itemLabelProvider != null) {
+ return itemLabelProvider.getText(eObject);
+ }
+ }
+ return super.getObjectLabel(eObject);
+ }
+
+ @Override
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ assert (progressMonitor != null);
+ progressMonitor.worked(1);
+
+ // copied from superclass, difference: use EValidatorAdapter instead of first value from eValidatorRegistry
+ // fix of bug 397518
+
+ boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject;
+ boolean result = validatorAdapter.validate(eClass, eObject, diagnostics, context);
+ if ((result || diagnostics != null) && !circular)
+ {
+ result &= doValidateContents(eObject, diagnostics, context);
+ }
+ return result;
+ }
} \ No newline at end of file

Back to the top