Problem customizing the outline [message #1042013] |
Mon, 15 April 2013 18:19  |
Eclipse User |
|
|
|
So, I tried to customize the outline tree provider for my DSL. The grammar starts like this:
MyLang:
definitions += Definition+
main = Main
;
Definition:
foo='foo'
;
Main:
bar='bar'
;
And I added the following xtend class:
class MyLangOutlineTreeProvider extends org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider {
def protected void _createChildren(DocumentRootNode parentNode, MyLang lang)
{
for (Definition definition : lang.definitions)
{
createNode(parentNode, definition)
}
createNode(parentNode, lang.main)
}
}
When I run the MyLang editor, it works, but if add some garbage after or between the definitions, I get the following Eclipse error: "Error refreshing outline
java.lang.NullPointerException"
Am I doing something wrong?
[Updated on: Tue, 16 April 2013 09:37] by Moderator
|
|
|
|
|
|
|
|
|
Re: Problem customizing the outline [message #1043466 is a reply to message #1042013] |
Wed, 17 April 2013 14:42  |
Eclipse User |
|
|
|
So, I set up a breakpoint and saw what I suspected.
The createNode method is called succesfully for each "foo" appearing before the unexpected "x". Then, the for loop ends and createNode is called with lang.main as the second argument. However, the attribute main is null, which causes the problem.
This is obviously because Xtext couldn't parse a non-well formed instance of MyLang. Now, I don't see how this setup could be used in practice: whenever this kind of situation occurs (usually, when the user is editing a file), an error popup will appear. Pretty annoying. I guess I could use try/catch in the OutlineTreeProvider for every similar rule (or check if the attribute is not null).
|
|
|
Powered by
FUDForum. Page generated in 0.04493 seconds