found IMarker strange behavior [message #1777130] |
Fri, 24 November 2017 14:09  |
Eclipse User |
|
|
|
I found IMarker strange behavior.
I am currently working on Eclipse plugin that intensively use IMarkers to highlight a code. After some point i realizes that Eclipse paints markers relatively slow. Look at example:

After some attempts to find a solution, i found strange behaviour of Eclipse: when you add a AnnotationModel to active Editor, markers for this editor painted in a blink of an eye.
Here is an example of code, that puts 2000 markers to open java code, that markers would be painted slowly (i used this code to capture image above):
public class GenerateCurrent extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot workspaceRoot = workspace.getRoot();
IJavaModel javaModel = JavaCore.create(workspaceRoot);
IEditorInput editorInput= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
ITypeRoot root = null;
if (editorInput != null) {
IJavaElement input= JavaUI.getEditorInputJavaElement(editorInput);
if (input instanceof ITypeRoot) {
root = (ITypeRoot) input;
}
}
if (root == null) {
System.out.println("Can not convert to ITypeRoot");
return null;
}
IResource res = root.getResource();
IDocumentProvider provider = ((ITextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).getDocumentProvider();
AnnotationModel am = (AnnotationModel)provider.getAnnotationModel((PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput()));
//IAnnotationModel newAM = new AnnotationModel();
//am.addAnnotationModel(newAM, newAM);
try {
for (int i = 0; i < 2000; i++) {
IMarker marker = res.createMarker("ru.psiras.spec.markers.testmarker");
marker.setAttribute(IMarker.CHAR_START, i);
marker.setAttribute(IMarker.CHAR_END, i+1);
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
You could expect comment lines. In this lines i am simply creates new AnnotationModel and adds it to Editor's AnnotationModel. After this, there is no usage of this newly created AnnotationModel. When this lines are uncommented, Eclipse paints markers in a moment, here is an screen capture of this event:

Is it bug, or i am missing something?
P.S.
Founded trick is not solution for me, because of different usage conditions: when i create markers for IResource i knows nothing about Editor that would hold AnnotationModel .
Thanks for future answers.
[Updated on: Fri, 24 November 2017 14:46] by Moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.12816 seconds