diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index 88f8743aa6b2..cb5dd5ce6c7b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -526,13 +526,15 @@ public class BackendCompilerWrapper { application.invokeAndWait(new Runnable() { public void run() { for (final Module module : modules) { - List filesToCompile = chunk.getFilesToCompile(module); - for (final VirtualFile file : filesToCompile) { - if (transformer.isTransformable(file)) { + for (final VirtualFile file : chunk.getFilesToCompile(module)) { + final VirtualFile untransformed = chunk.getOriginalFile(file); + if (transformer.isTransformable(untransformed)) { application.runWriteAction(new Runnable() { public void run() { try { - VirtualFile fileCopy = createFileCopy(getTempDir(module), file); + // if untransformed != file, the file is already a (possibly transformed) copy of the original 'untransformed' file. + // If this is the case, just use already created copy and do not copy file content once again + final VirtualFile fileCopy = untransformed.equals(file)? createFileCopy(getTempDir(module), file) : file; originalToCopyFileMap.put(file, fileCopy); } catch (IOException e) { @@ -551,9 +553,9 @@ public class BackendCompilerWrapper { final List filesToCompile = chunk.getFilesToCompile(module); for (int j = 0; j < filesToCompile.size(); j++) { final VirtualFile file = filesToCompile.get(j); - VirtualFile fileCopy = originalToCopyFileMap.get(file); + final VirtualFile fileCopy = originalToCopyFileMap.get(file); if (fileCopy != null) { - final boolean ok = transformer.transform(myCompileContext, fileCopy, file); + final boolean ok = transformer.transform(myCompileContext, fileCopy, chunk.getOriginalFile(file)); if (ok) { chunk.substituteWithTransformedVersion(module, j, fileCopy); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java index ccd4c43310bc..9b2b412c20f4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/ModuleChunk.java @@ -82,6 +82,11 @@ public class ModuleChunk extends Chunk { myTransformedToOriginalMap.put(transformedFile, originalFile); } + public VirtualFile getOriginalFile(VirtualFile file) { + final VirtualFile original = myTransformedToOriginalMap.get(file); + return original != null? original : file; + } + @NotNull public List getFilesToCompile(Module forModule) { return myModuleToFilesMap.get(forModule); diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/JavaSourceTransformingCompiler.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/JavaSourceTransformingCompiler.java index 1860c01420ff..27a397569aad 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/JavaSourceTransformingCompiler.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/JavaSourceTransformingCompiler.java @@ -27,7 +27,7 @@ public interface JavaSourceTransformingCompiler extends Compiler { * * @param file an original file that is about to be compiled with java compiler * @return true if compiler would like to transform the file, false otherwise. - * If true is returned, a copy of ariginal file will be made and {@link #transform(CompileContext,com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.vfs.VirtualFile)} + * If true is returned, a copy of original file will be made and {@link #transform(CompileContext,com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.vfs.VirtualFile)} * method will be called on it. If transformation succeeded, the transformed copy will be passed to java compiler instead of original file. */ boolean isTransformable(VirtualFile file); @@ -36,7 +36,7 @@ public interface JavaSourceTransformingCompiler extends Compiler { * Transforms the specified file. * * @param context the current compile context. - * @param file a copy of original file to be transformed + * @param file a copy of original file to be transformed. If there are more than one transformer registered, this copy may already contain transformations made by other transformers which were called before this one * @param originalFile an original file. Since the copy that is supposed to be modified is located outside the project, it is not possible to use PSI for analysis. * So the original file is provided. Note that it is passed for reference purposes only. It MUST NOT be transformed or changed in any way. * For example, it is possible to obtain a PsiFile for the original file: