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