diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index 2daee60495d..53b044822a5 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; @@ -26,7 +27,6 @@ import org.jetbrains.jet.analyzer.AnalyzerFacade; import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything; import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver; import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm; -import org.jetbrains.jet.lang.DefaultModuleConfiguration; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl; import org.jetbrains.jet.lang.psi.JetFile; @@ -47,6 +47,12 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { INSTANCE; + public static final List DEFAULT_IMPORTS = ImmutableList.of( + new ImportPath("java.lang.*"), + new ImportPath("kotlin.*"), + new ImportPath("kotlin.io.*"), + new ImportPath("jet.*")); + private AnalyzerFacadeForJVM() { } @@ -195,6 +201,6 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { @NotNull public static ModuleDescriptorImpl createJavaModule(@NotNull String name) { - return new ModuleDescriptorImpl(Name.special(name), JavaBridgeConfiguration.ALL_JAVA_IMPORTS, JavaToKotlinClassMap.getInstance()); + return new ModuleDescriptorImpl(Name.special(name), DEFAULT_IMPORTS, JavaToKotlinClassMap.getInstance()); } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JavaBridgeConfiguration.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JavaBridgeConfiguration.java deleted file mode 100644 index 148b6b5b9fc..00000000000 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JavaBridgeConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.lang.resolve.java; - -import org.jetbrains.jet.lang.DefaultModuleConfiguration; -import org.jetbrains.jet.lang.resolve.ImportPath; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class JavaBridgeConfiguration { - - public static final List DEFAULT_JAVA_IMPORTS = Collections.unmodifiableList(Arrays.asList(new ImportPath("java.lang.*"))); - public static final List ALL_JAVA_IMPORTS; - - static { - List allJavaImports = new ArrayList(); - allJavaImports.addAll(DEFAULT_JAVA_IMPORTS); - allJavaImports.addAll(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS); - ALL_JAVA_IMPORTS = Collections.unmodifiableList(allJavaImports); - } -} diff --git a/core/descriptors/src/org/jetbrains/jet/lang/DefaultModuleConfiguration.java b/core/descriptors/src/org/jetbrains/jet/lang/DefaultModuleConfiguration.java deleted file mode 100644 index 07bc9da8ec0..00000000000 --- a/core/descriptors/src/org/jetbrains/jet/lang/DefaultModuleConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.lang; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.jet.lang.resolve.ImportPath; - -import java.util.List; - -public class DefaultModuleConfiguration { - public static final List DEFAULT_JET_IMPORTS = ImmutableList.of( - new ImportPath("kotlin.*"), - new ImportPath("kotlin.io.*"), - new ImportPath("jet.*")); - - private DefaultModuleConfiguration() { - } -} diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index ede348c6a3e..c9ec506bf0d 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -20,16 +20,15 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.DefaultModuleConfiguration; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor; import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl; import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.name.SpecialNames; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.storage.LockBasedStorageManager; @@ -128,7 +127,7 @@ public class KotlinBuiltIns { private KotlinBuiltIns() { try { this.builtInsModule = new ModuleDescriptorImpl(Name.special(""), - DefaultModuleConfiguration.DEFAULT_JET_IMPORTS, + Collections.emptyList(), PlatformToKotlinClassMap.EMPTY); loadBuiltIns(builtInsModule); diff --git a/idea/src/org/jetbrains/jet/plugin/completion/weigher/JetDeclarationRemotenessWeigher.java b/idea/src/org/jetbrains/jet/plugin/completion/weigher/JetDeclarationRemotenessWeigher.java index 6ae6f1c22a3..49b259bca3a 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/weigher/JetDeclarationRemotenessWeigher.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/weigher/JetDeclarationRemotenessWeigher.java @@ -71,7 +71,7 @@ public class JetDeclarationRemotenessWeigher extends LookupElementWeigher { return MyResult.notImported; } else { - if (ImportInsertHelper.isImportedWithKotlinDefault(importPath)) { + if (ImportInsertHelper.isImportedWithDefault(importPath, file)) { return MyResult.kotlinDefaultImport; } return MyResult.imported; diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java index 017f5143eb0..f129f5f8421 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java @@ -42,13 +42,13 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.asJava.LightClassUtil; import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor; -import org.jetbrains.jet.lang.DefaultModuleConfiguration; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.mapping.KotlinToJavaTypesMap; import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer; @@ -222,7 +222,7 @@ public class JetSourceNavigationHelper { } }); ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(Name.special(""), - DefaultModuleConfiguration.DEFAULT_JET_IMPORTS, + AnalyzerFacadeForJVM.DEFAULT_IMPORTS, PlatformToKotlinClassMap.EMPTY); KotlinCodeAnalyzer analyzer = new ResolveSession( project, diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java index 92832af2ae7..4a8dd86f1a6 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java @@ -22,18 +22,17 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.DefaultModuleConfiguration; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.ImportPath; -import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration; +import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.plugin.project.ProjectStructureUtil; import org.jetbrains.jet.plugin.references.JetPsiReference; import org.jetbrains.jet.util.QualifiedNamesUtil; -import org.jetbrains.k2js.analyze.JsConfiguration; +import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS; import java.util.List; @@ -135,26 +134,14 @@ public class ImportInsertHelper { } } - if (isImportedWithKotlinDefault(importPath)) return true; - - if (ProjectStructureUtil.isJsKotlinModule(jetFile)) { - return isImportedWithJsDefault(importPath); - } - else { - return isImportedWithJavaDefault(importPath); - } + return isImportedWithDefault(importPath, jetFile); } - public static boolean isImportedWithJavaDefault(ImportPath importPath) { - return QualifiedNamesUtil.isImported(JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS, importPath); - } - - public static boolean isImportedWithJsDefault(ImportPath importPath) { - return QualifiedNamesUtil.isImported(JsConfiguration.DEFAULT_IMPORT_PATHS, importPath); - } - - public static boolean isImportedWithKotlinDefault(ImportPath importPath) { - return QualifiedNamesUtil.isImported(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS, importPath); + public static boolean isImportedWithDefault(@NotNull ImportPath importPath, @NotNull JetFile contextFile) { + List defaultImports = ProjectStructureUtil.isJsKotlinModule(contextFile) + ? AnalyzerFacadeForJS.DEFAULT_IMPORTS + : AnalyzerFacadeForJVM.DEFAULT_IMPORTS; + return QualifiedNamesUtil.isImported(defaultImports, importPath); } public static boolean doNeedImport(@NotNull ImportPath importPath, @NotNull JetFile file) { diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java index 0c3bccbaec6..e40f1c67cec 100644 --- a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java +++ b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java @@ -18,6 +18,7 @@ package org.jetbrains.k2js.analyze; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; @@ -35,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProv import org.jetbrains.jet.lang.resolve.lazy.storage.LockBasedLazyResolveStorageManager; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.k2js.config.Config; import java.util.Collection; @@ -42,6 +44,11 @@ import java.util.Collections; import java.util.List; public final class AnalyzerFacadeForJS { + public static final List DEFAULT_IMPORTS = ImmutableList.of( + new ImportPath("js.*"), + new ImportPath("java.lang.*"), + new ImportPath("jet.*"), + new ImportPath("kotlin.*")); private AnalyzerFacadeForJS() { } @@ -152,7 +159,7 @@ public final class AnalyzerFacadeForJS { @NotNull private static ModuleDescriptorImpl createJsModule(@NotNull String name) { - return new ModuleDescriptorImpl(Name.special(name), JsConfiguration.DEFAULT_IMPORT_PATHS, PlatformToKotlinClassMap.EMPTY); + return new ModuleDescriptorImpl(Name.special(name), DEFAULT_IMPORTS, PlatformToKotlinClassMap.EMPTY); } } diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java b/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java deleted file mode 100644 index 074849e9c50..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.k2js.analyze; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.ImportPath; -import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; - -import java.util.List; - -public class JsConfiguration { - - @NotNull - public static final List DEFAULT_IMPORT_PATHS = ImmutableList.of( - new ImportPath("js.*"), - new ImportPath("java.lang.*"), - new ImportPath(KotlinBuiltIns.getInstance().getBuiltInsPackageFqName(), true), - new ImportPath("kotlin.*")); - - JsConfiguration() { - } -}