Loading plugins/org.etsi.mts.tdl.tx/src/org/etsi/mts/tdl/validation/TDLtxValidator.java +82 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,18 @@ */ package org.etsi.mts.tdl.validation; import java.net.URI; import java.net.URISyntaxException; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.ecore.util.EObjectValidator; import org.eclipse.epsilon.evl.emf.validation.CompositeEValidator; import org.eclipse.epsilon.evl.emf.validation.EvlValidator; import org.eclipse.xtext.validation.Check; import org.etsi.mts.tdl.TestConfiguration; import org.etsi.mts.tdl.tdlPackage; /** * This class contains custom validation rules. Loading @@ -10,8 +22,19 @@ package org.etsi.mts.tdl.validation; * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation */ public class TDLtxValidator extends AbstractTDLtxValidator { private static boolean initialised; static { // try { // init(); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } // public static final String INVALID_NAME = "invalidName"; public static final String INVALID_NAME = "invalidName"; // // @Check // public void checkGreetingStartsWithCapital(Greeting greeting) { Loading @@ -22,4 +45,62 @@ public class TDLtxValidator extends AbstractTDLtxValidator { // } // } public TDLtxValidator() { super(); try { init(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void init() throws Exception { if (initialised) { return; } //TODO: goes a bit in circles //TODO: extract into an activator or something? also as command //TODO: works in principle, occasionally causes hangs and strange errors though... System.out.println("init EVL validator"); // Assuming you have generated the metamodel code EPackage ePackage = tdlPackage.eINSTANCE; // Pass a model name if your script uses it // Pass a valid bundle ID as it used for reporting (if not in a plugin use your project name or similar) String modelName = ""; //This seems to be important! Otherwise strange hangs occur String bundleId = "org.etsi.mts.tdl.constraints"; URI evlScriptURI = new URI("platform:/plugin/"+bundleId+"/constraints/tdl-generated-ETSI-ES-203-119-1-V1.5.1-fixed.evl"); EvlValidator evlValidator = new EvlValidator( evlScriptURI, modelName , ePackage.getNsURI(), bundleId); evlValidator.setShowErrorDialog(false); EValidator existingValidator = EValidator.Registry.INSTANCE.getEValidator(ePackage); if (existingValidator instanceof CompositeEValidator) { ((CompositeEValidator) existingValidator).getDelegates().add(evlValidator); } else { if (existingValidator == null) { existingValidator = EObjectValidator.INSTANCE; } CompositeEValidator newValidator = new CompositeEValidator(); newValidator.getDelegates().add(existingValidator); newValidator.getDelegates().add(evlValidator); EValidator.Registry.INSTANCE.put(ePackage, newValidator); } } @Check public void checkConfigurationsStartWithCapital(TestConfiguration c) { if (!Character.isUpperCase(c.getName().charAt(0))) { warning("Name should start with a capital", tdlPackage.Literals.ELEMENT__NAME, INVALID_NAME); } } } Loading
plugins/org.etsi.mts.tdl.tx/src/org/etsi/mts/tdl/validation/TDLtxValidator.java +82 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,18 @@ */ package org.etsi.mts.tdl.validation; import java.net.URI; import java.net.URISyntaxException; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.ecore.util.EObjectValidator; import org.eclipse.epsilon.evl.emf.validation.CompositeEValidator; import org.eclipse.epsilon.evl.emf.validation.EvlValidator; import org.eclipse.xtext.validation.Check; import org.etsi.mts.tdl.TestConfiguration; import org.etsi.mts.tdl.tdlPackage; /** * This class contains custom validation rules. Loading @@ -10,8 +22,19 @@ package org.etsi.mts.tdl.validation; * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation */ public class TDLtxValidator extends AbstractTDLtxValidator { private static boolean initialised; static { // try { // init(); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } // public static final String INVALID_NAME = "invalidName"; public static final String INVALID_NAME = "invalidName"; // // @Check // public void checkGreetingStartsWithCapital(Greeting greeting) { Loading @@ -22,4 +45,62 @@ public class TDLtxValidator extends AbstractTDLtxValidator { // } // } public TDLtxValidator() { super(); try { init(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void init() throws Exception { if (initialised) { return; } //TODO: goes a bit in circles //TODO: extract into an activator or something? also as command //TODO: works in principle, occasionally causes hangs and strange errors though... System.out.println("init EVL validator"); // Assuming you have generated the metamodel code EPackage ePackage = tdlPackage.eINSTANCE; // Pass a model name if your script uses it // Pass a valid bundle ID as it used for reporting (if not in a plugin use your project name or similar) String modelName = ""; //This seems to be important! Otherwise strange hangs occur String bundleId = "org.etsi.mts.tdl.constraints"; URI evlScriptURI = new URI("platform:/plugin/"+bundleId+"/constraints/tdl-generated-ETSI-ES-203-119-1-V1.5.1-fixed.evl"); EvlValidator evlValidator = new EvlValidator( evlScriptURI, modelName , ePackage.getNsURI(), bundleId); evlValidator.setShowErrorDialog(false); EValidator existingValidator = EValidator.Registry.INSTANCE.getEValidator(ePackage); if (existingValidator instanceof CompositeEValidator) { ((CompositeEValidator) existingValidator).getDelegates().add(evlValidator); } else { if (existingValidator == null) { existingValidator = EObjectValidator.INSTANCE; } CompositeEValidator newValidator = new CompositeEValidator(); newValidator.getDelegates().add(existingValidator); newValidator.getDelegates().add(evlValidator); EValidator.Registry.INSTANCE.put(ePackage, newValidator); } } @Check public void checkConfigurationsStartWithCapital(TestConfiguration c) { if (!Character.isUpperCase(c.getName().charAt(0))) { warning("Name should start with a capital", tdlPackage.Literals.ELEMENT__NAME, INVALID_NAME); } } }