Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText 2.0 --- Hover Documentation(Looking for some tutorials)
XText 2.0 --- Hover Documentation [message #696628] Thu, 14 July 2011 12:40 Go to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
I am looking for some kind of tutorial about Hover implementation for Xtext 2.0

is there any ?

For example at the following link
http://malubu.wordpress.com/2011/05/18/hovertext/

in MyDslInformationControll class, there is some declaration such as TestLocation (line 65), the class testLocation is not exist anymore in Xtext2.0



[Updated on: Thu, 14 July 2011 13:04]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #696735 is a reply to message #696628] Thu, 14 July 2011 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i don't know of any tutorial, but it should not be any problem to
find samples of implementing/subclassing of IEObjectDocumentationProvider/DefaultEObjectHoverProvider
(Xtext/Xbase/Xtend/Mwe2)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 14 July 2011 18:15]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #696741 is a reply to message #696735] Thu, 14 July 2011 18:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

here a short solution for the greeting example:

package org.xtext.example.mydsl.ui;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import org.xtext.example.mydsl.myDsl.Greeting;

public class MyDslEObjectHoverProvider extends DefaultEObjectHoverProvider {
	
	@Override
	protected String getFirstLine(EObject o) {
		if (o instanceof Greeting) {
			return "Damn good greeting: " + ((Greeting)o).getName();
		}
		return super.getFirstLine(o);
	}

}



package org.xtext.example.mydsl.ui;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.xtext.example.mydsl.myDsl.Greeting;

public class MyDslEObjectDocumentationProvider implements IEObjectDocumentationProvider {

	@Override
	public String getDocumentation(EObject o) {
		if (o instanceof Greeting) {
			return "This is a nice Greeting";
		}
		return null;
	}

}


/*
 * generated by Xtext
 */
package org.xtext.example.mydsl.ui;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;

/**
 * Use this class to register components to be used within the IDE.
 */
public class MyDslUiModule extends org.xtext.example.mydsl.ui.AbstractMyDslUiModule {
	public MyDslUiModule(AbstractUIPlugin plugin) {
		super(plugin);
	}
	
	public Class<? extends IEObjectHoverProvider> bindIEObjectHoverProvider() {
		return MyDslEObjectHoverProvider.class;
	}
	
	public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProviderr() {
		return MyDslEObjectDocumentationProvider.class;
	}
}



~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.0 --- Hover Documentation [message #696756 is a reply to message #696741] Thu, 14 July 2011 19:08 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Thanks Christian,
I gonna try to figure it out and come back Wink
Thanks again

[Updated on: Tue, 19 July 2011 14:11]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #696769 is a reply to message #696756] Thu, 14 July 2011 19:37 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hello Christian!

I just tried this , and ran this sample without any compiling problem, However,, when I point key word "Hello" with my mouse arrow, the hover didnt pop up,
why do you think?
Re: XText 2.0 --- Hover Documentation [message #696770 is a reply to message #696769] Thu, 14 July 2011 19:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i guess this is cause the hovers by default are not shown for Keywords.
you may have to customize org.eclipse.xtext.resource.DefaultLocationInFileProvider too

/*
 * generated by Xtext
 */
package org.xtext.example.mydsl;

import org.eclipse.xtext.resource.ILocationInFileProvider;

/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends ILocationInFileProvider> bindILocationInFileProvider() {
		return MyDslLocationInFileProvider.class;
	}
	
}


package org.xtext.example.mydsl;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.resource.DefaultLocationInFileProvider;
import org.eclipse.xtext.util.ITextRegion;

public class MyDslLocationInFileProvider extends DefaultLocationInFileProvider {
	
	@Override
	public ITextRegion getSignificantTextRegion(EObject obj) {
		return super.getFullTextRegion(obj);
	}

}


or you customize org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 14 July 2011 19:58]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #696783 is a reply to message #696770] Thu, 14 July 2011 20:12 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Thank you so much Christian, this is absolutely working

Thanks alot
Re: XText 2.0 --- Hover Documentation [message #696977 is a reply to message #696783] Fri, 15 July 2011 08:46 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian

as you know I have this grammar ;


Librarymodel:
	(elements+=NonEmptyline)*;
	
NonEmptyline:
	writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;

Words hidden (): ID (WS ID)* ;


I want hovering for NonEmptyLine and i just change the if loop as follows

public class MyDslEObjectDocumentationProvider implements IEObjectDocumentationProvider {
	
		@Override
	public String getDocumentation(EObject o) {
		if (o instanceof NonEmpityLine) {	
			return "This is a NonEmpityLine";
		}
		return null;
}


as well as here too;

protected String getFirstLine(EObject o) {
		if (o instanceof NonEmpityLine) {
			return "Damn good coding: " ;
		}
		return super.getFirstLine(o);
	}



Consequent ; When I point on the following line, Hovering doesnt show up for my NonEmptyline in somthng.mydsl;

Writer1:Book1:1233:213

Is it because ; NonEmptyline consists of other parameters which are hidden?
Second; I want to implement hovers for each field (writer,selected writer's book,selected book's isbn..etc)in my NOnEmptyLine,
which have been divided with ':'/',' for user,so user will know which type has to be typed,
while user is typing code, is there anyway to display information ?

[Updated on: Fri, 15 July 2011 08:46]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #696979 is a reply to message #696977] Fri, 15 July 2011 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i do not know the API any better than you so do what i have done: Use the Debugger Wink

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.0 --- Hover Documentation [message #697071 is a reply to message #696979] Fri, 15 July 2011 13:10 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Thanks Christian

I guesss , I need an other way to define hovering for hidden or terminal roules

They are different than normal type hovers, if we consider my grammer
NonEmpityLine consists of hidden Words and some in

I tried to do some thing like this


rammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

LCModel:
    (types+=Type)*;   

Type:
  Rule1|Rule2|Rule3|Greeting;



Rule1:
	'$' name=Words
	
;
Rule2:
	'rule2' name=Words2
	
;

 Words2  : 	
    	ID (WS ID)*  	
    ;

 Rule3: 

 'rule3' name=ID '!';
	

 	
NonEmptyline:
	writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;

   Words hidden (): 	
    	ID (WS ID)*  	
    ;
    



and to distinguish which is called


public class MyDslEObjectHoverProvider extends DefaultEObjectHoverProvider {
	
	
	LeafNode leaf;
	StringBuffer result = new StringBuffer();
	


	@Override
	protected String getFirstLine(EObject o) {
		
       	
		}else if (o instanceof Rule1) {
			return " DDD RULE1 ";
			
		}
		else if(o instanceof Rule2){
			return " DDD Rule2";
		}
		else  if (o instanceof Rule3) {
			return "DDD This is Rule3 ";

                   } else   if (o instanceof NonEmptyline) {
			return "DDD This is Rule3 ";
                         }
			return super.getFirstLine(o);
	

I get hover for rule1, rule 2 ,rule 3 but not for NonEmptyline

Should I override the getHoverInfo for hidden roles?

caner

[Updated on: Fri, 15 July 2011 13:13]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #697073 is a reply to message #697071] Fri, 15 July 2011 13:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

there is something messed up in your code postings. i don't get your problem Wink
and actually you are hiding nothing Wink

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 15 July 2011 13:18]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #697082 is a reply to message #697073] Fri, 15 July 2011 13:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

have a look at this:

	protected boolean hasHover(EObject o) {
		return nameProvider.getFullyQualifiedName(o)!=null;
	}


ant youll know what to do ;-): Give your line a qualifiedname

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.0 --- Hover Documentation [message #697171 is a reply to message #697082] Fri, 15 July 2011 17:44 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Can u explain little bit more this is last step of my task,
should i change the grammer?for qualified name?
namerpovider instance of what?
Re: XText 2.0 --- Hover Documentation [message #697182 is a reply to message #697171] Fri, 15 July 2011 17:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi, you have to create and bind a IQualifiedNamePeovider that gives
your NonEmptyLine a Name. Easiest is to subclass
DefaultDeclarativeQualifiedNameProvider.

Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 15 July 2011 19:37]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #697430 is a reply to message #697182] Sat, 16 July 2011 18:24 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Rolling Eyes Hi Christian
First of all , I wish you a nice weekend!

Also why It does difference than Greeting sample ?
And for my NonEmptyline, Can you give some sample code please?

Best Regards
Re: XText 2.0 --- Hover Documentation [message #697449 is a reply to message #697430] Sat, 16 July 2011 19:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

The Qualified name Provider gives a stuff a qualified name and by default it uses the name attribute of an EOject to calculate it.
this is why greetings have a qualified name and your lines not.
Have a look at your personal blog posting: http://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.0 --- Hover Documentation [message #697475 is a reply to message #697449] Sat, 16 July 2011 22:43 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi

Tons of Thanks for your explanation, you are really helpful.
This is working really fine, and I guess I can use it for my dsl comment rule which is same with terminal single line comment rule,
On the other hand, if I have a keyword 'NEL' for nonemptyline as follows, when i point the NEL it works as well.

LibraryModel:
    (types+=Type)*;   

Type:
  NonEmptyline;
 	
NonEmptyline:
	'NEL' writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;

   Words hidden (): 	
    	ID (WS ID)*  	
    ;


However, my emptyline has not a keyword as follows,

NonEmptyline:
	writer=Words ':' book=Words ':'pageNumber=INT ',' isbn=INT
;

   Words hidden (): 	
    	ID (WS ID)*  	
    ;

Which means, i have to point on writer or another parameter for display a hover.

I tried to define onemore qualifiedname for writer, But Xtext didnt generate interface for writer and other book, isbn and pagenumbers.


it didnt work, i need to define somethng for writer parameter which has not a key word and part of the nonemptyline and as well as for other parameters. is there anyway to do this kind with Xtext 2.0 ?


BR Caner

[Updated on: Sun, 17 July 2011 09:20]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #697566 is a reply to message #697475] Sun, 17 July 2011 08:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i am not quite sure what you want to do

(1) get EClasses for Wrter books and co

short answer: RTFM
longer answer: RTFM at http://www.eclipse.org/Xtext/documentation/2_0_0/020-grammar-language.php#metamodelInference
even longer answer:

NonEmptyline:
	 writer=Writer ':' book=Book ':'pageNumber=PageNumber ',' isbn=ISBN
;

Writer:
	name=Words
;

Book:
	name=Words
;

PageNumber:
	value=INT
;

ISBN:
	value=INT
;

Words hidden (): 	
    ID (WS ID)*  	
;


(2) ????

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 17 July 2011 09:01]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #697582 is a reply to message #697566] Sun, 17 July 2011 10:01 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Yeah this is exactly what i wanted, now when I point on a parameter, i get different hover for each one,
So I had to change my grammar, and now everything is fine thank you so much again.
Best Regards

[Updated on: Sun, 17 July 2011 10:02]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #698446 is a reply to message #697582] Tue, 19 July 2011 13:43 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian

I hope you are fine
I want to ask that, how I can make unit testing for my hovers? and as well as myDSL?
BR
CANER
Re: XText 2.0 --- Hover Documentation [message #698460 is a reply to message #698446] Tue, 19 July 2011 14:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi, have no idea. Sry. Christian

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText 2.0 --- Hover Documentation [message #698464 is a reply to message #698460] Tue, 19 July 2011 14:22 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Wink no problem
BR
Re: XText 2.0 --- Hover Documentation [message #704330 is a reply to message #698464] Thu, 28 July 2011 14:02 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
No Message Body

[Updated on: Thu, 28 July 2011 14:02]

Report message to a moderator

Re: XText 2.0 --- Hover Documentation [message #714631 is a reply to message #704330] Thu, 11 August 2011 06:42 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian

I have a Xtext plugin which has been implemented with Xtext 2.0
Well
When I have installed the plugin on an Indigo, I have validations,coloring, and code completion features, they are working fine However Hovering is not working,
What might be reason?

BR
Caner
Re: XText 2.0 --- Hover Documentation [message #714632 is a reply to message #714631] Thu, 11 August 2011 06:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
No

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How can I define a rule which is each line must have just one type date?
Next Topic:how to validate over all files & customize new project wizard
Goto Forum:
  


Current Time: Thu Mar 28 11:31:35 GMT 2024

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

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

Back to the top