Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolve different parser rules dependency. (To establish the relation between rules.)
Resolve different parser rules dependency. [message #1780821] Sun, 28 January 2018 21:52 Go to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
I am new to xtext and need some help. I have a problem statement and don't know how to implement the same. Below is a small example:

//Xtext Grammar---------

Feature_decl: 'feature' name=ID;

Delta_decl: 'delta' name=ID;

Product_line_decl: 'productline' name=ID delta=[Delta_decl|ID] 'when' feature+=[Feature_decl|ID]* (',' feature+=[Feature_decl|ID]*) ';' ;


//Runtime Result----------

feature F1 //on hover or click show D1 and D2
feature F2 //on hover or click show D1 and D2
feature F3 //on hover or click show D2

delta D1 //on hover or click show F1 and F2
delta D2 //on hover or click show F1, F2 and F3

productline example1 D1 when F1,F2; // Establish the relationship between feature and delta

productline example2 D2 when F1,F2,F3;

Now,I want to acheive the relation between features and delta declaration. When I click/hover on any feature say 'F1' anywhere in the program it should show depenedent deltas 'D1' and 'D2'. Similarly, when I hover over a delta say 'D1', it should show list of features i.e. 'F1' and 'F2'.
Re: Resolve different parser rules dependency. [message #1780832 is a reply to message #1780821] Mon, 29 January 2018 05:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
Have a look at the following hooks

IReferenceFinder
HyperlinkHelper
DefaultEOnjectHover


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1780913 is a reply to message #1780832] Mon, 29 January 2018 22:31 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

Thank you for the quick response. However, I am new to Xtext and working on my master thesis where this is a major requirement. Can you provide some more detail so that I can search in the correct direction. I am not able to find any good example or documentation of the above mentioned topics.

Thanks in advance.
Re: Resolve different parser rules dependency. [message #1780921 is a reply to message #1780913] Tue, 30 January 2018 05:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
No I can't there is nothing. You might search the web for usages or customizations of this places but I don't have the time to do the actual work for you

You might use a debugger as well and search the Xtext code base


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Tue, 30 January 2018 05:58]

Report message to a moderator

Re: Resolve different parser rules dependency. [message #1780922 is a reply to message #1780921] Tue, 30 January 2018 06:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
Ps if the references are locally only you might navigate the ast up and down manually e.g. by using helpers in EcoreUtil2

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1780923 is a reply to message #1780922] Tue, 30 January 2018 06:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
And you might have a look at the mark occurrences feature

https://github.com/eclipse/xtext-eclipse/blob/242b5fcc83f4697f6381f9264f710773e8435ce8/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/occurrences/DefaultOccurrenceComputer.java


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1781310 is a reply to message #1780923] Mon, 05 February 2018 21:37 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

I read the documentation as mentioned by you about the EcoreUtil2, however, I have some doubts. I am new to xtext so you may find these question a little silly.
1. Regarding EcoreUtil2
a. I created a 'java' file in the package 'org.xtext.xx.ui' and try to call the method 'getAllReferencedObjects'. Since it is a static method it should be accessible by class name. However, when I try to call EcoreUtil2. getAllReferencedObjects. It does not populate.
b. This method requires parameter namely org.eclipse.emf.ecore.EObject referrer and org.eclipse.emf.ecore.EReference reference. How can I get EObject reference. I have just written a xtext grammar. I am not sure how I can access the EObject.

2. To get the relationship between the Deltas and Features(as explained by my example above).
a. Since I was not able to run my Java file and create an Ecore object. I made some changes in the 'compile' method present in the 'org.xtext.xx.ui.labeling'. There I am able to get the relationship between features and deltas and also able to print them using 'println' command.

3. For the Hover, I referred to the documentation and made a custom message. Now, I am getting the custom message by changing the xxLabelProvider.xtend.

Now since I have values present in my compile method, is there any method through which I can set the value of the hover message to the value computed in the compile method.

I was also thinking of creating a hidden element in the grammar.The compile method will set the attribute value to the values I need and then hover method in the 'org.xtext.xx.ui.labeling' can access and display that attribute's value.

Thanks in advance.



Re: Resolve different parser rules dependency. [message #1781330 is a reply to message #1781310] Tue, 06 February 2018 07:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
Hi,

i still can follow you since your questions are all theoretically.

(1a) for references: are these local references or not. if not have a look at IReferenceFinder.findReferences*
(1b) if yes: use IReferenceFinder or search for YourModelRoot with EcoreUtil2.getContainerOfType. Traverse the ast and search the features and deltas. filter for the ones you want.
(1c) getAllReferencedObjects is looking forn outgoing references, not to find inverses
(1d) You get a MyDslPackage.Literals constants interface that has a YOURCLASS_YOURREFERENCE

(2) i dont understand

(3) i dont understand. if you can print "hello world" you can print "your calculated stuff"


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1781344 is a reply to message #1781330] Tue, 06 February 2018 09:25 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

(1a) for references: are these local references or not. if not have a look at IReferenceFinder.findReferences*

What do you mean by local references? Does it mean all the code is present in a single file?

Also, I am able to understand the method and its usage but I am not sure how to use it. I am creating a new class say A in the package 'org.xtext.xx.ui' which extends EcoreUtil2. Now I want to use 'getAllReferencedObjects' which take 2 parameters. I want to know how I can get these parameters value?

Also, do I need to override the default implementation of ''getAllReferencedObjects' if present and write my code there? Or creating a new class in package 'org.xtext.xx.ui' is correct?


(2) i dont understand

Below is my xtext grammar. The product_line_decl forms the relationship between the deltas and features described above.

//Xtext Grammar---------

Feature_decl: 'feature' name=ID;

Delta_decl: 'delta' name=ID;

Product_line_decl: 'productline' name=ID delta=[Delta_decl|ID] 'when' feature+=[Feature_decl|ID]* (',' feature+=[Feature_decl|ID]*) ';' ;

//Runtime Result----------
//-------------------Features
feature F1

feature F2
feature F3

//-----------------Deltas
delta D1
delta D2

productline example1 D1 when F1,,F2; // Establish the relationship between feature and delta

productline example2 D2 when F1,F2,F3;

When I override the 'compile' function present in 'org.xx.generator' (sorry I mentioned the wrong package), I was able to print

D1->F1,F2

D2->F1,F2,F3

(3) I dont understand. if you can print "hello world" you can print "your calculated stuff"

I am able to print custom messages in 'org.xtext.xx.ui.labeling' package and the compile function is present in the another package called the 'generator'. I am not able to use the text function present in the org.xtext.xx.ui.labeling in my generator class. Hope this helps. Sorry, I am new to xtext so I am not sure what I am doing is correct.


Many thanks for the help anyways.

Re: Resolve different parser rules dependency. [message #1781351 is a reply to message #1781344] Tue, 06 February 2018 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
Quote:
What do you mean by local references? Does it mean all the code is present in a single file?

yes

i dont think getallReferencedObjects is what you are looking for. have a look at IReferenceFinder

(2) i dont understand what you want to achieve

(3) then you need to put your logic to a common place and use it from generator and label provider


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1781354 is a reply to message #1781351] Tue, 06 February 2018 11:06 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
(1)i dont think getallReferencedObjects is what you are looking for. have a look at IReferenceFinder

I can have the code in a single file or multiple files. I tried using these methods but was not successful. May you please let me know where do I need to create the class (in which package) so that I can use the methods.

(2) i dont understand what you want to achieve

I want to acheive a relationship between deltas and features. When a user hover on a delta say D1 , he should be able to see the associated Features. Similarly, when a user hover over a feature say F1 he should be able to see the associated deltas. Please find the attached file.


​(3) then you need to put your logic to a common place and use it from generator and label provider

I was not able to import the label package inside the generator. To use both I think I need to create a class which imports both the classes and then use this class to get information from the generator and displays the information on hover using the label method. Am I understanding it right?
Re: Resolve different parser rules dependency. [message #1781356 is a reply to message #1781354] Tue, 06 February 2018 11:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
you can simply do a @Inject IReferenceFinder referenceFinder;

you can simply create a YourUtil class and inject to to both the generator and label provider


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Resolve different parser rules dependency. [message #1781357 is a reply to message #1781356] Tue, 06 February 2018 11:37 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hey Christian,

Thank you so much for answering my questions so promptly... :-) . I will do it and let you know.
Navigation on Hover. [message #1781694 is a reply to message #1781356] Mon, 12 February 2018 10:04 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

Now. I am able to customize the hover and establish the relation between feature and deltas as per my requirements. When I hover over let say D1 it popups the dependent Features F1, F2, F3 and similarly when I hover on D2 it popup F4,F2.

Is it possible to define the navigation functionality like when I click on F1in the label text it will direct to its definition where F1 is declared i.e. how can I give cross-references in xtext label?

[Updated on: Mon, 12 February 2018 10:10]

Report message to a moderator

Re: Navigation on Hover. [message #1781698 is a reply to message #1781694] Mon, 12 February 2018 10:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
i dont know. this is what HyperlinkHelper ususally does. for oing this in the hover you have to find a solution yourself

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Navigation on Hover. [message #1781702 is a reply to message #1781698] Mon, 12 February 2018 10:35 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
so there is no way to pass text function an object( cross-reference) instead of string?
Re: Navigation on Hover. [message #1781705 is a reply to message #1781702] Mon, 12 February 2018 11:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
i dont understand

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Navigation on Hover. [message #1781708 is a reply to message #1781705] Mon, 12 February 2018 13:04 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

I am using LabelProviders text method to display my customized values on hover. These values are basically the name of the element present in Xtext grammar. I want to know whether there exists a way using which I can navigate to the element declaration when I click on hover item i.e. I want to make the label of the text which displays on hover to be clickable.

Refer to the attach image.
Re: Navigation on Hover. [message #1781709 is a reply to message #1781708] Mon, 12 February 2018 13:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
the question: what should a klick do.
navidate in the hover or the editor


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Mon, 12 February 2018 13:08]

Report message to a moderator

Re: Navigation on Hover. [message #1781710 is a reply to message #1781709] Mon, 12 February 2018 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
maybe somebody in the platform https://www.eclipse.org/forums/index.php/f/11/ or rcp https://www.eclipse.org/forums/index.php/f/106/ forum has an ide (problem should not be xtext specific)

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Navigation on Hover. [message #1781717 is a reply to message #1781710] Mon, 12 February 2018 14:08 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello Christian,

The hover labels of the elements are created by overriding the text(Element o) method of Xtext LabelProvider. This Xtext method takes String as the parameter. However, I want to display these values as a hyperlink so that user can click them and they can navigate to its declaration. Since Xtext label provider only offers a method to set the label as String. I want to know how can I pass a reference to the label instead of String.

Hope it is clear.
Re: Navigation on Hover. [message #1781723 is a reply to message #1781717] Mon, 12 February 2018 14:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
<a href="xxxxx"></a> ??????

or a escaped version. have a look at javadoc/xbase hovers in xtend


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Mon, 12 February 2018 14:54]

Report message to a moderator

Re: Navigation on Hover. [message #1781726 is a reply to message #1781723] Mon, 12 February 2018 15:10 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
I was also thinking of forming the text in the anchor tag . However, I was not sure what to put in 'href' field so that label text can navigate to its declaration .

Also, I am not sure what an escaped version is?
Re: Navigation on Hover. [message #1781732 is a reply to message #1781726] Mon, 12 February 2018 16:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
well this is what i try to tell you: i have never seen somebody doing this. thus i cannot answer

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Navigation on Hover. [message #1782098 is a reply to message #1781732] Sat, 17 February 2018 14:48 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hello,

As you suggested in this link

https://www.eclipse.org/forums/index.php?t=msg&th=337562/

to do the following
@Override
public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
return MyDslHyperlinkHelper.class;
}


I am also facing the same problem. However, I am not sure where to put this dependency "public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() { return MyCustomHyperlinkHelper.class; }". These dependencies are present in "src-gen" folder and get override when I run mwe engine. I have found a xtend file where I think I can put these dependencies but I am not sure how to include them or how to write them in xtend . Please help.

[Updated on: Sat, 17 February 2018 14:52]

Report message to a moderator

Re: Navigation on Hover. [message #1782104 is a reply to message #1782098] Sat, 17 February 2018 18:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
add it to MyDslUiModule.xtend

override Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
return MyDslHyperlinkHelper;
}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Sat, 17 February 2018 18:15]

Report message to a moderator

Re: Navigation on Hover. [message #1782111 is a reply to message #1782104] Sun, 18 February 2018 12:01 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 15
Registered: October 2017
Junior Member
Hi Christian,

Thanks for the response, I have found it.
I am able to show the desired values on hover of the references, but since it takes only string value so I can't pass the anchor tag for hyperlinking.

For Hyperlinking I am using IHyperlinkHelper but I am not sure where to put these references (which are Hyperlinked).

Is it possible to create/Customize a call-hierarchy/Quick-outline with the object references, so that the user can click it and go to the declaration of the hover content?
Re: Navigation on Hover. [message #1782112 is a reply to message #1782111] Sun, 18 February 2018 12:28 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11731
Registered: July 2009
Senior Member
I Dont understand.

simply create as many hyperlinks as you wish

the helper calls org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper.createHyperlinksTo(XtextResource, Region, EObject, IHyperlinkAcceptor)

simply create different hyperlinks to different targets ?!?


regarding your second question
yes and no
everythings is customizable
but you need to do it.
i cannot tell you how since i dont know
you need to read the code
read existing cxustomizations
etc


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Sun, 18 February 2018 12:30]

Report message to a moderator

Previous Topic:Creating hyperlinks in Xtext editor
Next Topic:Lexical syntax highlighting
Goto Forum:
  


Current Time: Tue Feb 20 21:28:46 GMT 2018

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

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