[compiler-impl] use Couple

This commit is contained in:
Konstantin Bulenkov
2014-05-16 00:29:58 +02:00
parent 1a54d3196a
commit 9d30723e4a
3 changed files with 22 additions and 18 deletions
@@ -126,7 +126,7 @@ public class CompileDriver {
public static volatile boolean ourDebugMode = false;
private final Project myProject;
private final Map<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> myGenerationCompilerModuleToOutputDirMap; // [IntermediateOutputCompiler, Module] -> [ProductionSources, TestSources]
private final Map<Pair<IntermediateOutputCompiler, Module>, Couple<VirtualFile>> myGenerationCompilerModuleToOutputDirMap; // [IntermediateOutputCompiler, Module] -> [ProductionSources, TestSources]
private final String myCachesDirectoryPath;
private boolean myShouldClearOutputDirectory;
@@ -171,7 +171,7 @@ public class CompileDriver {
myCachesDirectoryPath = CompilerPaths.getCacheStoreDirectory(myProject).getPath().replace('/', File.separatorChar);
myShouldClearOutputDirectory = CompilerWorkspaceConfiguration.getInstance(myProject).CLEAR_OUTPUT_DIRECTORY;
myGenerationCompilerModuleToOutputDirMap = new HashMap<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>>();
myGenerationCompilerModuleToOutputDirMap = new HashMap<Pair<IntermediateOutputCompiler, Module>, Couple<VirtualFile>>();
if (!useOutOfProcessBuild()) {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
@@ -183,7 +183,7 @@ public class CompileDriver {
final VirtualFile productionOutput = lookupVFile(lfs, CompilerPaths.getGenerationOutputPath(compiler, module, false));
final VirtualFile testOutput = lookupVFile(lfs, CompilerPaths.getGenerationOutputPath(compiler, module, true));
final Pair<IntermediateOutputCompiler, Module> pair = Pair.create(compiler, module);
final Pair<VirtualFile, VirtualFile> outputs = Pair.create(productionOutput, testOutput);
final Couple<VirtualFile> outputs = Couple.newOne(productionOutput, testOutput);
myGenerationCompilerModuleToOutputDirMap.put(pair, outputs);
}
if (config.getAnnotationProcessingConfiguration(module).isEnabled()) {
@@ -246,8 +246,8 @@ public class CompileDriver {
return false;
}
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
final Pair<VirtualFile, VirtualFile> outputs = entry.getValue();
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Couple<VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
final Couple<VirtualFile> outputs = entry.getValue();
final Pair<IntermediateOutputCompiler, Module> key = entry.getKey();
final Module module = key.getSecond();
compileContext.assignModule(outputs.getFirst(), module, false, key.getFirst());
@@ -439,10 +439,10 @@ public class CompileDriver {
private CompileScope attachIntermediateOutputDirectories(CompileScope originalScope, CompilerFilter filter) {
CompileScope scope = originalScope;
final Set<Module> affected = new HashSet<Module>(Arrays.asList(originalScope.getAffectedModules()));
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Couple<VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
final Module module = entry.getKey().getSecond();
if (affected.contains(module) && filter.acceptCompiler(entry.getKey().getFirst())) {
final Pair<VirtualFile, VirtualFile> outputs = entry.getValue();
final Couple<VirtualFile> outputs = entry.getValue();
scope = new CompositeScope(scope, new FileSetCompileScope(Arrays.asList(outputs.getFirst(), outputs.getSecond()), new Module[]{module}));
}
}
@@ -675,8 +675,8 @@ public class CompileDriver {
new CompileContextImpl(myProject, compileTask, scope, dependencyCache, !isRebuild && !forceCompile, isRebuild);
if (!useExtProcessBuild) {
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
final Pair<VirtualFile, VirtualFile> outputs = entry.getValue();
for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Couple<VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap.entrySet()) {
final Couple<VirtualFile> outputs = entry.getValue();
final Pair<IntermediateOutputCompiler, Module> key = entry.getKey();
final Module module = key.getSecond();
compileContext.assignModule(outputs.getFirst(), module, false, key.getFirst());
@@ -1082,7 +1082,7 @@ public class CompileDriver {
outputsToRefresh.add(output);
}
for (Pair<IntermediateOutputCompiler, Module> pair : myGenerationCompilerModuleToOutputDirMap.keySet()) {
final Pair<VirtualFile, VirtualFile> generated = myGenerationCompilerModuleToOutputDirMap.get(pair);
final Couple<VirtualFile> generated = myGenerationCompilerModuleToOutputDirMap.get(pair);
walkChildren(generated.getFirst(), context);
outputsToRefresh.add(generated.getFirst());
walkChildren(generated.getSecond(), context);
@@ -1881,7 +1881,7 @@ public class CompileDriver {
}
private VirtualFile getGenerationOutputDir(final IntermediateOutputCompiler compiler, final Module module, final boolean forTestSources) {
final Pair<VirtualFile, VirtualFile> outputs =
final Couple<VirtualFile> outputs =
myGenerationCompilerModuleToOutputDirMap.get(Pair.create(compiler, module));
return forTestSources? outputs.getSecond() : outputs.getFirst();
}
@@ -718,7 +718,7 @@ public class BackendCompilerWrapper {
if (pathsEquals) {
final String outputPath = cc.pathToClass.replace(File.separatorChar, '/');
final Pair<String, String> realLocation = moveToRealLocation(outputDir, outputPath, srcFile, filesToRefresh);
final Couple<String> realLocation = moveToRealLocation(outputDir, outputPath, srcFile, filesToRefresh);
if (realLocation != null) {
Collection<TranslatingCompiler.OutputItem> outputs = results.get(realLocation.getFirst());
if (outputs == null) {
@@ -760,7 +760,10 @@ public class BackendCompilerWrapper {
}
@Nullable
private Pair<String, String> moveToRealLocation(String tempOutputDir, String pathToClass, VirtualFile sourceFile, final List<File> filesToRefresh) {
private Couple<String> moveToRealLocation(String tempOutputDir,
String pathToClass,
VirtualFile sourceFile,
final List<File> filesToRefresh) {
final Module module = myCompileContext.getModuleByFile(sourceFile);
if (module == null) {
final String message =
@@ -768,7 +771,7 @@ public class BackendCompilerWrapper {
LOG.info(message);
myCompileContext.addMessage(CompilerMessageCategory.WARNING, message, sourceFile.getUrl(), -1, -1);
// do not move: looks like source file has been invalidated, need recompilation
return Pair.create(tempOutputDir, pathToClass);
return Couple.newOne(tempOutputDir, pathToClass);
}
final String realOutputDir;
if (myCompileContext.isInTestSourceContent(sourceFile)) {
@@ -782,7 +785,7 @@ public class BackendCompilerWrapper {
if (FileUtil.pathsEqual(tempOutputDir, realOutputDir)) { // no need to move
filesToRefresh.add(new File(pathToClass));
return Pair.create(realOutputDir, pathToClass);
return Couple.newOne(realOutputDir, pathToClass);
}
final String realPathToClass = realOutputDir + pathToClass.substring(tempOutputDir.length());
@@ -809,7 +812,7 @@ public class BackendCompilerWrapper {
}
if (success) {
filesToRefresh.add(toFile);
return Pair.create(realOutputDir, realPathToClass);
return Couple.newOne(realOutputDir, realPathToClass);
}
return null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.openapi.compiler.CompilerBundle;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.deployment.DeploymentUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -128,7 +129,7 @@ public class JarsBuilder {
private JarInfo[] sortJars() {
final DFSTBuilder<JarInfo> builder = new DFSTBuilder<JarInfo>(GraphGenerator.create(CachingSemiGraph.create(new JarsGraph())));
if (!builder.isAcyclic()) {
final Pair<JarInfo, JarInfo> dependency = builder.getCircularDependency();
final Couple<JarInfo> dependency = builder.getCircularDependency();
String message = CompilerBundle.message("packaging.compiler.error.cannot.build.circular.dependency.found.between.0.and.1",
dependency.getFirst().getPresentableDestination(),
dependency.getSecond().getPresentableDestination());