diff --git a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeProvider.java b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeProvider.java index 063d1574af7..e98f79df860 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeProvider.java @@ -16,48 +16,17 @@ package org.jetbrains.jet.plugin.project; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.analyzer.AnalyzerFacade; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; -import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector; public final class AnalyzerFacadeProvider { - - private final static Logger LOG = Logger.getInstance(AnalyzerFacade.class); - private AnalyzerFacadeProvider() { } @NotNull public static AnalyzerFacade getAnalyzerFacadeForFile(@NotNull JetFile file) { - VirtualFile virtualFile = file.getOriginalFile().getVirtualFile(); - if (virtualFile == null) { - return getDefaultAnalyzerFacade(); - } - Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(file.getProject()).getModuleForFile(virtualFile); - if (moduleForFile == null) { - return getDefaultAnalyzerFacade(); - } - return getAnalyzerFacadeForModule(moduleForFile); - } - - @NotNull - private static AnalyzerFacade getDefaultAnalyzerFacade() { - //TODO: should deal with situations when we can't determine whether to use java or js backend more carefully - LOG.info("Using default analyzer facade"); - return AnalyzerFacadeForJVM.INSTANCE; - } - - @NotNull - private static AnalyzerFacade getAnalyzerFacadeForModule(@NotNull Module module) { - if (KotlinFrameworkDetector.isJsKotlinModule(module)) { - return JSAnalyzerFacadeForIDEA.INSTANCE; - } - return AnalyzerFacadeForJVM.INSTANCE; + return TargetPlatformDetector.getPlatform(file) == TargetPlatform.JVM ? AnalyzerFacadeForJVM.INSTANCE : JSAnalyzerFacadeForIDEA.INSTANCE; } } diff --git a/idea/src/org/jetbrains/jet/plugin/project/TargetPlatform.java b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatform.java new file mode 100644 index 00000000000..d5a7c361d6f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatform.java @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2013 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; + +public interface TargetPlatform { + TargetPlatform JVM = new TargetPlatformImpl("JVM"); + TargetPlatform JS = new TargetPlatformImpl("JS"); +} diff --git a/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformDetector.java b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformDetector.java new file mode 100644 index 00000000000..e5a16ddaf6f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformDetector.java @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2013 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.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.analyzer.AnalyzerFacade; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector; + +public class TargetPlatformDetector { + public static final TargetPlatformDetector INSTANCE = new TargetPlatformDetector(); + private static final Logger LOG = Logger.getInstance(AnalyzerFacade.class); + + private TargetPlatformDetector() { + } + + @NotNull + public static TargetPlatform getPlatform(@NotNull JetFile file) { + VirtualFile virtualFile = file.getOriginalFile().getVirtualFile(); + if (virtualFile == null) { + return getDefaultPlatform(); + } + Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(file.getProject()).getModuleForFile(virtualFile); + if (moduleForFile == null) { + return getDefaultPlatform(); + } + + return getPlatform(moduleForFile); + } + + @NotNull + public static TargetPlatform getPlatform(@NotNull Module module) { + if (KotlinFrameworkDetector.isJsKotlinModule(module)) { + return TargetPlatform.JS; + } + return TargetPlatform.JVM; + } + + @NotNull + private static TargetPlatform getDefaultPlatform() { + LOG.info("Using default platform"); + return TargetPlatform.JVM; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformImpl.java b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformImpl.java new file mode 100644 index 00000000000..8a7d08cb952 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/project/TargetPlatformImpl.java @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2013 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 org.jetbrains.annotations.NotNull; + +public class TargetPlatformImpl implements TargetPlatform { + @NotNull private final String platformName; + + public TargetPlatformImpl(@NotNull String platformName) { + this.platformName = platformName; + } + + @Override + public String toString() { + return platformName; + } +}