Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » found IMarker strange behavior
found IMarker strange behavior [message #1777130] Fri, 24 November 2017 19:09 Go to next message
Igor Adamovich is currently offline Igor AdamovichFriend
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:
https://media.giphy.com/media/26u8y8UQz7dWNwfC0/giphy.gif

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:
https://media.giphy.com/media/3osBLz2wvV43Cyd74Q/giphy.gif

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 Go to previous messageGo to next message
Igor Adamovich is currently offline Igor AdamovichFriend
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

Re: found IMarker strange behavior [message #1777164 is a reply to message #1777133] Sat, 25 November 2017 09:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marker creation is a modification of the IResource model. Each such modification produces an IResourceDelta, and that's a relatively expensive process depending on what all the listeners are doing. As such, when doing many modifications like what you show in the code, you should use one of the IWorkspace.run methods to batch the changes such that they produce a single resource delta, not thousands of them.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: found IMarker strange behavior [message #1777166 is a reply to message #1777164] Sat, 25 November 2017 11:55 Go to previous message
Igor Adamovich is currently offline Igor AdamovichFriend
Messages: 6
Registered: March 2017
Junior Member
Big thanks! It's the solution.
Previous Topic:duplicate topic in this forum, please delete this.
Next Topic:HTTP Proxy Authentication Error with Neon
Goto Forum:
  


Current Time: Wed Apr 24 15:32:19 GMT 2024

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

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

Back to the top