mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEADEV-42200: when multiple src transforming compilers are registered, pass correct original file for reference.
This commit is contained in:
+8
-6
@@ -526,13 +526,15 @@ public class BackendCompilerWrapper {
|
||||
application.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
for (final Module module : modules) {
|
||||
List<VirtualFile> 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<VirtualFile> 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);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,11 @@ public class ModuleChunk extends Chunk<Module> {
|
||||
myTransformedToOriginalMap.put(transformedFile, originalFile);
|
||||
}
|
||||
|
||||
public VirtualFile getOriginalFile(VirtualFile file) {
|
||||
final VirtualFile original = myTransformedToOriginalMap.get(file);
|
||||
return original != null? original : file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<VirtualFile> getFilesToCompile(Module forModule) {
|
||||
return myModuleToFilesMap.get(forModule);
|
||||
|
||||
+2
-2
@@ -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:<br><br>
|
||||
|
||||
Reference in New Issue
Block a user