Gangmax Blog

Three Eclipse Problems I Met

OSGi bundle issue

After I added a “org.eclipse.ui.views.contentoutline.ContentOutlinePage.java(abstract class)” implementation in my code and compiled it, I found running the eclipse plug-in would get an “ClassNotFoundError” which complained that it could’t find the “ContentOutlinePage” class.

It took me some time to figure out the root cause is: I forgot to add the “org.eclipse.ui.views” bundle, where the “ContentOutlinePage” class is in, to the “MANIFEST.MF” file like below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Require-Bundle: org.eclipse.ant.launching,
org.eclipse.jdt.core,
org.eclipse.debug.core,
org.eclipse.help.ui,
org.eclipse.ui.forms,
org.eclipse.ui.ide,
org.eclipse.ui.navigator,
org.eclipse.ui.editors,
org.eclipse.ui.views,
org.eclipse.jface.text,
org.eclipse.jdt.ui,
org.eclipse.ui.console,
org.eclipse.ui.externaltools,
org.junit

This is all the OSGi moduling system all about: if you want to use some exposed interfaces(not java interface) of the other modules in the moduling system, you need to declare that in your “MANIFEST.MF”.

Adapter issue

In order to link the outline view with the text editor, I need to override the “public Object getAdapter(Class adapter)” method of the text editor class, in which I return a customized “ContentOutlinePage” instance when it’s needed.

But after I did so, I found it didn’t work: the outline view was not be displayed when the editor was opened. It took me much time to figure out the problem. All at a sudden, I realize I may override the “getAdapter()” method at wrong place.

In our program, we have a customized “FormEditor” class, which is a “MultiPageEditorPart” class also(super class of FormEditor). And our “JsonTextEditor” class is a “TextEditor”, which is one page of our “FormEditor” class.

At first I overrided the “getAdatper()” method of “JsonTestEditor” which didn’t work. Then I realized maybe I should override the “getAdapter()” method of “FormEditor”. After I did so, it works.

The lession is: consider the code structure before adding required code mechanism by the framework.

One more

Slicing a substring from the original one with 1 character missing, makes the whole parsing result wrong.

I was working on implementing the syntax color feature of the JSON text editor in in the last two days. That means I need to parse the words in the JSON document and return the “IToken” instance for each parsed segment.

One issue supprised me when I was debugging it: after I trim the meaningless leading/ending characters of the segement, the parsing result is totally messed up. How did this happen?

After some step-by-step tracing, I found the problem is: I slices the meaning sgement content from the original one with the last character “"“ missed, then the parsing method return an “IToken.UNDEFINED”. When eclipse got such a token, it will bypass the current “IRule” instance and try the others. So the parsing result is totally unexpected.

The lesson is I didn’t understand “IToken.UNDEFINED” well. This return value will make the current IRule ignore the parsed content by the IRule instance and try the others IRule instances.

Comments