Skip to main content



      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 18:19 Go to next message
Eclipse UserFriend
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 #1042196 is a reply to message #1042013] Tue, 16 April 2013 01:23 Go to previous messageGo to next message
Eclipse UserFriend
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 09:46 Go to previous messageGo to next message
Eclipse UserFriend
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 10:34 Go to previous messageGo to next message
Eclipse UserFriend
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 10:54 Go to previous messageGo to next message
Eclipse UserFriend
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 08:20 Go to previous messageGo to next message
Eclipse UserFriend
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 08:29 Go to previous messageGo to next message
Eclipse UserFriend
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 14:42 Go to previous message
Eclipse UserFriend
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: Tue Jul 22 14:30:24 EDT 2025

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

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

Back to the top