Skip to main content



      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 08:40 Go to next message
Eclipse UserFriend
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 09:04] by Moderator

Re: XText 2.0 --- Hover Documentation [message #696735 is a reply to message #696628] Thu, 14 July 2011 14:14 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Thu, 14 July 2011 14:15] by Moderator

Re: XText 2.0 --- Hover Documentation [message #696741 is a reply to message #696735] Thu, 14 July 2011 14:26 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XText 2.0 --- Hover Documentation [message #696756 is a reply to message #696741] Thu, 14 July 2011 15:08 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian,
I gonna try to figure it out and come back Wink
Thanks again

[Updated on: Tue, 19 July 2011 10:11] by Moderator

Re: XText 2.0 --- Hover Documentation [message #696769 is a reply to message #696756] Thu, 14 July 2011 15:37 Go to previous messageGo to next message
Eclipse UserFriend
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 15:40 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Thu, 14 July 2011 15:58] by Moderator

Re: XText 2.0 --- Hover Documentation [message #696783 is a reply to message #696770] Thu, 14 July 2011 16:12 Go to previous messageGo to next message
Eclipse UserFriend
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 04:46 Go to previous messageGo to next message
Eclipse UserFriend
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 04:46] by Moderator

Re: XText 2.0 --- Hover Documentation [message #696979 is a reply to message #696977] Fri, 15 July 2011 04:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: XText 2.0 --- Hover Documentation [message #697071 is a reply to message #696979] Fri, 15 July 2011 09:10 Go to previous messageGo to next message
Eclipse UserFriend
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 09:13] by Moderator

Re: XText 2.0 --- Hover Documentation [message #697073 is a reply to message #697071] Fri, 15 July 2011 09:14 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Fri, 15 July 2011 09:18] by Moderator

Re: XText 2.0 --- Hover Documentation [message #697082 is a reply to message #697073] Fri, 15 July 2011 09:36 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XText 2.0 --- Hover Documentation [message #697171 is a reply to message #697082] Fri, 15 July 2011 13:44 Go to previous messageGo to next message
Eclipse UserFriend
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 13:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi, you have to create and bind a IQualifiedNamePeovider that gives
your NonEmptyLine a Name. Easiest is to subclass
DefaultDeclarativeQualifiedNameProvider.

Regards Christian

[Updated on: Fri, 15 July 2011 15:37] by Moderator

Re: XText 2.0 --- Hover Documentation [message #697430 is a reply to message #697182] Sat, 16 July 2011 14:24 Go to previous messageGo to next message
Eclipse UserFriend
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 15:40 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: XText 2.0 --- Hover Documentation [message #697475 is a reply to message #697449] Sat, 16 July 2011 18:43 Go to previous messageGo to next message
Eclipse UserFriend
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 05:20] by Moderator

Re: XText 2.0 --- Hover Documentation [message #697566 is a reply to message #697475] Sun, 17 July 2011 04:51 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Sun, 17 July 2011 05:01] by Moderator

Re: XText 2.0 --- Hover Documentation [message #697582 is a reply to message #697566] Sun, 17 July 2011 06:01 Go to previous messageGo to next message
Eclipse UserFriend
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 06:02] by Moderator

Re: XText 2.0 --- Hover Documentation [message #698446 is a reply to message #697582] Tue, 19 July 2011 09:43 Go to previous messageGo to next message
Eclipse UserFriend
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 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi, have no idea. Sry. Christian
Re: XText 2.0 --- Hover Documentation [message #698464 is a reply to message #698460] Tue, 19 July 2011 10:22 Go to previous messageGo to next message
Eclipse UserFriend
Wink no problem
BR
Re: XText 2.0 --- Hover Documentation [message #704330 is a reply to message #698464] Thu, 28 July 2011 10:02 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Thu, 28 July 2011 10:02] by Moderator

Re: XText 2.0 --- Hover Documentation [message #714631 is a reply to message #704330] Thu, 11 August 2011 02:42 Go to previous messageGo to next message
Eclipse UserFriend
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 02:44 Go to previous message
Eclipse UserFriend
No
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: Mon Jul 28 17:20:19 EDT 2025

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

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

Back to the top