Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Getting all dsl objects from a specific file from current workspace
Getting all dsl objects from a specific file from current workspace [message #1739441] Mon, 01 August 2016 14:06 Go to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Hello together,

I'm currently trying to increase the performance of my DSL, especially in the editor, and found a bottleneck in my TemplateProposalProvider.

I've written my own class to get specific DSL elements, but it's iterating over all files in the workspace, so it's really slow.

I'm overriding the following method: createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor)


My grammar could be stated as:
RootElement:
	elements+=AbstractElement*
	
AbstractElement:
	Class | Statement



I'm trying to get all Statement's from my workspace which are referencable by my current Class.

I can get the RootElement object by using:
ContentAssistContext.rootModel as RootElement

From there on I tried to use the IResourceSetProvider to get the ResourceSet for my project, which however did not have any resources.
I tried the ResourceDescriptionsProvider, which gave me a bunch of URI's or objects which have all attributes set to null.

The following is giving me all Statements (all = the correct amount), but all the attributes are null.


@Inject
private ResourceDescriptionsProvider rdProvider

@Inject
private IResourceSetProvider rsProvider

// Method
val rootElement = context.rootModel as RootElement
val class = rootElement.elements.filter(Class).head
val platform = rootElement.eResource.URI.toPlatformString(true)
val project = ResourcesPlugin.workspace.root.getFile(new Path(platform))
val resourceSet = rsProvider.get(project)

rdProvider.getResourceDescriptions(resourceSet).allResourceDescriptions.map[it.exportedObjects].flatten.map[it.EObjectOrProxy].filter(Statement)



Which would be the correct way to get all the objects I'm looking for? Bonus points if I also get the objects from referenced Eclipse-Projects Smile


cheers!
Re: Getting all dsl objects from a specific file from current workspace [message #1739443 is a reply to message #1739441] Mon, 01 August 2016 14:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
rdProvider.getResourceDescriptions(resourceSet).allResourceDescriptions.map[it.exportedObjects].flatten.map[it.EObjectOrProxy].filter(Statement) look ok. what is the problem with that?
since these are index entries only you have proxies here. you can of course resolve that. but that wil be slow again.
so why do you want to look at the Statements attributes?

i can use IContainer.Manager.getVisibleContainers to retrict that to visible resources.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739447 is a reply to message #1739441] Mon, 01 August 2016 16:25 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Hi Christian,

I want to write TemplateProposal's as you can find them in Eclipse for Javamethods.

Consider the following definition:

public void someMethod(String firstParam, String secondParam)


I want to be able to complete it like so:

<CTRL+SPACE>select someMethod<ENTER>
results in
someMethod(firstParam, secondParam)


I get that part with the templating correct, I can also tab through the parameter etc.

The only thing that is not good is the performance, as I need to find all possible Statements within my scope, which are roughly 211 at the moment.

When I hit CTRL+Space it takes like 1-2 seconds to load up all the proposals.

(Also the method gets called 3 times for pressing ctrl+space once, is that normal?)
Re: Getting all dsl objects from a specific file from current workspace [message #1739464 is a reply to message #1739447] Tue, 02 August 2016 05:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
seems the newsgroup is stuck.

if you want to inspect the Statements from the index, then you have to resove it, which may lead to a reparse, which will be slow.
depending on how your parameters works you can store information on the params in the userdata of the EObjectescriptions in the index - although cross referencing does not work while indexing, so you may no be ablte to store full type information on your params there
(you did no post anything on how your semantic are)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739465 is a reply to message #1739464] Tue, 02 August 2016 06:21 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
RootElement:
	elements+=AbstractElement*
	
AbstractElement:
	Class | Statement

Statement:
        'Statement' name=ID '('  parameter=ParameterList ')'

Class:
        'Class' name=ID
        '{'
                variables+=Variable*
                calls+=StatementCall*
        '}'

StatementCall:
        statement=[Statement] '(' parameter=StatementCallParameter ')'

StatementCallParameter:
        variable=[Variable]

Variable:
        'var' name=ID type=STRING


Semantically I'm at the
StatementCall
position and try to complete all possible statements.

The eclipse workspace is like this:

workspace root
|
|____ Project with Classes
|____ Project with Statements

The eclipse projects are referenced, which means if I have the
IProject
from the Classes project (which I use to get the resourceSet) I can use
IProject.referencedProject.findFirst[it.name == "Statementproject"]
and get the project which has all the statements.

What I then do is iterate over all IContainers (recursive) and IFiles of the project to get all IFiles which have the same fileextension as my dsl (e.g. "mydsl"), create a
PlatformResourceUri
with
IFile.getFullPath.toString
, ask the resource set of the project for the specific resource and cast it to
RootModel
.

It works but it takes some time.

Thats the long way of getting the objects. If I want to do this via ResourceDescriptions then the eResource on any object in there is null, which means I can't form a patformUri to ask the resourceSet for any object corresponding to a URI.

As a full rebuild of that DSL-workspace builds around 200 resource description chunks I thought the best idea to get those resources is from asking for what's already built.

The full rebuild takes around 3 minutes without heavy scoping.

val uri = URI.createPlatformResourceURI(member.getFullPath().toString(), true)
val resourceSet = resourceSetProvider.get(container.project)
val resource = resourceSet.getResource(uri, true)

[Updated on: Tue, 02 August 2016 06:51]

Report message to a moderator

Re: Getting all dsl objects from a specific file from current workspace [message #1739469 is a reply to message #1739465] Tue, 02 August 2016 07:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
as i said: you need to resolve the proxy.

which information about the params are needed in the template?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739478 is a reply to message #1739469] Tue, 02 August 2016 09:29 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
I've never stored informations on the index, how could I do it?

I just need the name of the parameter.

How can I resolve the proxy? If I write the following:

		val statementProxies = rdProvider.getResourceDescriptions(resourceSet).allResourceDescriptions.map[it.exportedObjects].flatten.map[it.EObjectOrProxy].filter(Statement)
		println(statementProxies.size)
	
		println(statementProxies.filter[it.eResource?.URI != null].size)


the output then is:

211
0

which is the correct amount of Statements, but I can't get the URI of any of the resolved proxies, which I need to get the object from the resourceset


Getting the 211 proxies takes 10ms by the way. If resolving the real objects is as fast as that it might take around 60ms (3x20ms) for getting all statements, that would be super cool Smile

[Updated on: Tue, 02 August 2016 09:32]

Report message to a moderator

Re: Getting all dsl objects from a specific file from current workspace [message #1739480 is a reply to message #1739478] Tue, 02 August 2016 09:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
it.EObjectUri ?

if you just need the name

subclass DefaultResourceDescriptionStrategy
adapt createEObjectDescriptions

create a EObejctDescription with user data map.
fill the parameter names where.

read it from userdata inside .map[...... / it.getUserData(key)]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739484 is a reply to message #1739480] Tue, 02 August 2016 10:24 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Thank you Christian, it's working with EObjectUri!

I was using the Proxy to just work with something thats a subclass of Statement, but the following is working now:

val statementUris = rdProvider
					.getResourceDescriptions(resourceSet)
					.allResourceDescriptions.map[it.exportedObjects]
					.flatten
					.filter[it.EObjectOrProxy instanceof Statement]
	        			.map[it.EObjectURI]

val statements = statementUris.map[resourceSet.getEObject(it, true) as Statement]


Is there anything I can do to speed up the building of resourceDescriptions? The full build takes around 3 minutes and is using around 200 chunks. The workspace has around 1800 classes and 200 statements. After the build is done I normally work with 2-3 classes and they don't reference each other. Eclipse then uses up to 1.2gb of memory in the heap and slowing down.
Re: Getting all dsl objects from a specific file from current workspace [message #1739503 is a reply to message #1739447] Mon, 01 August 2016 16:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
I was asking: what is the problem you have with taking the statements from
the index


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739504 is a reply to message #1739447] Mon, 01 August 2016 16:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
Did you consider eg storing info on the Params inside the user data of the
statement index entries? (Depends how you Params and their types work


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739505 is a reply to message #1739484] Tue, 02 August 2016 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
You need to profile that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting all dsl objects from a specific file from current workspace [message #1739530 is a reply to message #1739505] Tue, 02 August 2016 17:00 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Hi Christian,

the problem was that I didn't do it correctly Wink

I tried to get the EObject by using EObjectOrProxy and when that didn't work I dotted through the EObject and saw that I can get the URI. But the eResource was also null. Using EObjectUri instead of EObjectOrProxy did the trick.

With how it works now I don't need to store the params on the index, since it would contain a few more informations (name, type, usage).

However, I'll test the perfomance with userdata on the descriptions and measure it.

How can I profile a Xtext DSL?
Re: Getting all dsl objects from a specific file from current workspace [message #1739536 is a reply to message #1739530] Tue, 02 August 2016 17:55 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14651
Registered: July 2009
Senior Member
As you profile other stuff. I use yourkit

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText netbeans support
Next Topic:xtext apply terminal rule only on selected parser rule
Goto Forum:
  


Current Time: Thu Feb 22 21:57:40 GMT 2024

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

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

Back to the top