Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » EMF-IncQuery » Aggregation of Strings of different Objects
Aggregation of Strings of different Objects [message #1413098] Wed, 27 August 2014 19:46 Go to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member

I want to calculate the metric "Relevant Lines of Code" on the JaMoPP model.
This means all lines of a Compilation Unit, that contains at least one non commented character of A-Z.
The query formulated in Epsilon Object Language is as follows:

operation calculateRloc () : Integer {
	return daten!CompilationUnit.all().
		select(x | x.isSource()).
	 	collect(x | x.rloc()).

operation CompilationUnit rloc() : Integer {
	var layouts = self.getChildrenByEType(AttributeLayoutInformation.createInstance().type());
	return layouts.sortBy(x | x.getStartOffset()).
		collect(x | x.layoutAsText()).
		select(x | x.matches("(?s).*[a-zA-Z].*")).
		select(x | x <> "<EOF>").

operation LayoutInformation layoutAsText () : String {
	return self.getHiddenTokenText().
		select(x | x="\n" or x="\t" or x=" " or x="\r").

operation Commentable isSource() : Boolean {
		return false;
	return self.eResource().getURI().toString().startsWith('file:/');

First, all source Compilation Units are collected.
For each Compilation Unit, all contained LayoutInformation Objects are gathered.

Then they are sorted by the attribute getStartOffset.
The string representation is concatened etc...

My question is if this is possible in Incquery.
Is there any way to sort a collection and concatenate the strings?

So far I understand Incquery it is not possible.

Thanks for any hint

Greetings, Mario

Re: Aggregation of Strings of different Objects [message #1413117 is a reply to message #1413098] Wed, 27 August 2014 21:09 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi Mario,

you are right, what you are looking for is not really possible in the graph pattern formalism of EMF-IncQuery. The results of a pattern (that is represented as a set) cannot be ordered directly (see bug for some related ideas); however, nothing stops you from loading the results programatically, then ordering the results using a Java comparator (or if you are using Java 8, Xtend or Guava, you can also use similar sort functions to the Epsilon code).

Concatenating string values from model attributes is possible with the eval constraint (, where you can use Java-like expressions to do the concatenation. However, you cannot combine the results of multiple matches, as that would greatly extend the capabilities of our language.


However, for such tasks as your I would suggest a combined Java/IncQuery approach. Define queries that are used to collect the model elements required for the aggregation, but do not manage the aggregation itself. Then do the aggregation using the results of these elementary patterns in Java code. The result could be similar to the Epsilon code shown above; the imperative code (that is most of the code above) should be written in Java, while the corresponding model element tuples can be assembled using EMF-IncQuery patterns.

I hope, the idea is clear enough. If not, feel free to ask for clarification.

Re: Aggregation of Strings of different Objects [message #1413133 is a reply to message #1413117] Wed, 27 August 2014 22:05 Go to previous message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi Zoltán,

thanks a lot for this detailed answer. It is clear to me.

My current task is to use only the query engine language, so I cannot use Incquery therefore.
For other kind of queries it was possible.

Greetings, Mario
Previous Topic:get Eclass of EObject
Next Topic:Check URI of Resource
Goto Forum:

Current Time: Tue May 21 01:41:04 GMT 2024

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

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

Back to the top