Bug 271962 - [API] JavaCore - IElementChangedListener, incorrect behavior
Summary: [API] JavaCore - IElementChangedListener, incorrect behavior
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-12 13:17 EDT by Jean-Rémi Desjardins CLA
Modified: 2009-05-15 06:58 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Rémi Desjardins CLA 2009-04-12 13:17:59 EDT
Build ID: M20090211-1700

Steps To Reproduce:
1.Create a new Eclipse plug-in
2.Register the (AbstractUIPlugin) as a IElementChangedListener of the (JavaCore)
3. Have the plug-in do some recognizable action when he receives a notification form the (JavaCore)
4. Run the plug-in in the Eclipse-Runtime
5. Change focus from one editor to another.


More information:
When you activate an editor, the JavaCore will send a ElementChanged event describing a change too every single element contained in the given editor window.
Comment 1 Srikanth Sankaran CLA 2009-05-12 05:55:32 EDT
(In reply to comment #0)
> Build ID: M20090211-1700
> Steps To Reproduce:
> 1.Create a new Eclipse plug-in
> 2.Register the (AbstractUIPlugin) as a IElementChangedListener of the
> (JavaCore)
> 3. Have the plug-in do some recognizable action when he receives a notification
> form the (JavaCore)
> 4. Run the plug-in in the Eclipse-Runtime
> 5. Change focus from one editor to another.
> More information:

Hello, it would have helped if you had indicated what exactly you thought
was a bug. 

> When you activate an editor, the JavaCore will send a ElementChanged event
> describing a change too every single element contained in the given editor
> window.

Did you register your plugin as an IElementChangedListener via
org.eclipse.jdt.core.JavaCore.addElementChangedListener(IElementChangedListener)
In that case, what you are seeing would be the right behavior.
The numerous element changed notifications you are seeing are
due to "working copy reconcile operation". The call to the method
addElementChangedListener sets it up so that there is a
notification for every ElementChangedEvent.POST_CHANGE and ElementChangedEvent.POST_RECONCILE. 

Based on your requirements, you may want to use
org.eclipse.jdt.core.JavaCore.addElementChangedListener(IElementChangedListener, int)
instead which actually allows you choose the events you
want to be notified about and you could omit the POST_RECONCILE event if
you don't want instantaneous feedback on fine grained changes that are
happening to the working copy.

Please see also the documentation on ElementChangedEvent class.

If I have not understood your problem and you think there is a
real bug here, please clarify -- Thanks.




Comment 2 Srikanth Sankaran CLA 2009-05-14 05:14:27 EDT
Closing this defect as INVALID since what is reported is
the right behavior and a workaround has been suggested to
filter out (what are seen to be) the  unwanted notifications.

Please reopen if defect has been misunderstood.
Comment 3 Frederic Fusier CLA 2009-05-15 05:28:26 EDT
Not sure to completely understand the problem though as only change the focus does not send any ElementChangedEvent events... But I agree that each time a character is hit in an editor, then registered listeners receive this kind of events and, as I Srikanth said, this is the expected behavior...

So consider this as verified for 3.5RC1 as the reconcile event can easily be filtered using the API with the event type mask Skrikanth refers to in comment 1.

Comment 4 Srikanth Sankaran CLA 2009-05-15 06:58:45 EDT
(In reply to comment #3)
> Not sure to completely understand the problem though as only change the focus
> does not send any ElementChangedEvent events... 

Actually, it does, when a dormant editor tab gets activated
for the first time in a session. This triggers a 
"become working copy" operation which generates a 
ElementChangedEvent.POST_CHANGE. Switching between editor tabs
that were activated already in a session does not generate further
ElementChangedEvent's.

Similarly, closing an editor by clicking on the X also generates
a POST_CHANGE event from the "discard working copy" operation.

So fortunately, there is no pending mystery here :)

Here is a sample call stack:

BytecodePerformance.elementChanged(ElementChangedEvent) line: 149	
DeltaProcessor$3.run() line: 1557	
SafeRunner.run(ISafeRunnable) line: 42	
DeltaProcessor.notifyListeners(IJavaElementDelta, int, IElementChangedListener[], int[], int) line: 1547	
DeltaProcessor.firePostChangeDelta(IJavaElementDelta, IElementChangedListener[], int[], int) line: 1381	
DeltaProcessor.fire(IJavaElementDelta, int) line: 1357	
BecomeWorkingCopyOperation(JavaModelOperation).run(IProgressMonitor) line: 769	
BecomeWorkingCopyOperation(JavaModelOperation).runOperation(IProgressMonitor) line: 788	
CompilationUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor) line: 100	
CompilationUnitDocumentProvider.createFileInfo(Object) line: 983	
CompilationUnitDocumentProvider(TextFileDocumentProvider).connect(Object) line: 478	
CompilationUnitDocumentProvider.connect(Object) line: 1198	
CompilationUnitEditor(AbstractTextEditor).doSetInput(IEditorInput) line: 4100	
CompilationUnitEditor(StatusTextEditor).doSetInput(IEditorInput) line: 203	
CompilationUnitEditor(AbstractDecoratedTextEditor).doSetInput(IEditorInput) line: 1330	
CompilationUnitEditor(JavaEditor).internalDoSetInput(IEditorInput) line: 2552	
CompilationUnitEditor(JavaEditor).doSetInput(IEditorInput) line: 2525	
CompilationUnitEditor.doSetInput(IEditorInput) line: 1371	
AbstractTextEditor$19.run(IProgressMonitor) line: 3081	
ModalContext.runInCurrentThread(IRunnableWithProgress, IProgressMonitor) line: 464	
ModalContext.run(IRunnableWithProgress, boolean, IProgressMonitor, Display) line: 372	
ApplicationWindow$1.run() line: 759	
BusyIndicator.showWhile(Display, Runnable) line: 70	
WorkbenchWindow(ApplicationWindow).run(boolean, boolean, IRunnableWithProgress) line: 756	
WorkbenchWindow.run(boolean, boolean, IRunnableWithProgress) line: 2576	
CompilationUnitEditor(AbstractTextEditor).internalInit(IWorkbenchWindow, IEditorSite, IEditorInput) line: 3099	
CompilationUnitEditor(AbstractTextEditor).init(IEditorSite, IEditorInput) line: 3126	
EditorManager.createSite(IEditorReference, IEditorPart, EditorDescriptor, IEditorInput) line: 798	
EditorReference.createPartHelper() line: 641	
EditorReference.createPart() line: 459	
EditorReference(WorkbenchPartReference).getPart(boolean) line: 595	
EditorReference.getPart(boolean) line: 821	
EditorPane(PartPane).setVisible(boolean) line: 313	
PresentablePart.setVisible(boolean) line: 180	
PresentablePartFolder.select(IPresentablePart) line: 270	
LeftToRightTabOrder.select(IPresentablePart) line: 65	
TabbedStackPresentation.selectPart(IPresentablePart) line: 473	
EditorStack(PartStack).refreshPresentationSelection() line: 1256	
EditorStack(PartStack).setSelection(LayoutPart) line: 1209	
EditorStack(PartStack).presentationSelectionChanged(IPresentablePart) line: 843	
PartStack.access$1(PartStack, IPresentablePart) line: 829	
PartStack$1.selectPart(IPresentablePart) line: 139	
TabbedStackPresentation$1.handleEvent(TabFolderEvent) line: 133	
DefaultTabFolder(AbstractTabFolder).fireEvent(TabFolderEvent) line: 270	
DefaultTabFolder(AbstractTabFolder).fireEvent(int, AbstractTabItem) line: 279	
DefaultTabFolder.access$1(DefaultTabFolder, int, AbstractTabItem) line: 1	
DefaultTabFolder$2.handleEvent(Event) line: 87	
EventTable.sendEvent(Event) line: 84	
CTabFolder(Widget).sendEvent(Event) line: 1003	
CTabFolder(Widget).sendEvent(int, Event, boolean) line: 1027	
CTabFolder(Widget).sendEvent(int, Event) line: 1012	
CTabFolder(Widget).notifyListeners(int, Event) line: 770	
CTabFolder.setSelection(int, boolean) line: 3256	
CTabFolder.onMouse(Event) line: 2045	
CTabFolder$1.handleEvent(Event) line: 323	
EventTable.sendEvent(Event) line: 84	
CTabFolder(Widget).sendEvent(Event) line: 1003	
Display.runDeferredEvents() line: 3880	
Display.readAndDispatch() line: 3473	
Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2405	
Workbench.runUI() line: 2369	
Workbench.access$4(Workbench) line: 2221	
Workbench$5.run() line: 500	
Realm.runWithDefault(Realm, Runnable) line: 332	
Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 493	
PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
IDEApplication.start(IApplicationContext) line: 113	
EclipseAppHandle.run(Object) line: 194	
EclipseAppLauncher.runApplication(Object) line: 110	
EclipseAppLauncher.start(Object) line: 79	
EclipseStarter.run(Object) line: 368	
EclipseStarter.run(String[], Runnable) line: 179	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
Method.invoke(Object, Object...) line: 597	
Main.invokeFramework(String[], URL[]) line: 559	
Main.basicRun(String[]) line: 514	
Main.run(String[]) line: 1311	
Main.main(String[]) line: 1287