found IMarker strange behavior [message #1777130] |
Fri, 24 November 2017 19:09 |
Igor Adamovich Messages: 6 Registered: March 2017 |
Junior Member |
|
|
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 19:46] Report message to a moderator
|
|
|
Re: found IMarker strange behavior [message #1777133 is a reply to message #1777130] |
Fri, 24 November 2017 19:37 |
Igor Adamovich Messages: 6 Registered: March 2017 |
Junior Member |
|
|
If you are interested in testing my example, besides the java code you need to create some entities in plugin.xml (button and annotation).
Here is the code to be pasted in plugin.xml:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="ru.psiras.spec.menus.GenerateCurrent"
id="ru.psiras.spec.menus.generateCurrent"
name="generateCurrent">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="ru.psiras.spec.menus.Specialization">
<command
commandId="ru.psiras.spec.menus.generateCurrent"
icon="icons/sample.gif"
tooltip="Generate residual programs for active page opened in editor"
label="Generate current">
</command>
</toolbar>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.editors.markerAnnotationSpecification"
id="testAnnotationSpecification" name="testAnnotation">
<specification annotationType="ru.psiras.spec.markers.testannotation"
label="test annotation"
overviewRulerPreferenceKey="sa.ruler"
overviewRulerPreferenceValue="false"
contributesToHeader = "false"
colorPreferenceKey="sa.color"
colorPreferenceValue="128,255,128"
textPreferenceKey="sa.text"
textPreferenceValue="false"
verticalRulerPreferenceKey="sa.vertical"
verticalRulerPreferenceValue="true"
textStylePreferenceKey="sa.style"
textStylePreferenceValue="NONE"
highlightPreferenceValue = "true"
highlightPreferenceKey="sa.highlight">
</specification>
</extension>
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
name="ru.psiras.spec.markers.testannotation"
markerType="ru.psiras.spec.markers.testmarker"/>
</extension>
<extension id="ru.psiras.spec.markers.testmarker" point="org.eclipse.core.resources.markers" name="Cool Marker">
<persistent value="false"/>
<super type="org.eclipse.core.resources.textmarker"/>
</extension>
After this you should create ru.psiras.spec.menus.GenerateCurrent class. It's code is given in topic starting message.
[Updated on: Fri, 24 November 2017 19:39] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02959 seconds