Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » How to validate only part of model(How to validate only part of model)
How to validate only part of model [message #1842761] Wed, 30 June 2021 16:55 Go to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Hello

I need to validate only part of model.
Is it possible to pass list of root objects. In this case only parent object and references will be validated?

Thanks
Arseniy Isakov

Re: How to validate only part of model [message #1842771 is a reply to message #1842761] Thu, 01 July 2021 03:56 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Arseniy,

Do you run your EVL constraints using the Java API, through an Eclipse run configuration, the EVL/EMF validation extension point [1], or the EVL ANT task?

Best,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/evl-emf-integration/

[Updated on: Thu, 01 July 2021 03:56]

Report message to a moderator

Re: How to validate only part of model [message #1842848 is a reply to message #1842771] Fri, 02 July 2021 15:54 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Hi Dimitris

I am running EVL engine from my code.
I embedded it in my product building process.
So I am using java API outside of eclipse

Thanks
Arseniy Isakov

[Updated on: Fri, 02 July 2021 23:37]

Report message to a moderator

Re: How to validate only part of model [message #1842857 is a reply to message #1842848] Sat, 03 July 2021 08:33 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Arseniy,

You will need to subclass EvlModule to achieve this. I've shared an example showing how to do this in https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/plain/examples/org.eclipse.epsilon.examples.standalone/src/org/eclipse/epsilon/examples/standalone/evl/SelectiveEvlModule.java

Best,
Dimitris
Re: How to validate only part of model [message #1842930 is a reply to message #1842857] Tue, 06 July 2021 20:49 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Thanks Dimitris

It is work fine.
Another question is it possible to add global variables to EVL module using java API

Thanks
Arseniy Isakov

Re: How to validate only part of model [message #1842935 is a reply to message #1842930] Wed, 07 July 2021 05:42 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Aresniy,

That's good to hear! I've added an example showing how to pass global variables to Epsilon programs in [1].

Best,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/run-epsilon-from-java/#adding-variables
Re: How to validate only part of model [message #1842953 is a reply to message #1842935] Wed, 07 July 2021 15:43 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Hi Dimitris

		if (moduleElement instanceof ConstraintContext) {
		return new SelectiveConstraintContext();
		}


This condition never become true. So SelectiveConstraintContext object never return back. Is it connected with version. I am on 1.4

my evl file looks like this

 import "tura:/generation-templates/template/commons/typeElementUtil.eol";
 
 context type::Type {

   constraint Type{
      check : self.getAllRecipeMappers()
      message : 'Runtime constraint ' + self.name+" -->"
  } 

}

operation type::Type getAllRecipeMappers() : Boolean { 

    var type = self;

    if ( component.isKindOf(recipe::JavaScriptComponent)){
        return false;
    }
    if ( component.isKindOf(recipe::JavaComponent)){
          if ( ingredient.controllerLayer == null){
             type.mappingType2Java(recipe,ingredient,'MODEL');
             if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                     type.mappingType2Java(recipe,ingredient,'VIEW');
                     if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                         return true;
                     }
                return false;
             }
             return false;
          }else{
             type.mappingType2Java(recipe,ingredient);
            if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                  return true;
             }
             return false;
          }
    }    
    return false;
    
}

Re: How to validate only part of model [message #1842959 is a reply to message #1842953] Wed, 07 July 2021 19:30 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Actually it is not working for 2.3.2
Re: How to validate only part of model [message #1842962 is a reply to message #1842959] Thu, 08 July 2021 01:15 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Hi Dimitris

I found an issue

I have 2 files

first is mainTypeMappingValidationRules.evl
import "tura:/generation-templates/validation/rules/runtimeTypedefinitionValidationRules.evl";


second file runtimeTypedefinitionValidationRules.evl

 import "tura:/generation-templates/template/commons/typeElementUtil.eol";
 
 context type::Type {

   constraint Type{
      check : self.getAllRecipeMappers()
      message : 'Runtime constraint ' + self.name+" -->"
  } 

}

operation type::Type getAllRecipeMappers() : Boolean { 

    var type = self;

    if ( component.isKindOf(recipe::JavaScriptComponent)){
        return false;
    }
    if ( component.isKindOf(recipe::JavaComponent)){
          if ( ingredient.controllerLayer == null){
             type.mappingType2Java(recipe,ingredient,'MODEL');
             if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                     type.mappingType2Java(recipe,ingredient,'VIEW');
                     if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                         return true;
                     }
                return false;
             }
             return false;
          }else{
             type.mappingType2Java(recipe,ingredient);
            if (type.~mapper <> null  and  not type.~mapper.equals("NA") and  ( type.isKindOf(type::Primitive) or  ( not type.isKindOf(type::Primitive) and  type.~library <> null ) )){
                  return true;
             }
             return false;
          }
    }    
    return false;
    
}



if I parse with SelectiveEvlModule first file
code below never fires
		if (moduleElement instanceof ConstraintContext) {
			return new SelectiveConstraintContext();
		}







Re: How to validate only part of model [message #1842966 is a reply to message #1842962] Thu, 08 July 2021 07:50 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Arseniy,

Could you please put together a minimal example [1] that I can use to reproduce the issue you're encountering and investigate?

Best,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: How to validate only part of model [message #1842971 is a reply to message #1842966] Thu, 08 July 2021 10:38 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
Hi Dimitris

See an archive.

Thanks
Arseniy Isakov
Re: How to validate only part of model [message #1842975 is a reply to message #1842971] Thu, 08 July 2021 11:20 Go to previous messageGo to next message
Arseniy Isakov is currently offline Arseniy IsakovFriend
Messages: 118
Registered: May 2012
Senior Member
So your final example has to look like this


package org.eclipse.epsilon.examples.standalone.evl;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.epsilon.common.module.ModuleElement;
import org.eclipse.epsilon.common.parse.AST;
import org.eclipse.epsilon.common.parse.problem.ParseProblem;
import org.eclipse.epsilon.emc.emf.InMemoryEmfModel;
import org.eclipse.epsilon.eol.exceptions.models.EolModelElementTypeNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelNotFoundException;
import org.eclipse.epsilon.evl.EvlModule;
import org.eclipse.epsilon.evl.dom.ConstraintContext;
import org.eclipse.epsilon.evl.execute.context.IEvlContext;

/**
 * Demonstrates subclassing EvlModule to only check constraints against a
 * selection of model elements
 */

public class SelectiveEvlModule extends EvlModule {

//*********************************************************************************
protected static List<EObject> rootEObjects;
//*********************************************************************************



	@Override
	public ModuleElement adapt(AST cst, ModuleElement parentAst) {
		ModuleElement moduleElement = super.adapt(cst, parentAst);
		if (moduleElement instanceof ConstraintContext) {
			return new SelectiveConstraintContext();
		}
		return moduleElement;
	}



//*********************************************************************************
	public HashMap<String, Class<?>> getImportConfiguration() {
		HashMap<String, Class<?>> importConfiguration = super.getImportConfiguration();
		importConfiguration.put("evl", SelectiveEvlModule.class);
		return importConfiguration;
	}	
//*********************************************************************************
	

	class SelectiveConstraintContext extends ConstraintContext {
		@Override
		public Collection<?> getAllOfSourceKind(IEvlContext context)
				throws EolModelElementTypeNotFoundException, EolModelNotFoundException {
			// Only return a subset containing elements which are
			// descendants of one of the root objects
			return super.getAllOfSourceKind(context).stream().filter(e -> shouldCheck(e)).collect(Collectors.toList());
		}
	}

	protected boolean shouldCheck(Object object) {
		// Only check elements which are decendants of one of the
		// root objects
		return EcoreUtil.isAncestor(rootEObjects, (EObject) object);
	}

	public void setRootEObjects(List<EObject> rootEObjects) {
		this.rootEObjects = rootEObjects;
	}

	public List<EObject> getRootEObjects() {
		return rootEObjects;
	}

	public static void main(String[] args) throws Exception {

		SelectiveEvlModule module = new SelectiveEvlModule();

		ResourceSetImpl resourceSet = new ResourceSetImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
		Resource resource = resourceSet.createResource(URI.createURI("foo.ecore"));
		resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);

		// Create 2 classes C1 and C2 with one attribute each
		EClass c1 = EcoreFactory.eINSTANCE.createEClass();
		c1.setName("C1");
		EAttribute a1 = EcoreFactory.eINSTANCE.createEAttribute();
		a1.setName("a1");
		c1.getEStructuralFeatures().add(a1);

		EClass c2 = EcoreFactory.eINSTANCE.createEClass();
		c2.setName("C2");
		EAttribute a2 = EcoreFactory.eINSTANCE.createEAttribute();
		a2.setName("a2");
		c2.getEStructuralFeatures().add(a2);

		resource.getContents().add(c1);
		resource.getContents().add(c2);

		InMemoryEmfModel model = new InMemoryEmfModel(resource);

		// Constraint for EAttibute
		module.parse(new File("mainRules.evl"));
		if (module.getParseProblems().size() > 0) {
			for (ParseProblem problem : module.getParseProblems()) {
				System.out.println(problem.toString());
			}
			return;
		}
		
		
		module.getContext().getModelRepository().addModel(model);

		// Only elements under C1 (i.e. attribute a1) should be checked
		module.setRootEObjects(Arrays.asList(c1));

		module.execute();
	}

}

Re: How to validate only part of model [message #1842976 is a reply to message #1842975] Thu, 08 July 2021 11:25 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Indeed - I was just about to reply with the same solution but you beat me to it :)

Best,
Dimitris
Previous Topic:Multiple object type assignment to one object type
Next Topic:Element shown twice in target metamodel
Goto Forum:
  


Current Time: Wed Apr 24 15:58:13 GMT 2024

Powered by FUDForum. Page generated in 0.03703 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top