[xtext 2] How to get EObject from an specific line of an XtextEditor? [message #661690] |
Sat, 26 March 2011 09:00 |
Alex Ruiz Messages: 103 Registered: March 2011 |
Senior Member |
|
|
Greetings,
How can I get the EObject that is the result of parsing a particular line in an XtextEditor?
So far I have this:
IXtextDocument document = editor.getDocument();
EList<EObject> objects = document.readOnly(new IUnitOfWork<EList<EObject>, XtextResource>() {
@Override public EList<EObject> exec(XtextResource state) throws Exception {
return state.getContents();
}
});
but it returns all the EObjects from the contents of the XtextEditor, which is useful to me as well. The only missing part is getting the EObject that belongs to a line in the XtextEditor (e.g. EObject from line 6 in an XtextEditor.)
Any help will be greatly appreciated
Thanks,
-Alex
[Updated on: Sun, 03 April 2011 08:16] Report message to a moderator
|
|
|
|
|
Re: How to get EObject from an specific line of an XtextEditor? [message #661703 is a reply to message #661690] |
Sat, 26 March 2011 12:41 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
You can get a Node from an EObject (it is in an adapter), or the EObject
from a Node.
You can traverse the Node tree, or the EObject tree (whatever works best
in your use case).
To make it general you probably have to deal with things like:
- Several EObjects on one line
- An EObject that is on several lines
- An EObject ending on one line, followed by one or more EObjects.
- Hidden text (WS, comments etc.)
- henrik
On 3/26/11 10:01 AM, Alex Ruiz wrote:
> Greetings,
>
> How can I get the EObject that is the result of parsing a particular
> line in an XtextEditor?
>
> So far I have this:
>
>
> IXtextDocument document = editor.getDocument();
> EList<EObject> objects = document.readOnly(new
> IUnitOfWork<EList<EObject>, XtextResource>() {
> @Override public EList<EObject> exec(XtextResource state) throws
> Exception {
> return state.getContents();
> }
> });
>
>
> but it returns all the EObjects from the contents of the XtextEditor,
> which is useful to me as well. The only missing part is getting the
> EObject that belongs to a line in the XtextEditor (e.g. EObject from
> line 6 in an XtextEditor.)
>
> Any help will be greatly appreciated :)
>
> Thanks,
> -Alex
>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03489 seconds