From 6e3d7cce61c24a4725095b788ee77de1bf8d6b23 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Wed, 25 Apr 2012 13:45:42 +0400 Subject: [PATCH] Remove redundant analyzer wrapper. --- .../jet/compiler/KotlinToJVMBytecodeCompiler.java | 13 ++++--------- .../messages/AnalyzerWithCompilerReport.java | 11 ++++------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java index 13945fd5949..6f8798ad661 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/KotlinToJVMBytecodeCompiler.java @@ -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 filesToAnalyzeCompletely = stubs ? Predicates.alwaysFalse() : Predicates.alwaysTrue(); analyzerWithCompilerReport.analyzeAndReport( - new AnalyzerWithCompilerReport.AnalyzerWrapper() { + new Function0() { @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(); diff --git a/compiler/cli/src/org/jetbrains/jet/compiler/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/compiler/messages/AnalyzerWithCompilerReport.java index d03a19efd8e..0a5d9812340 100644 --- a/compiler/cli/src/org/jetbrains/jet/compiler/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/jet/compiler/messages/AnalyzerWithCompilerReport.java @@ -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 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 files) { + public void analyzeAndReport(@NotNull Function0 analyzer, @NotNull Collection files) { reportSyntaxErrors(files); - analyzeExhaust = analyzerWrapper.analyze(); + analyzeExhaust = analyzer.invoke(); reportDiagnostics(); reportIncompleteHierarchies(); } - public interface AnalyzerWrapper { - @NotNull - AnalyzeExhaust analyze(); - } public static class SyntaxErrorDiagnostic extends SimpleDiagnostic { private String message;