diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java index a97a3400918..98642eeb720 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -486,23 +486,6 @@ public class TypeUtils { return TypeSubstitutor.create(substitutions).substitute(clazz.getDefaultType(), Variance.INVARIANT); } - private static void addAllClassDescriptors(@NotNull JetType type, @NotNull Set set) { - ClassDescriptor cd = getClassDescriptor(type); - if (cd != null) { - set.add(cd); - } - for (TypeProjection projection : type.getArguments()) { - addAllClassDescriptors(projection.getType(), set); - } - } - - @NotNull - public static List getAllClassDescriptors(@NotNull JetType type) { - Set classDescriptors = new HashSet(); - addAllClassDescriptors(type, classDescriptors); - return new ArrayList(classDescriptors); - } - public static boolean equalTypes(@NotNull JetType a, @NotNull JetType b) { return JetTypeChecker.INSTANCE.isSubtypeOf(a, b) && JetTypeChecker.INSTANCE.isSubtypeOf(b, a); } diff --git a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java index a5527c2cb0e..87c0aeff0ab 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.plugin; -import com.google.common.collect.Lists; import com.intellij.facet.Facet; import com.intellij.facet.FacetManager; import com.intellij.ide.plugins.IdeaPluginDescriptor; @@ -31,63 +30,9 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; -import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; -import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.types.DeferredType; -import org.jetbrains.jet.lang.types.ErrorUtils; -import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.plugin.configuration.ModuleTypeCacheManager; -import java.util.LinkedList; - public class JetPluginUtil { - @NotNull - private static LinkedList computeTypeFullNameList(JetType type) { - if (type instanceof DeferredType) { - type = ((DeferredType)type).getActualType(); - } - DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor(); - - LinkedList fullName = Lists.newLinkedList(); - while (declarationDescriptor != null && !(declarationDescriptor instanceof ModuleDescriptor)) { - fullName.addFirst(declarationDescriptor.getName().asString()); - declarationDescriptor = declarationDescriptor.getContainingDeclaration(); - } - assert fullName.size() > 0; - if (JavaDescriptorResolver.JAVA_ROOT.asString().equals(fullName.getFirst())) { - fullName.removeFirst(); - } - return fullName; - } - - public static boolean checkTypeIsStandard(JetType type, Project project) { - if (KotlinBuiltIns.getInstance().isAnyOrNullableAny(type) || KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type) || KotlinBuiltIns.getInstance().isUnit(type) || - KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) { - return true; - } - - LinkedList fullName = computeTypeFullNameList(type); - if (fullName.size() == 3 && fullName.getFirst().equals("java") && fullName.get(1).equals("lang")) { - return true; - } - - JetScope libraryScope = KotlinBuiltIns.getInstance().getBuiltInsScope(); - - DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration(); - if (ErrorUtils.isError(declaration)) { - return false; - } - while (!(declaration instanceof NamespaceDescriptor)) { - declaration = declaration.getContainingDeclaration(); - assert declaration != null; - } - return libraryScope == ((NamespaceDescriptor) declaration).getMemberScope(); - } - public static boolean isInSource(@NotNull PsiElement element) { return isInSource(element, true); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java index e71116522aa..92832af2ae7 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java @@ -26,17 +26,10 @@ 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.BindingContext; -import org.jetbrains.jet.lang.resolve.BindingContextUtils; -import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.lang.types.TypeUtils; -import org.jetbrains.jet.plugin.JetPluginUtil; -import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; import org.jetbrains.jet.plugin.project.ProjectStructureUtil; import org.jetbrains.jet.plugin.references.JetPsiReference; import org.jetbrains.jet.util.QualifiedNamesUtil; @@ -48,26 +41,6 @@ public class ImportInsertHelper { private ImportInsertHelper() { } - /** - * Add import directive corresponding to a type to file when it is needed. - * - * @param type type to import - * @param file file where import directive should be added - */ - public static void addImportDirectivesIfNeeded(@NotNull JetType type, @NotNull JetFile file) { - if (JetPluginUtil.checkTypeIsStandard(type, file.getProject()) || type.isError()) { - return; - } - BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext(); - PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, type.getMemberScope().getContainingDeclaration()); - if (element != null && element.getContainingFile() == file) { //declaration is in the same file, so no import is needed - return; - } - for (ClassDescriptor clazz : TypeUtils.getAllClassDescriptors(type)) { - addImportDirectiveIfNeeded(DescriptorUtils.getFQName(getTopLevelClass(clazz)).toSafe(), file); - } - } - /** * Add import directive into the PSI tree for the given namespace. *