Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2018-09-25 07:57:22 -0400
committerQuentin Le Menez2018-11-12 10:12:40 -0500
commit9772ea957acd5bd1aee9432f184479688d04c907 (patch)
tree58de41556b81c578b9be95bbe586317421b3a28d
parentc05fd538d64a06c765fee0d1289e006623d258c9 (diff)
downloadorg.eclipse.papyrus-9772ea957acd5bd1aee9432f184479688d04c907.tar.gz
org.eclipse.papyrus-9772ea957acd5bd1aee9432f184479688d04c907.tar.xz
org.eclipse.papyrus-9772ea957acd5bd1aee9432f184479688d04c907.zip
Bug 536144 - [EMF Facet] validation of a custom file must be improved
- Add classes to validate custom files. Change-Id: I2ca6c2cd377bd9fd94012f65bb7605c19f4ad354 Signed-off-by: Patrick Tessier <patrick.tessier@cea.fr>
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/.classpath1
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/META-INF/MANIFEST.MF4
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/pom.xml2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java48
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/EFacetValidator.java99
5 files changed, 152 insertions, 2 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/.classpath b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/.classpath
index 1bdc2a0ba05..d4da2f8873d 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/.classpath
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/.classpath
@@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/META-INF/MANIFEST.MF b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/META-INF/MANIFEST.MF
index b86968ff295..39b1b9bcdc8 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/META-INF/MANIFEST.MF
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/META-INF/MANIFEST.MF
@@ -25,9 +25,11 @@ Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 1.3.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.papyrus.emf.facet.efacet.metamodel;singleton:=true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Automatic-Module-Name: org.eclipse.papyrus.emf.facet.efacet.metamodel
+Bundle-Activator: org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.internal.Activator
+
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/pom.xml b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/pom.xml
index 2e9a3dd9c39..aef0d5aab7c 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/pom.xml
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/pom.xml
@@ -8,6 +8,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.emf.facet.efacet.metamodel</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java
new file mode 100644
index 00000000000..216ce60ff1c
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/Activator.java
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.internal;
+
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetPackage;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+
+public class Activator implements BundleActivator {
+
+ /**
+ * this method is overloaded in order to launch the validator
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ *
+ * @param arg0
+ * @throws Exception
+ */
+ public void start(BundleContext arg0) throws Exception {
+ EValidator.Registry.INSTANCE.put
+ (EFacetPackage.eINSTANCE,
+ new EValidator.Descriptor() {
+ public EValidator getEValidator() {
+ return EFacetValidator.eInstance;
+ }
+ });
+
+ }
+
+ public void stop(BundleContext arg0) throws Exception {
+
+ }
+
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/EFacetValidator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/EFacetValidator.java
new file mode 100644
index 00000000000..3078efd05bb
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.efacet.metamodel/src/org/eclipse/papyrus/emf/facet/efacet/metamodel/v0_2_0/efacet/internal/EFacetValidator.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.internal;
+
+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.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EObjectValidator;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetPackage;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+
+/**
+ * This class is is used to overload the validator of a file EMF facet
+ *
+ */
+public class EFacetValidator extends EObjectValidator {
+
+
+ /**
+ * the constant that reference the eOperation image of emf Facet
+ */
+ private static final String IMAGE_OVERRIDE = "image"; //$NON-NLS-1$
+ /**
+ * the constant that reference the eOperation label of emf Facet
+ */
+ private static final String LABEL_OVERRIDE = "label"; //$NON-NLS-1$
+ public static EFacetValidator eInstance= new EFacetValidator();
+
+ @Override
+ protected EPackage getEPackage() {
+ return EFacetPackage.eINSTANCE;
+ }
+ @Override
+ protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ switch (classifierID) {
+ case EFacetPackage.FACET_OPERATION:
+ return validateOperation((FacetOperation)value, diagnostics, context);
+ default:
+ return super.validate(classifierID, value, diagnostics, context);
+ }
+ }
+
+ private boolean validateOperation(FacetOperation facetOperation, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ if (!validate_NoCircularContainment(facetOperation, diagnostics, context)) return false;
+ boolean result = validate_EveryMultiplicityConforms(facetOperation, diagnostics, context);
+ if (result || diagnostics != null) result &= validateOperation_validate(facetOperation, diagnostics, context);
+ return result;
+ }
+ /**
+ * This method validate an operation in the facet on order to be successful understood by the EMF FACET engine
+ * @param facetOperation
+ * @param diagnostics
+ * @param context
+ * @return a boolean by taking in account the kind of the operation
+ */
+ private boolean validateOperation_validate(FacetOperation facetOperation, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ boolean valid = true;
+ if (diagnostics != null) {
+ //here we test parameter by taking account the kind of override
+ if( facetOperation.getOverride()!=null) {
+ if (facetOperation.getOverride().getName().equals(LABEL_OVERRIDE)||
+ facetOperation.getOverride().getName().equals(IMAGE_OVERRIDE)) {
+ if (facetOperation.getEParameters().size()!=1) {
+ valid=false;
+ }
+ if (!((EClass)facetOperation.getEParameters().get(0).getEType()).equals(EcorePackage.eINSTANCE.getEReference())) {
+ diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR,
+ EFacetValidator.DIAGNOSTIC_SOURCE,
+ 1, "The operation "+facetOperation.getName()+" that overrides 'label'must have a parameter typed by EReference '", //$NON-NLS-1$ //$NON-NLS-2$
+ new Object[] { facetOperation }));
+ valid=false;
+ }
+ }
+ }
+ }
+ return valid;
+ }
+
+}

Back to the top