merge analyzeBodies functions from JS and JVM backend

This commit is contained in:
Stepan Koltsov
2012-06-13 19:53:08 +04:00
parent 9290f55bad
commit edad5c9266
3 changed files with 66 additions and 41 deletions
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.analyzer.AnalyzerFacade;
import org.jetbrains.jet.di.InjectorForBodyResolve;
import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything;
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -70,7 +70,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
@NotNull BindingTrace headersTraceContext,
@NotNull BodiesResolveContext bodiesResolveContext
) {
return analyzeBodiesInFilesWithJavaIntegration(
return AnalyzerFacadeForEverything.analyzeBodiesInFilesWithJavaIntegration(
project, scriptParameters, filesForBodiesResolve,
headersTraceContext, bodiesResolveContext);
}
@@ -135,28 +135,6 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
}
}
public static AnalyzeExhaust analyzeBodiesInFilesWithJavaIntegration(
Project project, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull BindingTrace traceContext,
@NotNull BodiesResolveContext bodiesResolveContext) {
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(
filesToAnalyzeCompletely, false, false, scriptParameters);
bodiesResolveContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
InjectorForBodyResolve injector = new InjectorForBodyResolve(
project, topDownAnalysisParameters,
new ObservableBindingTrace(traceContext));
try {
injector.getBodyResolver().resolveBodies(bodiesResolveContext);
return AnalyzeExhaust.success(traceContext.getBindingContext(), JetStandardLibrary.getInstance());
} finally {
injector.destroy();
}
}
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
@NotNull CompilerSpecialMode compilerSpecialMode, @NotNull CompilerDependencies compilerDependencies) {
assert files.size() > 0;
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.analyzer;
import com.google.common.base.Predicate;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.di.InjectorForBodyResolve;
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.BodiesResolveContext;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.List;
/**
* @author Stepan Koltsov
*/
public class AnalyzerFacadeForEverything {
public static AnalyzeExhaust analyzeBodiesInFilesWithJavaIntegration(
Project project, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull BindingTrace traceContext,
@NotNull BodiesResolveContext bodiesResolveContext) {
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(
filesToAnalyzeCompletely, false, false, scriptParameters);
bodiesResolveContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
InjectorForBodyResolve injector = new InjectorForBodyResolve(
project, topDownAnalysisParameters,
new ObservableBindingTrace(traceContext));
try {
injector.getBodyResolver().resolveBodies(bodiesResolveContext);
return AnalyzeExhaust.success(traceContext.getBindingContext(), JetStandardLibrary.getInstance());
} finally {
injector.destroy();
}
}
}
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything;
import org.jetbrains.jet.di.InjectorForBodyResolve;
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJs;
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
@@ -110,25 +111,11 @@ public final class AnalyzerFacadeForJS {
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull Config config,
@NotNull BindingTrace traceContext,
@NotNull BodiesResolveContext bodiesResolveContext
) {
Project project = config.getProject();
@NotNull BodiesResolveContext bodiesResolveContext) {
Predicate<PsiFile> completely = Predicates.and(notLibFiles(config.getLibFiles()), filesToAnalyzeCompletely);
TopDownAnalysisParameters topDownAnalysisParameters =
new TopDownAnalysisParameters(completely, false, false, Collections.<AnalyzerScriptParameter>emptyList());
InjectorForBodyResolve injector = new InjectorForBodyResolve(
project, topDownAnalysisParameters, new ObservableBindingTrace(traceContext));
try {
bodiesResolveContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
injector.getBodyResolver().resolveBodies(bodiesResolveContext);
return AnalyzeExhaust.success(traceContext.getBindingContext(), JetStandardLibrary.getInstance());
}
finally {
injector.destroy();
}
return AnalyzerFacadeForEverything.analyzeBodiesInFilesWithJavaIntegration(
config.getProject(), Collections.<AnalyzerScriptParameter>emptyList(), completely, traceContext, bodiesResolveContext);
}
private static void checkForErrors(@NotNull Collection<JetFile> allFiles, @NotNull BindingContext bindingContext) {