Skip to main content



      Home
Home » Modeling » Epsilon » [SOLVED] [ECL] how to call lazy rules
[SOLVED] [ECL] how to call lazy rules [message #1113767] Sat, 21 September 2013 13:50 Go to next message
Eclipse UserFriend
Hi,
I have a problem with lazy rules.... i didn't understand how to call them! Basing on the book they are called only in an indirect way with the matches built-in operation. Is there a way to call them by passing the involved elements or something like that?

[Updated on: Tue, 24 September 2013 05:28] by Moderator

Re: [ECL] how to call lazy rules [message #1113814 is a reply to message #1113767] Sat, 21 September 2013 15:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

To invoke a lazy rule in ECL for a model element you need to call its matches() operation (e.g. x.matches()).

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114195 is a reply to message #1113814] Sun, 22 September 2013 06:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Thank you for the answer. I've tried with matches operation but it seems to not work properly. Probably i made some mistakes by declaring the lazy rule. I'm comparing a model conforms to java metamodel (provided by modisco framework) and a model conform to a ecore metametamodel.
Here a piece of my code:

rule MatchEClassWithClassDeclaration
	match c : CustomModel!EClass
	with a : ApiModel!ClassDeclaration {
	
	compare {
		if (a.name.isSubstringOf(c.name) or c.name.isSubstringOf(a.name)){
			return true;
		} else {
			if(a.name.simComparison(c.name) or a.name.ws4jComparison(c.name))
				return true;
			else
				return false;
		}
	}
	
	do {
		var md : OrderedSet = a.bodyDeclarations.select(a : MethodDeclaration | true);
		var ea : OrderedSet = c.eAttributes;
		md.matches();
		ea.matches();
		
		for(m : MethodDeclaration in md ){
			m.matches();
		}
		
		for(e : MethodDeclaration in ea ){
				e.matches();
		}
		matchInfo.put("type","EClass-ClassDeclaration");
	}
}


@lazy
rule MatchEAttributeWithMethodDeclaration
	match c: CustomModel!EAttribute
	with a : ApiModel!MethodDeclaration{
	
	compare {
		return true;		
	}
	
	do {
		'test'.println();
		matchInfo.put("type","EAttribute-MethodDeclaration");
	}
	

}


As you can see i called the lazy rule multiple times without success. Model elements held by the two ordered set are MethodDeclarations and EAttributes elements respectively.
Re: [ECL] how to call lazy rules [message #1114198 is a reply to message #1114195] Sun, 22 September 2013 06:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

matches() needs a parameter - e.g. x.matches(y). In your case, x should be an instance of EAttribute and y and instance of MethodDeclaration.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114243 is a reply to message #1114198] Sun, 22 September 2013 08:18 Go to previous messageGo to next message
Eclipse UserFriend
Unfortunately i tried a similar solution before posting my previous answer without success, but i had forgotten to insert it inside my code.
The extra code placed inside the do block is:

for(m : MethodDeclaration in md ){
			for(e : MethodDeclaration in ea ){
				m.matches(e);
			}
		}


I think there is a mistake related with the instance references... i can't figure out what it's..
Re: [ECL] how to call lazy rules [message #1114246 is a reply to message #1114243] Sun, 22 September 2013 08:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

ea appears to be a collection of EAttributes so the following loop

for(e : MethodDeclaration in ea ){ ... }

should look like

for(e : EAttribute in ea ){ ... }

instead.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114347 is a reply to message #1114246] Sun, 22 September 2013 11:55 Go to previous messageGo to next message
Eclipse UserFriend
Thank you!
It was a terrible mistake by me! Now the lazy rule mechanism seems to works. Only another two questions: Are matchings provided by lazy rules inserted inside the matchtrace? When for example is invoked m.matches(e) m matches the element in the "match" and e the element in the "with", right?
Re: [ECL] how to call lazy rules [message #1114357 is a reply to message #1114347] Sun, 22 September 2013 12:12 Go to previous messageGo to next message
Eclipse UserFriend
No worries. Yes, this sounds correct.

Cheers,
Dimitris
Re: [ECL] how to call lazy rules [message #1114390 is a reply to message #1114357] Sun, 22 September 2013 13:24 Go to previous messageGo to next message
Eclipse UserFriend
ok everything seems to work fine accept matchtrace... matchings provided by lazy rules seem to not be included inside my matchtrace. Here it is my full code:

pre {
	var sim = new Native("org.ossmeter.repository.plugin.simmetrics.Simmetrics");
	var ws4j = new Native("org.ossmeter.repository.plugin.ws4j.Ws4j");
	 
}

operation String simComparison(other: String ) : Boolean {
	return sim.getSimilarity(self,other) > 0.8;
}

operation String ws4jComparison(other: String) : Boolean {
	return ws4j.getSimilarity(self,other) > 0.8; 
}


rule MatchEClassWithClassDeclaration
	match c : CustomModel!EClass
	with a : ApiModel!ClassDeclaration {
	
	compare {
		if (a.name.isSubstringOf(c.name) or c.name.isSubstringOf(a.name)){
			return true;
		} else {
			if(a.name.simComparison(c.name) or a.name.ws4jComparison(c.name))
				return true;
			else
				return false;
		}
	}
	
	do {
		var md : OrderedSet = a.bodyDeclarations.select(a : MethodDeclaration | true);
		var ea : OrderedSet = c.eAttributes;
		
		for(m : ApiModel!MethodDeclaration in md ){
			for(e : CustomModel!EAttribute in ea ){
				m.matches(e);
			}
		}
		matchInfo.put("type","EClass-ClassDeclaration");
	}
}


@lazy
rule MatchEAttributeWithMethodDeclaration
	match a : ApiModel!MethodDeclaration
	with c : CustomModel!EAttribute {
	
	compare {
		return true;	
	}
	
	do {
		c.eContainer.name.print();
		':'.print();
		c.name.print();
		'---'.print();
		a.eContainer.name.print();
		':'.print();
		a.name.println();
		matchInfo.put("type","EAttribute-MethodDeclaration");
	}
	

}


post{
	var count : Integer = 0;
	var size : Integer = matchTrace.matches.size();
	while(count < size){
		var current = matchTrace.matches[count];
		if(current.matching){
			current.info.get('type').print();
			' : '.print();
			current.left.name.print();
			' <--> '.print();
			current.right.name.println();
		}	
		count = count + 1;
	}
}
Re: [ECL] how to call lazy rules [message #1114437 is a reply to message #1114390] Sun, 22 September 2013 14:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

You're right - this is a bug [1]. It's been now fixed in the SVN and in the latest interim release [2].

Cheers,
Dimitris

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=417774
[2] http://download.eclipse.org/epsilon/interim/
Re: [ECL] how to call lazy rules [message #1114822 is a reply to message #1114437] Mon, 23 September 2013 04:55 Go to previous message
Eclipse UserFriend
Yes now it works!

Thanks!
Previous Topic:[SOLVED][EUGENIA] generate EMFText model
Next Topic:Eclipse Epsilon 64bit
Goto Forum:
  


Current Time: Wed Jul 23 05:46:47 EDT 2025

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

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

Back to the top