Project: JDT
Bug 158375 [actions] Poor performance in FormatAllAction.runOnMultiple with single file.
Reported: 2006-09-22 15:43:09 | Status: resolved fixed

My plugin generates java source files into a project and is using org.eclipse.jdt.ui.actions.FormatAllAction.runOnMultiple(ICompiliationUnit[]) to format the generated files. I have discovered that if the ICU[] contains a single entry, then the file is opened in an editor and formatted. This has two pretty serious side effects. 1. the user must save the changes manually. 2. performance is very slow. I solved #1 by adding a call to ICU.commitWorkingCopy, but there is no mention of needing to do this in the javadocs for FormatAllAction.runOnMultiple. In my case, I was able to solve #2 if more than one package fragment is being formatted. I am able to collect the ICU[] for each package fragment into a single ICU[]. This avoids the ICU.length == 1 test from opening an editor. To me, this seems to be a bug. The fact that runOnMultiple behaves differently if it has only one ICU to deal with is bad enough, but that extra step of opening the file in an editor creates a lot of overhead and slows the method down considerably. runOnMultiple has the potential for being very useful for utility plug-in, but it should have constant behavior for all cases. I would think that if the user wants the file open in an editor, they should do that themselves.

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FormatAllAction.java