diff options
author | Camille Letavernier | 2020-11-12 16:48:34 +0000 |
---|---|---|
committer | Camille Letavernier | 2020-11-13 08:33:32 +0000 |
commit | 5fdc67349eaa04087e3d3e7613189042fc57d89e (patch) | |
tree | 2877796601504755c2d2f9578ad25b44a58b1bbf | |
parent | 74c4f07d88532accb8bda1d348a4df6c7722f2ec (diff) | |
download | org.eclipse.papyrus-bugs/568766-elementTypes.tar.gz org.eclipse.papyrus-bugs/568766-elementTypes.tar.xz org.eclipse.papyrus-bugs/568766-elementTypes.zip |
Bug 568766: [Toolsmiths] ElementTypes generation & validationbugs/568766-elementTypes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=568766
Add validation rules for the "ApplyToAllTypes" advice property
Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rwxr-xr-x | plugins/infra/types/org.eclipse.papyrus.infra.types/src/org/eclipse/papyrus/infra/types/validator/ElementTypesConfigurationsValidator.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types/src/org/eclipse/papyrus/infra/types/validator/ElementTypesConfigurationsValidator.java b/plugins/infra/types/org.eclipse.papyrus.infra.types/src/org/eclipse/papyrus/infra/types/validator/ElementTypesConfigurationsValidator.java index 2b4f36e6e96..d672c95064e 100755 --- a/plugins/infra/types/org.eclipse.papyrus.infra.types/src/org/eclipse/papyrus/infra/types/validator/ElementTypesConfigurationsValidator.java +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types/src/org/eclipse/papyrus/infra/types/validator/ElementTypesConfigurationsValidator.java @@ -18,12 +18,16 @@ package org.eclipse.papyrus.infra.types.validator; import java.util.Collections; 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.EPackage; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EObjectValidator; import org.eclipse.papyrus.emf.validation.AbstractEObjectDependencyValidator; +import org.eclipse.papyrus.infra.types.AbstractAdviceBindingConfiguration; import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration; import org.eclipse.papyrus.infra.types.ElementTypesConfigurationsPackage; @@ -58,18 +62,55 @@ public class ElementTypesConfigurationsValidator extends AbstractEObjectDependen */ @Override protected boolean validate(int classifierID, Object object, DiagnosticChain diagnostics, Map<Object, Object> context) { - // strangely, I never entered in this method boolean result = super.validate(classifierID, object, diagnostics, context); switch (classifierID) { case ElementTypesConfigurationsPackage.ELEMENT_TYPE_SET_CONFIGURATION: result = result && validateElementTypeSetConfiguration((ElementTypeSetConfiguration) object, diagnostics, context); break; + case ElementTypesConfigurationsPackage.ABSTRACT_ADVICE_BINDING_CONFIGURATION: + result = result & validateTypeReference((AbstractAdviceBindingConfiguration) object, diagnostics, context); + break; default: // nothing to do } return result; } + /** + * @see org.eclipse.emf.ecore.util.EObjectValidator#getEPackage() + * + * @return + */ + @Override + protected EPackage getEPackage() { + return ElementTypesConfigurationsPackage.eINSTANCE; + } + + + /** + * @param object + * @param diagnostics + * @param context + * @return + */ + protected boolean validateTypeReference(AbstractAdviceBindingConfiguration object, DiagnosticChain diagnostics, Map<Object, Object> context) { + if (object.isApplyToAllTypes() && object.getTarget() != null) { + // Target will be ignored and should be null + String message = "applyToAllTypes is true, but the AdviceConfiguration has an ElementType target"; + BasicDiagnostic diag = new BasicDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE, 2, message, + new Object[] { object }); + diagnostics.add(diag); + return false; + } else if (!object.isApplyToAllTypes() && object.getTarget() == null) { + // Target was accidentally unset + String message = "applyToAllTypes is false, but the AdviceConfiguration doesn't have an ElementType target."; + BasicDiagnostic diag = new BasicDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE, 3, message, + new Object[] { object }); + diagnostics.add(diag); + return false; + } + return true; + } /** * |