Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF-IncQuery » Find and count elements of certain type inside a element
Find and count elements of certain type inside a element [message #1395286] Sun, 06 July 2014 17:57 Go to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi,

I have to write a query in Incquery, that finds elements of certain types inside an element.
In a Java Query I use either allContents or the getChildenByEType() method of the JaMoPP metamodel.

The concrete example for the JaMoPP metamodel:

Inside a method all elements of type
-ForLoop
-WhileLoop
-Condition
-CatchBlock
-...

must be found.

The query should only return the methods, that contain more than four elements of this.
I know this works using the count statement.

The method class has a method "getChildenByEType(EClass)" or getChildrenByType(Class).
But I cannot call this method in an Incquery query.

Is there any way to solve this problem with Incquery?

Thanks, Mario
Re: Find and count elements of certain type inside a element [message #1395658 is a reply to message #1395286] Mon, 07 July 2014 07:58 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 262
Registered: July 2015
Senior Member
Hi Mario,

sadly, you have found an important limitation of our query language: there is no way to express constraints over the containment hierarchy; and we do not allow calling methods/EOperations on EClasses in check/eval expressions.

The main reason for these limitations are two-folds:
1. Incrementally indexing the containment hierarchy (especially transitively) is really expensive in terms of both memory usage and initialization time.
2. Our indexing only behaves correctly when all called operations/methods are pure functions (in the functional sense). The most important thing that must not be called from check expressions are value getters, and until now we have approximated this by removing the support for calling any method/operation on EClasses. This is not the best/final solution, but we couldn't come up with something better until now.

I can suggest only a single (ugly) workaround for short-term solution: create a pattern, that enumerates all possible children of a node, and then use the transitive closure of this pattern. For performance and resource usage, try to use as few relations as possible for your case. We have (an unfinished) example of this kind available in the following (JaMoPP-based) example: https://github.com/ujhelyiz/viatra2-programunderstanding/blob/master/transformation/hu.bme.mit.viatra2.examples.reveng/src/hu/bme/mit/viatra2/examples/reveng/queries.eiq - look at the belowStatement and statementInPattern patterns.

For longer term, we are already working on an alternative query strategy, that instead of indexing matches uses a search-based strategy that we already tested to support these use cases, but is not yet ready for external usage. If this algorithm is finished, we are planning to fine-tune the query language to support a wider range of use cases. See the https://bugs.eclipse.org/bugs/show_bug.cgi?id=406073 tracking bug for the state of this approach.

Cheers,
Zoltán
Re: Find and count elements of certain type inside a element [message #1395807 is a reply to message #1395658] Mon, 07 July 2014 12:20 Go to previous messageGo to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 136
Registered: July 2009
Senior Member
What about this:

package test

import "http://www.emftext.org/java/statements"
import "http://www.emftext.org/java/members"
import "http://www.emftext.org/java/containers"
import "http://www.emftext.org/java"
import "http://www.emftext.org/java/instantiations"

pattern findMethod(method : ClassMethod) {
countForLoop == count find findForLoop(method, _forLoop);
countWhileLoop == count find findWhileLoop(method, _whileLoop);
countConditions == count find findCondition(method, _conditions);
sum == eval(countForLoop + countWhileLoop + countConditions);
check(sum >= 4);
}

private pattern findForLoop(method: ClassMethod, loop : ForLoop){
find findSomethingTransitively(method, loop);
}

private pattern findWhileLoop(method: ClassMethod, loop : WhileLoop){
find findSomethingTransitively(method, loop);
}

private pattern findCondition(method: ClassMethod, condition : Condition){
find findSomethingTransitively(method, condition);
}

private pattern findSomethingTransitively(container, child){
find findSomething+(container, child);
}

private pattern findSomething(container, child){
StatementListContainer.statements(container, child);
} or {
StatementContainer.statement(container, child);
} or {
Switch.cases(container, caseBlock);
SwitchCase.statements(caseBlock, child);
} or {
TryBlock.catcheBlocks(container, catchBlock);
CatchBlock.statements(catchBlock, child);
} or {
Condition.elseStatement(container, child);
}
Re: Find and count elements of certain type inside a element [message #1693306 is a reply to message #1395807] Thu, 23 April 2015 06:35 Go to previous messageGo to next message
Pulkit Manocha is currently offline Pulkit ManochaFriend
Messages: 7
Registered: April 2015
Junior Member
Is there any way to use count without calling another pattern?
for example instead of writing two patterns to count some attribute, can I somehow merge them into one?:


pattern Countentries(obj,e)={
      MyObject.entries(obj,e);
}

pattern checkcount(obj)={
   MyObject(obj);
   N= count find Countentries(obj,_e);
   check(N>5);
}




Instead of the above, is there any alternative to write just one pattern that achieves the same result?
Re: Find and count elements of certain type inside a element [message #1693314 is a reply to message #1693306] Thu, 23 April 2015 06:56 Go to previous message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 124
Registered: July 2009
Senior Member
Quote:
Is there any way to use count without calling another pattern?


No, the current version of the pattern language only allows count on subpattern calls.

You can open a Bugzilla issue for an enhancement and we will see if such a syntactic sugar could be added sometime.
Previous Topic:UML Incquery pattern : constrain to particular model name
Next Topic:Transitive Closure for IncQuery Patterns at Runtime
Goto Forum:
  


Current Time: Fri Aug 28 15:07:37 GMT 2015

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

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