Resolve circular dependency. Introduce JsAnalyzerFacadeForIDEA.

This commit is contained in:
Pavel V. Talanov
2012-04-09 13:50:48 +04:00
parent 06ab0d7a55
commit 0f44771447
6 changed files with 64 additions and 27 deletions
@@ -30,6 +30,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.plugin.project.IDEAConfig;
import org.jetbrains.k2js.facade.K2JSTranslator;
import java.util.Collection;
@@ -64,6 +65,7 @@ public final class K2JSRunnerUtils {
String outputFilePath = constructPathToGeneratedFile(project, outputDirPath);
K2JSTranslator.translateWithCallToMainAndSaveToFile(kotlinFiles,
outputFilePath,
new IDEAConfig(project),
project);
notifySuccess(outputDirPath);
}
@@ -33,16 +33,13 @@ public final class AnalyzerFacadeProvider {
@NotNull
public static AnalyzerFacade getAnalyzerFacadeForFile(@NotNull JetFile file) {
if (JsModuleDetector.isJsProject(file.getProject())) {
return AnalyzerFacadeForJS.INSTANCE;
}
return AnalyzerFacadeForJVM.INSTANCE;
return getAnalyzerFacadeForProject(file.getProject());
}
@NotNull
public static AnalyzerFacade getAnalyzerFacadeForProject(@NotNull Project project) {
if (JsModuleDetector.isJsProject(project)) {
return AnalyzerFacadeForJS.INSTANCE;
return JSAnalyzerFacadeForIDEA.INSTANCE;
}
return AnalyzerFacadeForJVM.INSTANCE;
}
@@ -0,0 +1,52 @@
/*
* 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.plugin.project;
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.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.analyzer.AnalyzerFacade;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import java.util.Collection;
/**
* @author Pavel Talanov
*/
public enum JSAnalyzerFacadeForIDEA implements AnalyzerFacade {
INSTANCE;
private JSAnalyzerFacadeForIDEA() {
}
@NotNull
@Override
public AnalyzeExhaust analyzeFiles(@NotNull Project project,
@NotNull Collection<JetFile> files,
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
BindingContext context = AnalyzerFacadeForJS.analyzeFiles(files, new IDEAConfig(project));
return new AnalyzeExhaust(context, JetStandardLibrary.getInstance());
}
}