Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JavaSourceViewerConfiguration in own editor(How can I use JavaSourceViewerConfiguration in my own editor..?)
JavaSourceViewerConfiguration in own editor [message #1391634] Tue, 01 July 2014 07:13 Go to next message
Pjot Odor is currently offline Pjot OdorFriend
Messages: 3
Registered: June 2014
Junior Member
Hi,

I am trying to better understand how the code assistance/auto completion works in eclipse, and in this process I have created an editor (plug-in) from the example package org.eclipse.ui.examples.javaeditor. What I want is the same auto completion that is already implemented in eclipse, the reason being that I want to try and use it in another way in a plug-in or a java program. Is this possible?

What I am trying right now is this. I set up the SourceViewer, in JavaEditor.java, like this:

protected void initializeEditor() {
super.initializeEditor();
IPreferenceStore store= getPreferenceStore();
JavaSourceViewerConfiguration config = new JavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING);
setSourceViewerConfiguration(config);
}

Should this be enough to set up the auto completion? I am very unsure how this works, I also tried changing the function createSourceViewer, also in JavaEditor.java, like so:

protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
fAnnotationAccess= createAnnotationAccess();
fOverviewRuler= createOverviewRuler(getSharedColors());
ISourceViewer viewer = new JavaSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles, getPreferenceStore());

getSourceViewerDecorationSupport(viewer);

return viewer;
}

The result is the pop-up window like in Eclipse shows up, but it says "No default proposals" no matter what. What more things do I need to consider here?

Many thanks in advance!

Edit 1: Note that the JavaEditor class is extended from TextEditor in org.eclipse.ui.editors.text.

[Updated on: Tue, 01 July 2014 07:16]

Report message to a moderator

Re: JavaSourceViewerConfiguration in own editor [message #1391687 is a reply to message #1391634] Tue, 01 July 2014 08:55 Go to previous message
Pjot Odor is currently offline Pjot OdorFriend
Messages: 3
Registered: June 2014
Junior Member
So I made some progress, and thought I'd share it in case anyone else is struggling with this. Also I bumped in to some new problems.
I changed approach slighly, now I have just created an editor plug-in from the template "plug-in with an editor". I named it SampleEditor and added a few lines to the constructor in SampleEditor.java making it look like this:

public SampleEditor() {
super();
colorManager = new ColorManager();
IPreferenceStore store= getPreferenceStore();
JavaSourceViewerConfiguration config = new JavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING);
setSourceViewerConfiguration(config);
}

Some problems i run in to:
1. When I try to run in in a separate Eclipse, it doesn't work. I get the error message "This compilation unit is not on the build path of a Java project".

However when I export it to a .jar file and put it in my Eclipse dropins folder, it works to some extent. When I hover with the mouse or press ctrl+space somewhere in the code it works just like in eclipse, and I get some documentation to pop-up with information about the class. Also writing syso + 'ctrl+space' gives the System.out.println() line. But when I try to get completion proposals it goes wrong.

2. When I try to write for example SomeClass. and hit 'ctrl+space' I get the error message "Cannot access compilation unit Reason: Index out of bounds".

I get the feeling that 1. and 2. are closely related. Anyone have any ideas on how I can go from here?

EDIT: I have come to understand that you are not supposed to use JavaSourceViewerConfiguration in a self made plug-in, since it is internal (Whatever that means?). Is there any other way to mimic the behaviour of the code assist in Eclipse that anyone knows of?

[Updated on: Tue, 01 July 2014 11:03]

Report message to a moderator

Previous Topic:save preferences between workspaces
Next Topic:Variables view sometimes loses selection when hitting a breakpoint a second time
Goto Forum:
  


Current Time: Thu Dec 26 12:53:39 GMT 2024

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

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

Back to the top