Bug 30623 - Strange java delta when creating a new class
Summary: Strange java delta when creating a new class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 2.1 RC1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-30 11:45 EST by Estelle Ringenbach CLA
Modified: 2003-02-24 05:18 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Estelle Ringenbach CLA 2003-01-30 11:45:14 EST
I'm listening to the java delta in order to capture the creation of
classes, fields (I'm using the UI to create them). and I'm very surprised by 
the various delta that I got when a new java file is created

Indeed:
    my listener is called 4 times:
    The first time notifies that the java file has been added
    The second time notifies that the java file has been removed!!!
    The third and fourth one indicate the creation of the java file...

The code that gave me this result is the example provided in the 
help : "manipulating java code". My listener is on POST_CHANGE, and I'm using 
I200301071430.
On the news post, Jerome Lanneluc said that JavaCore.run() should be used.
Comment 1 Philipe Mulet CLA 2003-01-30 12:26:57 EST
Jerome - pls double check if our behavior is fine (or is it UI causing grief?)
Comment 2 Jerome Lanneluc CLA 2003-01-30 12:29:44 EST
Dirk, why did you move this bug to JDT/Core? Shouldn't JDT/UI use JavaCore.run
() when creating classes and fields?
Comment 3 Dirk Baeumer CLA 2003-01-31 03:11:08 EST
Jerome I should have been a little bit more explicit. Sorry. I moved it to 
JDT/Core since the bug says that the behaviour shows up with the example code 
provided in the help section manipulating java code. I thought you might want 
to update the help using JavaCore.run(...). 
Comment 4 Jerome Lanneluc CLA 2003-01-31 03:19:06 EST
I think Estelle meant that she's using the example code provided in the help 
section to listen to Java deltas. Otherwise she's using the UI to create fiels, 
classes... Estelle can you confirm?
Comment 5 Dirk Baeumer CLA 2003-01-31 04:01:51 EST
Jerome, you are right. She is saying that she is using the UI to create them, 
but we don't have dialogs to create methods and fields. I will dig into the 
problem of creating classes. 
Comment 6 Dirk Baeumer CLA 2003-01-31 05:21:53 EST
OK, I looked into your code and we are using JavaCore.run when creating a new 
type. Estelle, which build are you using. This got changed somewhere between M3 
and M4. To be sure you should use I20030129. 
Comment 7 Estelle Ringenbach CLA 2003-01-31 20:46:11 EST
I succefully reproduced the problem in the version I20030129 (1650), using 
Hello World plugin template from PDE and copying the code from 
the "Manipulating the java code" help section into the plugin class. 
The listener is registered at the end of the plugin constructor thanks to 
those two lines:
   		IElementChangedListener listener = new 
MyJavaElementChangeReporter();
		JavaCore.addElementChangedListener(listener, 
ElementChangedEvent.PRE_AUTO_BUILD);

Then to run, I activate the plugin, create a new class file using the class 
wizard, and I still get the 4 deltas I indicated in my initial post.

Hope this helps.
Comment 8 Dirk Baeumer CLA 2003-02-03 03:51:16 EST
Thanks, Estelle for your help. Here is what's happening:

- UI enclosed the creation of the new type in a runnable executed via 
  JavaCore.run.
- in fact 4 deltas are send out by the Java Model.
- first triggered by CompilationUnit.getSharedWorkingCOpy
- second triggered by WorkingCopy.reconcile
- thrid triggered by WorkingCopy.destroy
- forth triggered by Worksapce.endOperation.

Moving to Core for commenting on why working copy operations are send out 
immediatelly
Comment 9 Philipe Mulet CLA 2003-02-06 04:18:07 EST
Jerome - aren't we batching reconcile deltas ? 
Comment 10 Jerome Lanneluc CLA 2003-02-12 08:55:55 EST
We were not batching reconcile deltas. Added 3 new operations so as to be able 
to batch deltas for creation of shared working copies, deletion of shared 
working copies, and reconcile of working copies.
Comment 11 Estelle Ringenbach CLA 2003-02-16 21:16:34 EST
I'm using I20030214 and when I create a new java class using the wizard, my 
PRE_AUTO_BUILD listener is notified twice that a java class has been added.

The first PRE_AUTO_BUILD runs before the builder (what I expect) and the 
second one (PRE_AUTO_BUILD too) runs after the builder .....

I also noticed that the delta doesn't contain the creation of the IType 
correponding to the java class declaration (automatically created by the 
wizard).

The listener notification works fine when I create a java class without using 
the wizard : I create an empty file (with java extension), save it and fill it 
with a class declaration.

Comment 12 Jerome Lanneluc CLA 2003-02-17 05:12:16 EST
The first notification is the creation of the compilation unit. The second 
notification is the creation of the working copy (when the editor is opened).

The creation of the IType is implicitely notified by the notification of the 
creation of the ICompilationUnit (When an IJavaElement is added/removed, the 
addition/removal of its children is implicit)
Comment 13 Jerome Lanneluc CLA 2003-02-17 11:16:56 EST
Estelle, with the above explanation, is it ok to close ?
Comment 14 Philipe Mulet CLA 2003-02-17 15:00:44 EST
Our delta looks good. A compilation unit and a working copy are distinct 
elements.
Comment 15 Jerome Lanneluc CLA 2003-02-18 06:23:51 EST
Dirk, can you confirm that the UI does this in 2 batch operations? The first 
batch creates the compilation unit, the second opens the editor and creates the 
working copy.
Comment 16 Jerome Lanneluc CLA 2003-02-19 11:13:21 EST
Batching of delta is good. Please open a separate report against JDT/UI if you 
want the creation+opening of the type to be done in one batch.
Comment 17 David Audel CLA 2003-02-24 05:18:34 EST
Verified.