Bug 37161 - Batch Code Generation is not supported
Summary: Batch Code Generation is not supported
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-01 22:33 EDT by Daniel Berg CLA
Modified: 2004-05-06 07:59 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Berg CLA 2003-05-01 22:33:18 EDT
We have a code generation framework that uses the JDT APIs to create and delete 
compilation unit elements.  We have the framework setup such that we can 
generate changes while the Java editor is open on a file.  In this case, we 
generate into the open file.
What we have found is that doing multiple delete elements (e.g., fields and 
methods) within the CompilationUnit is extremely slow and it gets worse the 
larger the class and the more elements that are updated.  Looking into the 
problem, it appears that the save(...) on the WorkingCopy performs a reconcile
().  This happens on each and every element add, remove, or update.  This is 
expensive and slow.  What we would like is a capability to halt the save on the 
WorkingCopy by the JavaModelOperations while doing a batch set of changes.  
After the changes are complete, we would then save all WorkingCopies that have 
been modified and at this time the reconcile will take place.  Basically, we 
would only have one reconcile() on a particular WorkingCopy during this batch 
codegen instead of possible hundreds.
Comment 1 Olivier Thomann CLA 2003-05-02 10:56:23 EDT
Are you sure that the JavaCore.run(IWorkspaceRunnable action, IProgressMonitor
monitor) throws CoreException doesn't do what you want?
Comment 2 Philipe Mulet CLA 2003-05-05 06:49:22 EDT
Indeed, batching JavaModel operations was added for 2.1. If properly batched, 
then only one reconciliation action should occur at the end.

Is it ok to close ?
Comment 3 Daniel Berg CLA 2003-05-05 09:30:37 EDT
We did try using JavaCore.run(IWorkspaceRunnable action, IProgressMonitor
monitor) throws CoreException but it appeared that the reconcile still took 
place but the notifications were batched and sent at the end.

Should this stop the reconcile altogether?  I still see the save(...) method 
being called irregardless of whether this api is used or not.
Comment 4 Philipe Mulet CLA 2003-05-05 12:31:40 EDT
I see. The philosophy of the model is that side-effects are updating the model 
as they are performed. This is why the element additions, even if batched, are 
still performed immediately. The generated delta is accumulated until the end 
of the batch operation, and only notified at once. 

Thus, one can create a method, and immediately after use it (instead of waiting 
until the batch operation ends).

What you would need instead is to create a DOM ASTof the unit, update it all at 
once and commit it at the end. Unfortunately, there is currently no API for 
writing out some modified DOM AST back to source (this is on the 3.0 plan). 
JDT/UI has defined such custom mechanism for refactoring purpose though.

Comment 5 Gili Mendel CLA 2003-09-30 15:43:59 EDT
Besides the reconcile batching, It would be a good thing to allow one to
postpone the linkage between the model changing and the consequence change onto
the AnnotationModel (call to endReporting() from ReconcileWorkingCopyOperation),
like the AnnotationPainter.

We have a scenario were a set of instance fields, getter methods and IMethods
updates are made to a compilation unit (with error/warnings) in one Compound
command.  

Reconcile is slow, but, it may be called in between to ensure a consistent model
when needed. There is no need for the model change to propagate to its
listeners.  In our case we would not even want the JavaEditor "fliker" while the
 updates are in progress.
Comment 6 Philipe Mulet CLA 2003-10-01 09:35:05 EDT
The JDOM (you are using) is going to be deprecated as soon as the new DOM 
serialization support is added (on 3.0 plan). Using the DOM, you will be able 
to perform sets of changes and only persist them as source at the end.

However this is still work in progress.

Comment 7 Philipe Mulet CLA 2003-10-01 09:35:52 EDT
Just to further clarify, some of the JDOM APIs like move, copy are allowing to 
batch changes, but not all of them (create). 
Comment 8 Philipe Mulet CLA 2004-02-17 13:05:42 EST
David - please close once rewrite support is in.
Comment 9 Philipe Mulet CLA 2004-05-06 06:37:24 EDT
Rewrite support is now in.
Comment 10 David Audel CLA 2004-05-06 07:59:59 EDT
Rewrite support is now in

look at
org.eclipse.jdt.core.dom.rewrite.ASTRewrite
and
org.eclipse.jdt.core.dom.CompilationUnit#recordModifications()
org.eclipse.jdt.core.dom.CompilationUnit#rewrite(IDocument,Map)