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());
}
}
-1
View File
@@ -10,7 +10,6 @@
<orderEntry type="module" module-name="frontend" />
<orderEntry type="library" name="js-libs" level="project" />
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
<orderEntry type="module" module-name="idea" />
</component>
</module>
@@ -24,8 +24,6 @@ import com.intellij.openapi.project.Project;
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.AnalyzerFacade;
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJs;
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
import org.jetbrains.jet.lang.ModuleConfiguration;
@@ -38,32 +36,21 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.plugin.project.IDEAConfig;
import org.jetbrains.k2js.config.Config;
import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* @author Pavel Talanov
*/
public enum AnalyzerFacadeForJS implements AnalyzerFacade {
INSTANCE;
public final class AnalyzerFacadeForJS {
private AnalyzerFacadeForJS() {
}
@NotNull
@Override
public AnalyzeExhaust analyzeFiles(@NotNull Project project,
@NotNull Collection<JetFile> files,
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
BindingContext context = analyzeFiles(files, new IDEAConfig(project));
return new AnalyzeExhaust(context, JetStandardLibrary.getInstance());
}
@NotNull
public static BindingContext analyzeFilesAndCheckErrors(@NotNull List<JetFile> files,
@NotNull Config config) {
@@ -112,7 +99,7 @@ public enum AnalyzerFacadeForJS implements AnalyzerFacade {
@Override
public boolean apply(@Nullable PsiFile file) {
assert file instanceof JetFile;
@SuppressWarnings("UnnecessaryLocalVariable") boolean notLibFile = !jsLibFiles.contains(file.getOriginalFile());
@SuppressWarnings("UnnecessaryLocalVariable") boolean notLibFile = !jsLibFiles.contains(file);
return notLibFile;
}
};
@@ -24,7 +24,6 @@ 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.jet.plugin.JetMainDetector;
import org.jetbrains.jet.plugin.project.IDEAConfig;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import org.jetbrains.k2js.config.Config;
import org.jetbrains.k2js.generate.CodeGenerator;
@@ -49,8 +48,9 @@ public final class K2JSTranslator {
public static void translateWithCallToMainAndSaveToFile(@NotNull List<JetFile> files,
@NotNull String outputPath,
@NotNull Config config,
@NotNull Project project) throws Exception {
K2JSTranslator translator = new K2JSTranslator(new IDEAConfig(project));
K2JSTranslator translator = new K2JSTranslator(config);
String programCode = translator.generateProgramCode(files) + "\n";
JetFile fileWithMain = JetMainDetector.getFileWithMain(files);
if (fileWithMain == null) {