From 0011d5cbd8f0fd5a7f3edca3466e477b0f65a9ca Mon Sep 17 00:00:00 2001 From: Ansgar Radermacher Date: Tue, 15 Dec 2015 13:29:32 +0100 Subject: Bug 408215 - [OCL] Loaded Complete OCL resource does not contribute to validation Change-Id: I356190972a4af852a600147b4564925b3823b8e7 --- .../service/validation/OCLEValidatorAdapter.java | 94 ++++--- .../uml/service/validation/UMLDiagnostician.java | 273 +++++++++++---------- 2 files changed, 181 insertions(+), 186 deletions(-) (limited to 'plugins/uml') 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 index 7f8cf94dc23..d16ca2f0a81 100644 --- 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 @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Christian W. Damus (CEA) - Target EObject must be the diagnostic's first data element + * Ed Willink, Klaas Gadeyne, A. Radermacher - Bug 408215 * *****************************************************************************/ @@ -16,10 +17,13 @@ package org.eclipse.papyrus.uml.service.validation; import java.util.Map; +import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.emf.common.util.Diagnostic; 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.plugin.EcorePlugin; import org.eclipse.emf.ecore.util.EObjectValidator; import org.eclipse.emf.validation.model.IConstraintStatus; import org.eclipse.ocl.pivot.internal.delegate.OCLDelegateValidator; @@ -43,68 +47,58 @@ import org.eclipse.uml2.uml.OpaqueExpression; public class OCLEValidatorAdapter extends EValidatorAdapter { + /** + * Constructor. + * + */ + public OCLEValidatorAdapter(EValidator registeredValidator) { + super(registeredValidator); + } + // Overridden to invoke OCLDelegateValidator @Override public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map context) { if (eObject.eIsProxy()) { - if (context != null && context.get(ROOT_OBJECT) != null) { + if (context != null && context.get(EObjectValidator.ROOT_OBJECT) != null) { if (diagnostics != null) { - diagnostics.add(createDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE, - EOBJECT__EVERY_PROXY_RESOLVES, "_UI_UnresolvedProxy_diagnostic", - new Object[] { - getFeatureLabel(eObject.eContainmentFeature(), context), - getObjectLabel(eObject.eContainer(), context), - getObjectLabel(eObject, context) }, + diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE, + EObjectValidator.EOBJECT__EVERY_PROXY_RESOLVES, + // create message + EcorePlugin.INSTANCE.getString("_UI_UnresolvedProxy_diagnostic", //$NON-NLS-1$ + new Object[] { + EObjectValidator.getFeatureLabel(eObject.eContainmentFeature(), context), + EObjectValidator.getObjectLabel(eObject.eContainer(), context), + EObjectValidator.getObjectLabel(eObject, context) } + ), new Object[] { eObject.eContainer(), eObject.eContainmentFeature(), - eObject }, - context)); + eObject } + )); } } - } else if (eClass.eContainer() == getEPackage()) { - validate(eClass.getClassifierID(), eObject, diagnostics, context); - } else { - new OCLDelegateValidator(this) { + } + else if (EValidator.Registry.INSTANCE.get(eClass.eContainer()) == registeredValidator) { + if (eObject instanceof InstanceSpecification) { + UMLOCLEValidator.INSTANCE.validateInstanceSpecification((InstanceSpecification) eObject, diagnostics, context); + } + else if (eObject instanceof OpaqueAction) { + UMLOCLEValidator.INSTANCE.validateOpaqueAction((OpaqueAction) eObject, diagnostics, context); + } + else if (eObject instanceof OpaqueBehavior) { + return UMLOCLEValidator.INSTANCE.validateOpaqueBehavior((OpaqueBehavior) eObject, diagnostics, context); + } + else if (eObject instanceof OpaqueExpression) { + return UMLOCLEValidator.INSTANCE.validateOpaqueExpression((OpaqueExpression) eObject, diagnostics, context); + } + registeredValidator.validate(eClass, eObject, diagnostics, context); + } + else { + new OCLDelegateValidator(EObjectValidator.INSTANCE) { // Ensure that the class loader for this class will be used downstream. }.validate(eClass, eObject, diagnostics, context); } + return batchValidate(eObject, diagnostics, context); } - - @Override - public boolean validateInstanceSpecification(InstanceSpecification instanceSpecification, - DiagnosticChain diagnostics, Map 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 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 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 context) { - if (!super.validateOpaqueExpression(opaqueExpression, diagnostics, context)) { - return false; - } - return UMLOCLEValidator.INSTANCE.validateOpaqueExpression(opaqueExpression, diagnostics, context); - } -} +} \ No newline at end of file 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 ef1e107c13c..7ed41023470 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 @@ -1,136 +1,137 @@ -/***************************************************************************** - * 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 - * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Contribution related to bug 410457, 410119 and 410059 - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.service.validation; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.common.util.BasicDiagnostic; -import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.emf.common.util.DiagnosticChain; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.ocl.pivot.internal.delegate.OCLDelegateDomain; -import org.eclipse.papyrus.infra.services.validation.EcoreDiagnostician; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.util.UMLUtil; - -/** - * This is a specific diagnostician used to validate stereotype applications - * - */ -public class UMLDiagnostician extends EcoreDiagnostician { - - public UMLDiagnostician() { - super(new OCLEValidatorAdapter()); - validateStereotype = false; - } - - @Override - public Map createDefaultContext() { - Map context = super.createDefaultContext(); - if (context != null) { - OCLDelegateDomain.initializePivotOnlyDiagnosticianContext(context); - } - return context; - } - - @Override - public BasicDiagnostic createDefaultDiagnostic(EObject eObject) { - if (eObject == null || eObject.eResource() == null){ - return super.createDefaultDiagnostic(eObject); - } - ResourceSet resourceSet = eObject.eResource().getResourceSet(); - if (resourceSet != null) { - OCLDelegateDomain.initializePivotOnlyDiagnosticianResourceSet(resourceSet); - } - return super.createDefaultDiagnostic(eObject); - } - - /** - * Explicitly validate stereotype applications. - * - * @param eObject the eObject to validate - * @param diagnostics the diagnostic chain - * @param context the context - * @return - */ - protected boolean doValidateStereotypeApplications(EObject eObject, DiagnosticChain diagnostics, Map context) { - if (validateStereotype) { - // this function is called recursively. Avoid trying to obtain stereotype applications, if we are - // already examining a stereotype - return true; - } - List stereotypeApplications = eObject instanceof Element ? ((Element) eObject).getStereotypeApplications() : Collections. emptyList(); - if (!stereotypeApplications.isEmpty()) { - Iterator i = stereotypeApplications.iterator(); - validateStereotype = true; - boolean result = validate(i.next(), diagnostics, context); - while (i.hasNext() && (result || diagnostics != null)) { - result &= validate(i.next(), diagnostics, context); - } - validateStereotype = false; - return result; - } else { - return true; - } - } - - @Override - protected boolean doValidateContents(EObject eObject, DiagnosticChain diagnostics, Map context) { - boolean result = doValidateStereotypeApplications(eObject, diagnostics, context); - if (result || diagnostics != null) { - result &= super.doValidateContents(eObject, diagnostics, context); - } - return result; - } - - @Override - public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map context) { - if (!context.containsKey(this)) { - // put instance of the UMLDiagnostician into context map to identify first invocation - // (validate is called recursively) - context.put(this, null); - BasicDiagnostic newDiagChain = createDefaultDiagnostic(eObject); - boolean ok = super.validate(eObject, newDiagChain, context); - // replace markers here instead of using a validation adapter, see - // bug 410457 - [Validation] Ghost markers when validating profile constraints - // bug 410119 - [Validation] markers related to stereotype applications are not updated in diagrams - // bug 410059 - [Validation] delete subtree does not remove markers associated with stereotypes - for (Diagnostic d : newDiagChain.getChildren()) { - Object data[] = d.getData().toArray(); - if (data.length > 0) { - Object target = data[0]; - if (target instanceof EObject) { - EObject base = UMLUtil.getBaseElement((EObject) target); - if (base != null) { - data[0] = base; - } - } - } - diagnostics.add(new BasicDiagnostic( - d.getSeverity(), d.getSource(), d.getCode(), d.getMessage(), data)); - } - return ok; - } - else { - return super.validate(eObject, diagnostics, context); - } - } - - protected boolean validateStereotype; - -} +/***************************************************************************** + * 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 + * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Contribution related to bug 410457, 410119 and 410059 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.service.validation; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.DiagnosticChain; +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.EcoreDiagnostician; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * This is a specific diagnostician used to validate stereotype applications + * + */ +public class UMLDiagnostician extends EcoreDiagnostician { + + public UMLDiagnostician() { + super(new OCLEValidatorAdapter((EValidator) EValidator.Registry.INSTANCE.get(UMLPackage.eINSTANCE))); + validateStereotype = false; + } + + @Override + public Map createDefaultContext() { + Map context = super.createDefaultContext(); + if (context != null) { + OCLDelegateDomain.initializePivotOnlyDiagnosticianContext(context); + } + return context; + } + + @Override + public BasicDiagnostic createDefaultDiagnostic(EObject eObject) { + if (eObject == null || eObject.eResource() == null){ + return super.createDefaultDiagnostic(eObject); + } + ResourceSet resourceSet = eObject.eResource().getResourceSet(); + if (resourceSet != null) { + OCLDelegateDomain.initializePivotOnlyDiagnosticianResourceSet(resourceSet); + } + return super.createDefaultDiagnostic(eObject); + } + + /** + * Explicitly validate stereotype applications. + * + * @param eObject the eObject to validate + * @param diagnostics the diagnostic chain + * @param context the context + * @return + */ + protected boolean doValidateStereotypeApplications(EObject eObject, DiagnosticChain diagnostics, Map context) { + if (validateStereotype) { + // this function is called recursively. Avoid trying to obtain stereotype applications, if we are + // already examining a stereotype + return true; + } + List stereotypeApplications = eObject instanceof Element ? ((Element) eObject).getStereotypeApplications() : Collections. emptyList(); + if (!stereotypeApplications.isEmpty()) { + Iterator i = stereotypeApplications.iterator(); + validateStereotype = true; + boolean result = validate(i.next(), diagnostics, context); + while (i.hasNext() && (result || diagnostics != null)) { + result &= validate(i.next(), diagnostics, context); + } + validateStereotype = false; + return result; + } else { + return true; + } + } + + @Override + protected boolean doValidateContents(EObject eObject, DiagnosticChain diagnostics, Map context) { + boolean result = doValidateStereotypeApplications(eObject, diagnostics, context); + if (result || diagnostics != null) { + result &= super.doValidateContents(eObject, diagnostics, context); + } + return result; + } + + @Override + public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map context) { + if (!context.containsKey(this)) { + // put instance of the UMLDiagnostician into context map to identify first invocation + // (validate is called recursively) + context.put(this, null); + BasicDiagnostic newDiagChain = createDefaultDiagnostic(eObject); + boolean ok = super.validate(eObject, newDiagChain, context); + // replace markers here instead of using a validation adapter, see + // bug 410457 - [Validation] Ghost markers when validating profile constraints + // bug 410119 - [Validation] markers related to stereotype applications are not updated in diagrams + // bug 410059 - [Validation] delete subtree does not remove markers associated with stereotypes + for (Diagnostic d : newDiagChain.getChildren()) { + Object data[] = d.getData().toArray(); + if (data.length > 0) { + Object target = data[0]; + if (target instanceof EObject) { + EObject base = UMLUtil.getBaseElement((EObject) target); + if (base != null) { + data[0] = base; + } + } + } + diagnostics.add(new BasicDiagnostic( + d.getSeverity(), d.getSource(), d.getCode(), d.getMessage(), data)); + } + return ok; + } + else { + return super.validate(eObject, diagnostics, context); + } + } + + protected boolean validateStereotype; +} -- cgit v1.2.3