Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF-IncQuery » Check URI of Resource
Check URI of Resource [message #1339070] Wed, 07 May 2014 13:57 Go to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi,

I tried a lot of time to solve the problem, but I haven't found a solution so far.

I want to query all object that are instances of two certain classes.
That is what is written in the following.

But I didn't manage to check the URI of the object.
In Java it coded like this:

.eResource().getURI().toString().startsWith("file:/");

Any help is very welcome.

Greetings, Mario

package klassen


pattern allTypes(klasse) 
{
	ConcreteClassifier(klasse);
} 
or
{
	AnonymousClass(klasse);
}


Re: Check URI of Resource [message #1339150 is a reply to message #1339070] Wed, 07 May 2014 14:43 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 122
Registered: July 2009
Senior Member
Welcome to the EMF-IncQuery forum, Mario!

The pattern that you wrote will indeed match all EObjects that are instances of the two classes.

However, I don't really understand when do you want to check the URI?
Re: Check URI of Resource [message #1339167 is a reply to message #1339150] Wed, 07 May 2014 14:51 Go to previous messageGo to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Thanks for your answer.

The condition should are the following three:

(
-instance of ConcreteClassifier
OR
-instance of AnonymousClass
)
AND
-uri starts with "file://"

I haven't found a solution to check the uri

Do you know a way to do this?
Re: Check URI of Resource [message #1339178 is a reply to message #1339167] Wed, 07 May 2014 14:59 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 122
Registered: July 2009
Senior Member
The URI of an EMF resource is not something you should check in a pattern since resources and resource sets are not part of models, they are serialization details. In addition, when invoking EMF-IncQuery, you will initialize the engine on a given resource (or resource set), so you can check the URI before initializing. See https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/API#Loading_an_instance_model_and_executing_a_query

Or do you want to initialize the engine on the whole resource set, which includes a large number of resources, where not all of them are from file URIs?
Re: Check URI of Resource [message #1339273 is a reply to message #1339178] Wed, 07 May 2014 15:54 Go to previous messageGo to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Quote:

Or do you want to initialize the engine on the whole resource set, which includes a large number of resources, where not all of them are from "file://" URIs?


Thanks for the answer.

Yes, the ResourceSet contains different Resource types.

I first have to look whether the queries work if some resources are missing.
Re: Check URI of Resource [message #1341241 is a reply to message #1339150] Thu, 08 May 2014 11:42 Go to previous messageGo to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 136
Registered: July 2009
Senior Member
What Mario is gonna to achieve is the following:

-----example------
package org.emftext.refactoring.languages.java.smell.android

import "http://www.emftext.org/java/containers"

pattern isSource(unit:CompilationUnit) {
check({
var org.eclipse.emf.common.util.URI uri =
org.eclipse.emf.ecore.util.EcoreUtil::getURI(unit);
var ext = uri.fileExtension;
if("java" == ext) true else false;
});
}
-----example------

But, this check expression is not valid because the following errors are
displayed:

Multiple markers at this line
- Only simple EDataTypes are allowed in check expressions. The
variable unit has a type of CompilationUnit.
- There are potentially problematic java calls in the check expression.
Custom java calls without @Pure annotations considered unsafe
in IncQuery. The possible erroneous calls are the following:
[org.eclipse.emf.ecore.util.EcoreUtil.getURI,
org.eclipse.emf.common.util.URI.fileExtension].

What is this @Pure annotation? How can the file extension check be achieved?

cheers,
Jan
Re: Check URI of Resource [message #1341658 is a reply to message #1341241] Thu, 08 May 2014 15:36 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 122
Registered: July 2009
Senior Member
We have talked about restricting IncQueryEngine scopes to selected resources in the past, and due to your request I have now created an issue in Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=434435

As for your question: the Pure annotation is part of Xbase and while we planned to create an extension point to register Pure methods, it is not implemented afaik. However, that is only a warning.

The error say that you cannot access EObjects inside check expressions. The reasoning can be found here:
https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/QueryLanguage#Limitations_.28as_of_IncQuery_0.7.29
And here http://incquery.net/incquery/faq#Q:_How_does_one_use_attributes

Finally, I will reiterate:
The file extension and URI of the Resource are outside of the scope of EMF _models_ and thus, EMF-IncQuery pattern language.
Re: Check URI of Resource [message #1355542 is a reply to message #1341658] Wed, 14 May 2014 19:38 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 260
Registered: July 2015
Senior Member
Hi,

we have added a filter implementation for EMF-IncQuery that should be capable of removing some resources from indexing. Some documentation (with a very small example) is added to the API documentation wiki page: https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/API/Advanced#Using_Filtered_Input_Models_During_Pattern_Matching

This implementation is already in the latest CI/integration builds. Can you please have a look whether it helps you achieving what you need or something is still needed?

Cheers,
Zoltán
Re: Check URI of Resource [message #1404081 is a reply to message #1355542] Tue, 29 July 2014 13:36 Go to previous messageGo to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi Zoltán,

thanks for adding this feature.

The response time is shorter now for the RunOnce Engine.

My intention was of filtering for the final result, which Incquery returns.

For some queries, I can of course filter the result Incquery returns.
But if I want to use it in query for furter patterns, it does of course not work.

Greetings, Mario
Re: Check URI of Resource [message #1404752 is a reply to message #1404081] Tue, 05 August 2014 13:42 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 260
Registered: July 2015
Senior Member
Hi Mario,

I am sorry, but I do not understand how does it not work. Can you elaborate it, or even better, send a problematic case for me to try it out?

Cheers,
Zoltán
Re: Check URI of Resource [message #1412998 is a reply to message #1404752] Wed, 27 August 2014 14:29 Go to previous messageGo to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi Zoltán,

sorry for the late reply.

I load software models using JaMoPP.
The ResourceSet returned by the Modell Loader [1] contains Source Files and Class Files.

In one query I want to find all objects that are an instance of MemberContainer.
But only those that are in a source file.

The proposed solution using IBaseIndexResourceFilter does not work.
I have to filter the result from Incquery manually.

But I noticed that the memory usage decreases when filtering out all resources, that means that isResourceFiltered(Resource resource) always returns true.

The query time also decreases.

Greetings Mario

[1] https://github.com/DevBoost/JaMoPP/tree/master/Utils/org.emftext.language.java.jamoppc
Re: Check URI of Resource [message #1413000 is a reply to message #1412998] Wed, 27 August 2014 14:33 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 260
Registered: July 2015
Senior Member
Hi Mario,

this seems very strange. If you set isResourceFiltered as constant false, you should not receive any solutions at all. Either I have missed a case when implementing the filter, or I do not understand correctly how you are using it (I tend to think of more of the former, but have no idea what can be missing).

Maybe, could you share some example that exhibits this behavior?

Cheers,
Zoltán
Re: Check URI of Resource [message #1413095 is a reply to message #1413000] Wed, 27 August 2014 19:37 Go to previous messageGo to next message
Mario Bauer is currently offline Mario BauerFriend
Messages: 21
Registered: May 2014
Junior Member
Hi Zoltán,

I use version 0.8.0.201407021417.

This is the code:

public class IncQueryMethodsCC extends AbstractQuery {

	private AdvancedIncQueryEngine engine;
	private Collection<MethodsHighCCMatch> allMatchesCC;
	private Collection<TooLargeMemberContainersMatch> allMatchesMethods;
	private Collection<AlleTypenMatch> allMatchesMemberContainer;

	public IncQueryMethodsCC(ResourceSet resourceSet, String name) {
		super(resourceSet, name);
	}

	@Override
	public void createEngine() {
		try {
			engine = AdvancedIncQueryEngine.createUnmanagedEngine(resourceSet, createBaseIndexOptions());
		} catch (IncQueryException e) {
			e.printStackTrace();
		}
	}

	public BaseIndexOptions createBaseIndexOptions() {
		BaseIndexOptions baseIndexOptions = new BaseIndexOptions();
		baseIndexOptions.setResourceFilterConfiguration(new IBaseIndexResourceFilter() {

			@Override
			public boolean isResourceFiltered(Resource resource) {
				return true;
			}
		});
		return baseIndexOptions;
	}

	@Override
	public void runQuery() {
		try {
			allMatchesCC = engine.getMatcher(MethodsHighCCQuerySpecification.instance()).getAllMatches();

			allMatchesMethods = engine.getMatcher(TooLargeMemberContainersQuerySpecification.instance())
					.getAllMatches();

			allMatchesMemberContainer = engine.getMatcher(AlleTypenQuerySpecification.instance()).getAllMatches();

		} catch (IncQueryException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void doAdditional() {
		filterMethodsForSourceObjectsAndPrintNumber(allMatchesCC);
		filterTypesForSourceObjectsAndPrintNumber(allMatchesMemberContainer);
		filterTypesTooLargeForSourceObjectsAndPrintNumber(allMatchesMethods);
	}

	public void filterMethodsForSourceObjectsAndPrintNumber(Collection<MethodsHighCCMatch> allMatches) {
		List<EObject> resultSet = createList();
		Util.log(" #matches" + allMatches.size());
		for (MethodsHighCCMatch match : allMatches) {
			Member methode = match.getMethod();
			if (isSourceElement(methode)) {
				resultSet.add(methode);
				// Util.log(" " + Util.calulateCompleteMethodName(methode));
			}
		}
		Util.log(" size MethodsCC = " + resultSet.size());
	}

	public void filterTypesForSourceObjectsAndPrintNumber(Collection<AlleTypenMatch> allMatches) {
		List<EObject> resultSet = createList();
		Util.log(" #matches" + allMatches.size());
		for (AlleTypenMatch match : allMatches) {
			MemberContainer type = match.getInput();
			if (isSourceElement(type)) {
				resultSet.add(type);
			}
		}
		Util.log(" size All Types = " + resultSet.size());
	}

	public void filterTypesTooLargeForSourceObjectsAndPrintNumber(Collection<TooLargeMemberContainersMatch> allMatches) {
		List<EObject> resultSet = createList();
		Util.log(" #matches" + allMatches.size());
		for (TooLargeMemberContainersMatch match : allMatches) {
			MemberContainer type = match.getMemberContainer();
			if (isSourceElement(type)) {
				resultSet.add(type);
			}
		}
		Util.log(" size Too Large Types = " + resultSet.size());
	}

	public void dispose() {
		engine.dispose();
	}
}


public abstract class AbstractQuery {

	ResourceSet resourceSet;

	public AbstractQuery(ResourceSet resourceSet, String name) {
		super();
		this.resourceSet = resourceSet;
		this.name = name;
	}

	String name;
	long time;

	public void runAll() {
		log(name);

		// MemoryUsageMeter.activate();

		startTime();
		createEngine();
		log("engineloadtime=" + calculateUsedSeconds());

		startTime();
		runQuery();
		log("querytime=" + calculateUsedSeconds());

		doAdditional();
	}

	public double calculateUsedSeconds() {
		return convertTimeInSeconds(stopTime());
	};

	public abstract void doAdditional();

	public abstract void runQuery();

	public abstract void createEngine();

	public void startTime() {
		time = getNanoTime();
	}

	public long stopTime() {
		return getNanoTime() - time;
	}

}



Greetings Mario
Re: Check URI of Resource [message #1413266 is a reply to message #1413095] Thu, 28 August 2014 07:13 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 122
Registered: July 2009
Senior Member
Hi Mario,

please read the JavaDoc of resource filter configuration and suggest improvements if it is not clear.
Your code will filter _all_ EMF resources, therefore EMF-IncQuery will run over an empty model:
@Override
public boolean isResourceFiltered(Resource resource) {
  return true;
}


Instead, implement isResourceFiltered to return true IF the given resource represents a _class_ file (since you only want to match over _source_ file, which will not be filtered).

Cheers
Re: Check URI of Resource [message #1413273 is a reply to message #1413266] Thu, 28 August 2014 07:27 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 260
Registered: July 2015
Senior Member
Hi,

Ábel: I was relating to the following description from Mario:

Quote:

The proposed solution using IBaseIndexResourceFilter does not work.
I have to filter the result from Incquery manually.

But I noticed that the memory usage decreases when filtering out all resources, that means that isResourceFiltered(Resource resource) always returns true.


For me it means, all resources were filtered out... So I am not sure, what happened.

Mario: in addition to the code snippet, can you also provide queries/instance model; or at least tell us what is the expected/actual outcome of the code?

Cheers,
Zoltán
Previous Topic:Aggregation of Strings of different Objects
Next Topic:IncQuery Explorer and Xtext resources
Goto Forum:
  


Current Time: Tue Aug 04 18:13:25 GMT 2015

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

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