Hover provider for terminal rules [message #1699970] |
Mon, 29 June 2015 13:45 |
Mohsin waqas Messages: 33 Registered: June 2015 |
Member |
|
|
Hello,
MyGrammar is like:
Model: entities += Entity*;
Entity:
'entity' name = ID REGVALUE ('extends' superType=[Entity])? '{'
attributes += Attribute*
'}'
;
Attribute:
'<<<<' name=ID '>>>>'
;
terminal REGVALUE:'REGNO'('0'..'9')('0'..'9')*;
using the following MydslEObjectHoverProvider, i have implemented hover for rule "Entity"
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider;
import org.xtext.example.tet.*;
public class MydslEObjectHoverProvider extends DefaultEObjectHoverProvider {
@Override
protected String getFirstLine(EObject o) {
if (o instanceof Entity) {
return "this is a test hover: " + ((Entity)o).getName();
}
return super.getFirstLine(o);
}
}
but when I try to provide hover for terminal rule "REGVALUE", I am not able to do that. I cannot write like this
if (o instanceof REGVALUE) {
return "this is a test hover: " + ((REGVALUE)o).getName();
}
please guide me in which way should i go?
[Updated on: Mon, 29 June 2015 14:17] Report message to a moderator
|
|
|
Re: Hover provider for terminal rules [message #1699971 is a reply to message #1699970] |
Mon, 29 June 2015 13:49 |
|
Hi,
i do not understand what you want to do but you may debug into org.eclipse.xtext.resource.ILocationInFileProvider.getSignificantTextRegion(EObject) and org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int) and org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.hasHover(EObject) and others
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Hover provider for terminal rules [message #1721086 is a reply to message #1721085] |
Sat, 23 January 2016 15:09 |
|
Hi,
i dont understand your point. you can hover at everything!!!!!!
but if you want to do strange things you have to care yourself
(debugging is your friend)
the starting point is as a said before org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getHoverRegion(ITextViewer, int)
which calls
org.eclipse.xtext.ui.editor.hover.AbstractEObjectHover.getXtextElementAt(XtextResource, int)
this is the place where boris' implementation gives back the keyword.
keywords from grammar access are eobjects like rules and all other stuff in your grammar.
in your case it may be a org.eclipse.xtext.RuleCall which rules is the terminal rule PUSH_POP_OP
(once more a debugger will help)
from the node model you can not only get the grammar stuff you are at,
but you can get the text as well (INode.getText)
of course you would it make 1000000000 times easier when using a datatype rule
instead of a terminal
PUSH_POP_OP:
('push' | 'pop' )CONDITION_SUFFIX?
;
(no terminal keyword)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.05596 seconds