Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Folding on EReferences
Folding on EReferences [message #713556] Mon, 08 August 2011 15:42 Go to next message
Xavier Seignard is currently offline Xavier SeignardFriend
Messages: 52
Registered: June 2010
Member
Hello,

In my EMF metamodel, I've got an EObject which contains (i.e. containment = true) an EReference (with a * cardinality) to another EObject.

In my grammar, I want to be able to fold/unfold the whole list of EObjects handled by this EReference.

So I extended the DefaultFoldingRegionProvider and binded it in the UI module.

I only overwrote the doGetFoldingRegions method to handle my folding strategy.
So I parse my model, get the structural feature which is my EReference, and the call these methods defined in DefaultFoldingRegionProvider :

IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor = createAcceptor(xtextDocument, result);
computeObjectFolding(eReference, foldingRegionAcceptor);


I also overwrote the isHandled method to always return true.

But it doesn't work, so I think I'm missing some points. Or maybe it's not possible to fold/unfold on the whole EReference (and not each elements of that EReference, which works fine actually)?

Regards,

Xavier

[Updated on: Mon, 08 August 2011 15:43]

Report message to a moderator

Re: Folding on EReferences [message #713625 is a reply to message #713556] Mon, 08 August 2011 17:05 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Xavier,

you may have to use NodeModelUtils.findNodesForFeature(EObject,
EStructuralFeature) and merge the nodes in the resulting list to a
complete range that should be folded.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 08.08.11 17:42, Xavier Seignard wrote:
> Hello,
>
> In my EMF metamodel, I've got an EObject which contains (i.e.
> containment = true) an EReference (with a * cardinality) to another
> EObject.
>
> In my grammar, I want to be able to fold/unfold the whole list of
> EObjects handled by this EReference.
>
> So I extended the DefaultFoldingRegionProvider and binded it in the UI
> module.
>
> I only overwrote the doGetFoldingRegions method to handle my folding
> strategy.
> So I parse my model, get the structural feature which is my EReference,
> and the call these methods defined in DefaultFoldingRegionProvider.
>
> IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor =
> createAcceptor(xtextDocument, result);
> computeObjectFolding(eReference, foldingRegionAcceptor);
>
> I also overwrote the isHandled method to always return true.
>
> But it doesn't work, so I think I'm missing some points. Or maybe it's
> not possible to fold/unfold on the whole EReference (and not each
> elements of that EReference, which works fine actually)?
>
> Regards,
>
> Xavier
Re: Folding on EReferences [message #713875 is a reply to message #713625] Tue, 09 August 2011 09:14 Go to previous messageGo to next message
Xavier Seignard is currently offline Xavier SeignardFriend
Messages: 52
Registered: June 2010
Member
Thanks Sebastian for your quick answer.

Lets say my grammar look like this :

A returns A:
	{A}
	'a'
	name=ID
	'{'
		('b' '{' setOfB+=B+ '}' )?
		('c' '{' setOfC+=C* '}' )?
        '}';


Where B and C are other rules defined after.

With NodeModelUtils.findNodesForFeature I do get all nodes in the given feature (let's say feature with keyword 'b'). But as I gave a keyword for this feature, and it's not in the list of node I have, how can I calculate the offset? (For now I calculate it from the root node, but it's quite crappy).

And for the lenght, I add the length of each node, but I also need to add the length of the keyword and brackets (I do it in a crappy way for now), so is there any way to do it smartly?

Finally with I pass offset and length as parameters of foldingRegionAcceptor.accept and it works quite ok.

Any suggestion to calculate offset and length smartly?

Regards,

Xavier
Re: Folding on EReferences [message #713994 is a reply to message #713875] Tue, 09 August 2011 13:43 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Xavier,

don't know what you think is smart ... offset + length usually return
the endoffset. I assume that you want to fold everything starting from b
up to the closing brace and starting from c up to the closing brace again.

I'd navigate the node that is associated with A, find the node with
grammarElement==keywordB and navigate to its siblings until you reach
the closing brace. Ask that node for the endOffset and you'll have a
start and the end which leads to a nicely computed length.

Does that make sense?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 09.08.11 11:14, Xavier Seignard wrote:
> Thanks Sebastian for your quick answer.
>
> Lets say my grammar look like this :
>
> A returns A:
> {A}
> 'a'
> name=ID
> '{'
> ('b' '{' setOfB+=B+ '}' )?
> ('c' '{' setOfC+=C* '}' )?
> '}';
>
> Where B and C are other rules defined after.
>
> With NodeModelUtils.findNodesForFeature I do get all nodes in the given
> feature (let's say feature with keyword 'b'). But as I gave a keyword
> for this feature, and it's not in the list of node I have, how can I
> calculate the offset? (For now I calculate it from the root node, but
> it's quite crappy).
>
> And for the lenght, I add the length of each node, but I also need to
> add the length of the keyword and brackets (I do it in a crappy way for
> now), so is there any way to do it smartly?
>
> Finally with I pass offset and length as parameters of
> foldingRegionAcceptor.accept and it works quite ok.
>
> Any suggestion to calculate offset and length smartly?
>
> Regards,
>
> Xavier
Previous Topic:xtext syntax question
Next Topic:Migrating to xtext 2.0
Goto Forum:
  


Current Time: Thu Apr 25 20:09:45 GMT 2024

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

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

Back to the top