Remove redundant analyzer wrapper.

This commit is contained in:
Pavel V. Talanov
2012-04-25 13:45:42 +04:00
parent 891dd9fc1c
commit 6e3d7cce61
2 changed files with 8 additions and 16 deletions
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.LocalTimeCounter;
import jet.Function0;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -105,7 +106,7 @@ public class KotlinToJVMBytecodeCompiler {
CompileEnvironmentUtil
.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
}
ClassFileFactory moduleFactory = KotlinToJVMBytecodeCompiler.compileModule(configuration, moduleBuilder, directory);
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
if (moduleFactory == null) {
return false;
}
@@ -193,7 +194,6 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
public static ClassLoader compileText(
CompileEnvironmentConfiguration configuration,
String code) {
configuration.getEnvironment()
.addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code));
@@ -213,7 +213,6 @@ public class KotlinToJVMBytecodeCompiler {
@Nullable
public static GenerationState analyzeAndGenerate(
CompileEnvironmentConfiguration configuration,
boolean stubs
) {
AnalyzeExhaust exhaust = analyze(configuration, stubs);
@@ -231,17 +230,15 @@ public class KotlinToJVMBytecodeCompiler {
private static AnalyzeExhaust analyze(
final CompileEnvironmentConfiguration configuration,
boolean stubs) {
final JetCoreEnvironment environment = configuration.getEnvironment();
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
final Predicate<PsiFile> filesToAnalyzeCompletely =
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
analyzerWithCompilerReport.analyzeAndReport(
new AnalyzerWithCompilerReport.AnalyzerWrapper() {
new Function0<AnalyzeExhaust>() {
@NotNull
@Override
public AnalyzeExhaust analyze() {
public AnalyzeExhaust invoke() {
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
JetControlFlowDataTraceFactory.EMPTY,
@@ -256,9 +253,7 @@ public class KotlinToJVMBytecodeCompiler {
@NotNull
private static GenerationState generate(
final CompileEnvironmentConfiguration configuration,
AnalyzeExhaust exhaust,
boolean stubs) {
JetCoreEnvironment environment = configuration.getEnvironment();
Project project = environment.getProject();
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
import jet.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
@@ -53,7 +54,7 @@ public final class AnalyzerWithCompilerReport {
@NotNull
private static final SimpleDiagnosticFactory<PsiErrorElement> SYNTAX_ERROR_FACTORY = SimpleDiagnosticFactory.create(Severity.ERROR);
private boolean hasErrors;
private boolean hasErrors = false;
@NotNull
private final MessageCollector messageCollectorWrapper;
@Nullable
@@ -131,17 +132,13 @@ public final class AnalyzerWithCompilerReport {
return hasErrors;
}
public void analyzeAndReport(@NotNull AnalyzerWrapper analyzerWrapper, @NotNull Collection<JetFile> files) {
public void analyzeAndReport(@NotNull Function0<AnalyzeExhaust> analyzer, @NotNull Collection<JetFile> files) {
reportSyntaxErrors(files);
analyzeExhaust = analyzerWrapper.analyze();
analyzeExhaust = analyzer.invoke();
reportDiagnostics();
reportIncompleteHierarchies();
}
public interface AnalyzerWrapper {
@NotNull
AnalyzeExhaust analyze();
}
public static class SyntaxErrorDiagnostic extends SimpleDiagnostic<PsiErrorElement> {
private String message;