From 3ac9b1501c10430c7ff6fcb341c3f0109aaea42b Mon Sep 17 00:00:00 2001 From: Benoit Maggi Date: Fri, 8 Aug 2014 11:25:23 +0200 Subject: Bug 441408 - [UmlRT] Add test for validations rules - add a test for the isActiveEntity rule - add a getter to get the diagnostic from the command - change the source to a unique id for the BasicDiagnostic comming from status Change-Id: I1f09e1d01fa9944675ea6c0ee872e6aa1011418c Signed-off-by: Benoit Maggi --- .../services/validation/EValidatorAdapter.java | 36 +++++++++++++++++----- .../commands/AbstractValidateCommand.java | 7 +++++ 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'plugins') 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 ffc8e2fa89a..04bcb5ebcf2 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 @@ -8,7 +8,7 @@ * Contributors: * IBM - Initial API and implementation * 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 *****************************************************************************/ @@ -29,7 +29,9 @@ import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; 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.util.UMLValidator; @@ -181,15 +183,35 @@ public class EValidatorAdapter } } else if (status instanceof IConstraintStatus) { IConstraintStatus constraintStatus = (IConstraintStatus) status; - diagnostics.add(new BasicDiagnostic( - status.getSeverity(), - status.getPlugin(), - status.getCode(), - status.getMessage(), - toArray(constraintStatus.getResultLocus(), constraintStatus.getTarget()))); + diagnostics.add(createBasicDiagnostic(status, constraintStatus)); } } + /** + * Create a basic diagnostic with an unique id as source + * @param status + * @param constraintStatus + * @return + */ + protected BasicDiagnostic createBasicDiagnostic(IStatus status, + IConstraintStatus constraintStatus) { + String source = status.getPlugin(); + IModelConstraint constraint = constraintStatus.getConstraint(); + if (constraint != null){ + IConstraintDescriptor descriptor = constraint.getDescriptor(); + if (descriptor != null) { + source = descriptor.getId(); + } + } + + return new BasicDiagnostic( + status.getSeverity(), + source, + status.getCode(), + status.getMessage(), + toArray(constraintStatus.getResultLocus(), constraintStatus.getTarget())); + } + /** * Converts a possibly unordered collection to a list that has a designated * {@code first} element. 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 34df185abac..628dee777d1 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 @@ -109,6 +109,13 @@ abstract public class AbstractValidateCommand extends AbstractTransactionalComma public void disableUIFeedback() { this.showUIfeedback = false; } + + /** + * @return + */ + public Diagnostic getDiagnostic() { + return diagnostic; + } /** * @return The resource on which markers should be applied. -- cgit v1.2.3