Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem customizing the outline(I tried to customize the outline tree creation, but if my DSL code is not well formed, I get errors from Eclipse)
Problem customizing the outline [message #1042013] Mon, 15 April 2013 22:19 Go to next message
Erick Fonseca is currently offline Erick FonsecaFriend
Messages: 68
Registered: December 2011
Member
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 13:37]

Report message to a moderator

Re: Problem customizing the outline [message #1042196 is a reply to message #1042013] Tue, 16 April 2013 05:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

the example grammar look strange.
in general: simply make the code nullsafe dont work?!?
Re: Problem customizing the outline [message #1042489 is a reply to message #1042196] Tue, 16 April 2013 13:46 Go to previous messageGo to next message
Erick Fonseca is currently offline Erick FonsecaFriend
Messages: 68
Registered: December 2011
Member
Sorry, I oversimplified my grammar in the original post, now I made the corrections.
I don't think being nullsafe is related to the problem. For example, if I have the following

foo
foo
x
foo
bar


after a couple of seconds I get an error message from Eclipse. It doesn't happen before the first foo or after bar. This is weird, because I just followed the instructions for the most basic outline tree editing.
Re: Problem customizing the outline [message #1042524 is a reply to message #1042489] Tue, 16 April 2013 14:34 Go to previous messageGo to next message
michael m is currently offline michael mFriend
Messages: 17
Registered: March 2013
Junior Member
Could you post the stacktrace?
It should give you at least a hint where this NPE happens.
Re: Problem customizing the outline [message #1042542 is a reply to message #1042524] Tue, 16 April 2013 14:54 Go to previous messageGo to next message
Erick Fonseca is currently offline Erick FonsecaFriend
Messages: 68
Registered: December 2011
Member
michael b wrote on Tue, 16 April 2013 10:34
Could you post the stacktrace?
It should give you at least a hint where this NPE happens.


Here it is:

java.lang.NullPointerException
at org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider._createNode(DefaultOutlineTreeProvider.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider.createNode(DefaultOutlineTreeProvider.java:106)
at org.xtext.example.mydsl.ui.outline.MyLangOutlineTreeProvider._createChildren(MyLangOutlineTreeProvider.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider.createChildren(DefaultOutlineTreeProvider.java:79)
at org.eclipse.xtext.ui.editor.outline.impl.AbstractOutlineNode$1.process(AbstractOutlineNode.java:80)
at org.eclipse.xtext.ui.editor.outline.impl.AbstractOutlineNode$1.process(AbstractOutlineNode.java:1)
at org.eclipse.xtext.util.concurrent.IUnitOfWork$Void.exec(IUnitOfWork.java:36)
at org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode$1.exec(DocumentRootNode.java:47)
at org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode$1.exec(DocumentRootNode.java:1)
at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:221)
at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:79)
at org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode.readOnly(DocumentRootNode.java:44)
at org.eclipse.xtext.ui.editor.outline.impl.AbstractOutlineNode.getChildren(AbstractOutlineNode.java:77)
at org.eclipse.xtext.ui.editor.outline.impl.OutlineRefreshJob.restoreChildrenSelectionAndExpansion(OutlineRefreshJob.java:68)
at org.eclipse.xtext.ui.editor.outline.impl.OutlineRefreshJob$1.exec(OutlineRefreshJob.java:60)
at org.eclipse.xtext.ui.editor.outline.impl.OutlineRefreshJob$1.exec(OutlineRefreshJob.java:1)
at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:221)
at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:79)
at org.eclipse.xtext.ui.editor.outline.impl.OutlineRefreshJob.refreshOutlineModel(OutlineRefreshJob.java:57)
at org.eclipse.xtext.ui.editor.outline.impl.OutlineRefreshJob.run(OutlineRefreshJob.java:46)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Re: Problem customizing the outline [message #1043203 is a reply to message #1042542] Wed, 17 April 2013 12:20 Go to previous messageGo to next message
michael m is currently offline michael mFriend
Messages: 17
Registered: March 2013
Junior Member
So and its not possible to set a breakpoint in
Quote:
org.xtext.example.mydsl.ui.outline.MyLangOutlineTreeProvider._createChildren(MyLangOutlineTreeProvider.java:26)

which should be triggered after a few sec?
Debug it from there to see whats wrong with the input.
Re: Problem customizing the outline [message #1043211 is a reply to message #1043203] Wed, 17 April 2013 12:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

why should this not be debuggable? in double overwrite it in your class
Re: Problem customizing the outline [message #1043466 is a reply to message #1042013] Wed, 17 April 2013 18:42 Go to previous message
Erick Fonseca is currently offline Erick FonsecaFriend
Messages: 68
Registered: December 2011
Member
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).
Previous Topic:Difference between JVMInferrer and Generator
Next Topic:Recursive Grammar
Goto Forum:
  


Current Time: Sat Nov 29 10:20:27 GMT 2014

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

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