From 69e0f23db905a7334d198215f47f739342f547e1 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Fri, 14 Aug 2015 22:42:20 +0300 Subject: [PATCH] Classify Location.NO_LOCATION usages --- .../kotlin/backend/common/CodegenUtil.java | 2 +- .../kotlin/backend/common/CodegenUtilKt.kt | 13 ++--- .../kotlin/codegen/ClosureCodegen.java | 4 +- .../kotlin/codegen/ExpressionCodegen.java | 2 +- .../codegen/ImplementationBodyCodegen.java | 6 +-- .../kotlin/codegen/SamWrapperCodegen.java | 2 +- .../MultiModuleJavaAnalysisCustomTest.kt | 3 +- ...stractAnnotationDescriptorResolveTest.java | 14 +++--- .../kotlin/test/util/DescriptorValidator.java | 8 +-- .../kotlin/types/BoundsSubstitutorTest.java | 2 +- .../kotlin/types/JetTypeCheckerTest.java | 2 +- .../kotlin/types/TypeSubstitutorTest.java | 4 +- .../jetbrains/kotlin/idea/util/TypeUtils.kt | 3 +- .../IDELightClassGenerationSupport.java | 4 +- .../caches/resolve/JavaResolveExtension.kt | 5 +- .../kotlin/idea/util/ShortenReferences.kt | 6 +-- .../smart/MultipleArgumentsItemProvider.kt | 3 +- .../smart/TypeInstantiationItems.kt | 3 +- .../smart/TypesWithContainsDetector.kt | 29 +++++------ .../kotlin/idea/core/IterableTypesDetector.kt | 8 +-- .../kotlin/idea/core/NameValidators.kt | 10 ++-- .../KotlinCopyPasteReferenceProcessor.kt | 12 +++-- ...PositionManagerLibraryClassFileSearcher.kt | 40 +++++++-------- .../idea/imports/KotlinImportOptimizer.kt | 3 +- .../ConvertFunctionToPropertyIntention.kt | 5 +- .../ConvertPropertyToFunctionIntention.kt | 3 +- .../ChangeMemberFunctionSignatureFix.java | 2 +- .../callableBuilder/CallableBuilder.kt | 5 +- .../callableBuilder/typeUtils.kt | 3 +- .../CreateParameterByRefActionFactory.kt | 3 +- .../changeSignature/JetChangeSignatureData.kt | 3 +- .../JetChangeSignatureUsageProcessor.java | 6 +-- .../extractableAnalysisUtil.kt | 5 +- .../idea/util/ImportInsertHelperImpl.kt | 50 +++++++++++++------ .../kotlin/idea/kdoc/KDocFinderTest.kt | 9 ++-- .../refactoring/rename/AbstractRenameTest.kt | 5 +- .../js/translate/utils/ManglingUtils.java | 2 +- 37 files changed, 167 insertions(+), 122 deletions(-) diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java index 0e30141328e..fc0b5181dc5 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java @@ -60,7 +60,7 @@ public class CodegenUtil { @NotNull ClassifierDescriptor returnedClassifier, @NotNull ClassifierDescriptor... valueParameterClassifiers ) { - Collection functions = owner.getDefaultType().getMemberScope().getFunctions(name, LookupLocation.NO_LOCATION); + Collection functions = owner.getDefaultType().getMemberScope().getFunctions(name, LookupLocation.NO_LOCATION_FROM_BACKEND); for (FunctionDescriptor function : functions) { if (!CallResolverUtilPackage.isOrOverridesSynthesized(function) && function.getTypeParameters().isEmpty() diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtilKt.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtilKt.kt index caebf406512..5ea0498ad3e 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtilKt.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtilKt.kt @@ -16,16 +16,17 @@ package org.jetbrains.kotlin.backend.common +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.types.JetType -import kotlin.platform.platformStatic -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.utils.keysToMapExceptNulls +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.MemberComparator -import java.util.Comparator +import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.isDynamic +import org.jetbrains.kotlin.utils.keysToMapExceptNulls +import java.util.Comparator +import kotlin.platform.platformStatic public object CodegenUtilKt { @@ -57,7 +58,7 @@ public object CodegenUtilKt { val name = overriddenDescriptor.getName() // this is the actual member of delegateExpressionType that we are delegating to - (scope.getFunctions(name) + scope.getProperties(name)) + (scope.getFunctions(name, LookupLocation.NO_LOCATION_FROM_BACKEND) + scope.getProperties(name, LookupLocation.NO_LOCATION_FROM_BACKEND)) .first { (listOf(it) + DescriptorUtils.getAllOverriddenDescriptors(it)).map { it.getOriginal() }.contains(overriddenDescriptor.getOriginal()) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 98dd71a544a..7428d4340ed 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.psi.JetElement; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.incremental.components.LookupLocation; +import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.expressions.OperatorConventions; import org.jetbrains.kotlin.utils.UtilsPackage; @@ -453,6 +454,7 @@ public class ClosureCodegen extends MemberCodegen { ClassDescriptor elementClass = elementDescriptor.getExtensionReceiverParameter() == null ? getBuiltIns(elementDescriptor).getFunction(arity) : getBuiltIns(elementDescriptor).getExtensionFunction(arity); - return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE, LookupLocation.NO_LOCATION).iterator().next(); + JetScope scope = elementClass.getDefaultType().getMemberScope(); + return scope.getFunctions(OperatorConventions.INVOKE, LookupLocation.NO_LOCATION_FROM_BACKEND).iterator().next(); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 6bcc05d0819..f7fe977d8cf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1075,7 +1075,7 @@ public class ExpressionCodegen extends JetVisitor implem Type asmLoopRangeType = asmType(loopRangeType); Collection incrementProp = - loopRangeType.getMemberScope().getProperties(Name.identifier("increment"), LookupLocation.NO_LOCATION); + loopRangeType.getMemberScope().getProperties(Name.identifier("increment"), LookupLocation.NO_LOCATION_FROM_BACKEND); assert incrementProp.size() == 1 : loopRangeType + " " + incrementProp.size(); incrementType = asmType(incrementProp.iterator().next().getType()); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 2038c984628..2a8d6767f00 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -403,7 +403,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { private boolean isGenericToArrayPresent() { Collection functions = - descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"), LookupLocation.NO_LOCATION); + descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"), LookupLocation.NO_LOCATION_FROM_BACKEND); for (FunctionDescriptor function : functions) { if (CallResolverUtilPackage.isOrOverridesSynthesized(function)) { continue; @@ -817,7 +817,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Type type = typeMapper.mapType(getBuiltIns(descriptor).getArrayType(INVARIANT, descriptor.getDefaultType())); FunctionDescriptor valuesFunction = - KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES, LookupLocation.NO_LOCATION), new Function1() { + KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES, LookupLocation.NO_LOCATION_FROM_BACKEND), new Function1() { @Override public Boolean invoke(FunctionDescriptor descriptor) { return CodegenUtil.isEnumValuesMethod(descriptor); @@ -837,7 +837,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { private void generateEnumValueOfMethod() { FunctionDescriptor valueOfFunction = - KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF, LookupLocation.NO_LOCATION), new Function1() { + KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF, LookupLocation.NO_LOCATION_FROM_BACKEND), new Function1() { @Override public Boolean invoke(FunctionDescriptor descriptor) { return CodegenUtil.isEnumValueOfMethod(descriptor); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java index 871292a4774..27ce73e66d9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java @@ -149,7 +149,7 @@ public class SamWrapperCodegen { (ClassDescriptor) erasedInterfaceFunction.getContainingDeclaration(), OwnerKind.IMPLEMENTATION, state), cv, state, parentCodegen); FunctionDescriptor invokeFunction = - functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE, LookupLocation.NO_LOCATION).iterator().next().getOriginal(); + functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE, LookupLocation.NO_LOCATION_FROM_BACKEND).iterator().next().getOriginal(); StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false, StackValue.none()); codegen.genDelegate(erasedInterfaceFunction, invokeFunction, functionField); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt index e1dc9172ea5..fd3afd54c8d 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/MultiModuleJavaAnalysisCustomTest.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoots import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.context.ProjectContext import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetFile @@ -113,7 +114,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() { private fun checkClassInPackage(moduleDescriptor: ModuleDescriptor, packageName: String, className: String) { val kotlinPackage = moduleDescriptor.getPackage(FqName(packageName)) val kotlinClassName = Name.identifier(className) - val kotlinClass = kotlinPackage.memberScope.getClassifier(kotlinClassName) as ClassDescriptor + val kotlinClass = kotlinPackage.memberScope.getClassifier(kotlinClassName, LookupLocation.NO_LOCATION_FROM_TEST) as ClassDescriptor checkClass(kotlinClass) } diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java index 2ea2590cb97..ae4644babe0 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java @@ -155,7 +155,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) { Name functionName = Name.identifier(name); JetScope memberScope = packageView.getMemberScope(); - Collection functions = memberScope.getFunctions(functionName, LookupLocation.NO_LOCATION); + Collection functions = memberScope.getFunctions(functionName, LookupLocation.NO_LOCATION_FROM_TEST); assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName(); return functions.iterator().next(); } @@ -164,7 +164,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { Name functionName = Name.identifier(name); JetScope memberScope = classDescriptor.getMemberScope(Collections.emptyList()); - Collection functions = memberScope.getFunctions(functionName, LookupLocation.NO_LOCATION); + Collection functions = memberScope.getFunctions(functionName, LookupLocation.NO_LOCATION_FROM_TEST); assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName(); return functions.iterator().next(); } @@ -173,13 +173,13 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) { Name propertyName = Name.identifier(name); JetScope memberScope = packageView.getMemberScope(); - Collection properties = memberScope.getProperties(propertyName, LookupLocation.NO_LOCATION); + Collection properties = memberScope.getProperties(propertyName, LookupLocation.NO_LOCATION_FROM_TEST); if (properties.isEmpty()) { for (DeclarationDescriptor descriptor : memberScope.getAllDescriptors()) { if (descriptor instanceof ClassDescriptor) { Collection classProperties = ((ClassDescriptor) descriptor).getMemberScope(Collections.emptyList()) - .getProperties(propertyName, LookupLocation.NO_LOCATION); + .getProperties(propertyName, LookupLocation.NO_LOCATION_FROM_TEST); if (!classProperties.isEmpty()) { properties = classProperties; break; @@ -200,7 +200,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { Name propertyName = Name.identifier(name); JetScope memberScope = classDescriptor.getMemberScope(Collections.emptyList()); - Collection properties = memberScope.getProperties(propertyName, LookupLocation.NO_LOCATION); + Collection properties = memberScope.getProperties(propertyName, LookupLocation.NO_LOCATION_FROM_TEST); assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName(); return (PropertyDescriptor) properties.iterator().next(); } @@ -208,7 +208,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix @NotNull protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) { Name className = Name.identifier(name); - ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className, LookupLocation.NO_LOCATION); + ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className, LookupLocation.NO_LOCATION_FROM_TEST); assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass); assert aClass instanceof ClassDescriptor : "Not a class: " + aClass; return (ClassDescriptor) aClass; @@ -218,7 +218,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix private static ClassDescriptor getInnerClassDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { Name propertyName = Name.identifier(name); JetScope memberScope = classDescriptor.getMemberScope(Collections.emptyList()); - ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName, LookupLocation.NO_LOCATION); + ClassifierDescriptor innerClass = memberScope.getClassifier(propertyName, LookupLocation.NO_LOCATION_FROM_TEST); assert innerClass instanceof ClassDescriptor : "Failed to find inner class " + propertyName + " in class " + diff --git a/compiler/tests/org/jetbrains/kotlin/test/util/DescriptorValidator.java b/compiler/tests/org/jetbrains/kotlin/test/util/DescriptorValidator.java index 8806a5165d2..aba2efb385f 100644 --- a/compiler/tests/org/jetbrains/kotlin/test/util/DescriptorValidator.java +++ b/compiler/tests/org/jetbrains/kotlin/test/util/DescriptorValidator.java @@ -411,7 +411,7 @@ public class DescriptorValidator { public Void visitVariableDescriptor( VariableDescriptor descriptor, JetScope scope ) { - assertFound(scope, descriptor, scope.getProperties(descriptor.getName(), LookupLocation.NO_LOCATION)); + assertFound(scope, descriptor, scope.getProperties(descriptor.getName(), LookupLocation.NO_LOCATION_FROM_TEST)); return null; } @@ -419,7 +419,7 @@ public class DescriptorValidator { public Void visitFunctionDescriptor( FunctionDescriptor descriptor, JetScope scope ) { - assertFound(scope, descriptor, scope.getFunctions(descriptor.getName(), LookupLocation.NO_LOCATION)); + assertFound(scope, descriptor, scope.getFunctions(descriptor.getName(), LookupLocation.NO_LOCATION_FROM_TEST)); return null; } @@ -427,7 +427,7 @@ public class DescriptorValidator { public Void visitTypeParameterDescriptor( TypeParameterDescriptor descriptor, JetScope scope ) { - assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), LookupLocation.NO_LOCATION), true); + assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), LookupLocation.NO_LOCATION_FROM_TEST), true); return null; } @@ -435,7 +435,7 @@ public class DescriptorValidator { public Void visitClassDescriptor( ClassDescriptor descriptor, JetScope scope ) { - assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), LookupLocation.NO_LOCATION), true); + assertFound(scope, descriptor, scope.getClassifier(descriptor.getName(), LookupLocation.NO_LOCATION_FROM_TEST), true); return null; } diff --git a/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java b/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java index 7a074b02fcf..04875d9554c 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/BoundsSubstitutorTest.java @@ -74,7 +74,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment { JetFile jetFile = JetPsiFactory(getProject()).createFile("fun.kt", text); ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment()); Collection functions = - module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"), LookupLocation.NO_LOCATION); + module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"), LookupLocation.NO_LOCATION_FROM_TEST); assert functions.size() == 1 : "Many functions defined"; FunctionDescriptor function = ContainerUtil.getFirstItem(functions); diff --git a/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java index 0bc118bfd11..7aeec7846f9 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/JetTypeCheckerTest.java @@ -624,7 +624,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { else { Name shortName = fqName.shortName(); assert shortName.equals(defaultImport.getImportedName()); - writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName, LookupLocation.NO_LOCATION)); + writableScope.addClassifierDescriptor(module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName, LookupLocation.NO_LOCATION_FROM_TEST)); } } scopeChain.add(module.getPackage(FqName.ROOT).getMemberScope()); diff --git a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java index 760a8937a4d..ed8b088d4f2 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java @@ -86,7 +86,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { JetFile jetFile = JetPsiFactory(getProject()).createFile(text); ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment()); JetScope topLevelDeclarations = module.getPackage(FqName.ROOT).getMemberScope(); - ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"), LookupLocation.NO_LOCATION); + ClassifierDescriptor contextClass = topLevelDeclarations.getClassifier(Name.identifier("___Context"), LookupLocation.NO_LOCATION_FROM_TEST); assert contextClass instanceof ClassDescriptor; WritableScopeImpl typeParameters = new WritableScopeImpl(JetScope.Empty.INSTANCE$, module, RedeclarationHandler.THROW_EXCEPTION, "Type parameter scope"); @@ -125,7 +125,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { String typeParameterName = pair.first; String replacementProjectionString = pair.second; - ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName), LookupLocation.NO_LOCATION); + ClassifierDescriptor classifier = scope.getClassifier(Name.identifier(typeParameterName), LookupLocation.NO_LOCATION_FROM_TEST); assertNotNull("No type parameter named " + typeParameterName, classifier); assertTrue(typeParameterName + " is not a type parameter: " + classifier, classifier instanceof TypeParameterDescriptor); diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt index 380854cd40b..9bbf896d579 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/TypeUtils.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION @@ -81,7 +82,7 @@ fun JetType.isResolvableInScope(scope: JetScope?, checkTypeParameters: Boolean): if (descriptor == null || descriptor.getName().isSpecial()) return false if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true - return scope != null && scope.getClassifier(descriptor.getName()) == descriptor + return scope != null && scope.getClassifier(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) == descriptor } public fun JetType.approximateWithResolvableType(scope: JetScope?, checkTypeParameters: Boolean): JetType { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java index c0e0fe31786..52e82ad2b18 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.java @@ -140,7 +140,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport if (declaration instanceof JetFunction) { JetFunction jetFunction = (JetFunction) declaration; Name name = jetFunction.getNameAsSafeName(); - Collection functions = packageDescriptor.getMemberScope().getFunctions(name, LookupLocation.NO_LOCATION); + Collection functions = packageDescriptor.getMemberScope().getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE); for (FunctionDescriptor descriptor : functions) { ForceResolveUtil.forceResolveAllContents(descriptor); } @@ -148,7 +148,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport else if (declaration instanceof JetProperty) { JetProperty jetProperty = (JetProperty) declaration; Name name = jetProperty.getNameAsSafeName(); - Collection properties = packageDescriptor.getMemberScope().getProperties(name, LookupLocation.NO_LOCATION); + Collection properties = packageDescriptor.getMemberScope().getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE); for (VariableDescriptor descriptor : properties) { ForceResolveUtil.forceResolveAllContents(descriptor); } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt index 986dd1f049d..13f9090a6c9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.caches.resolve import com.intellij.openapi.project.Project import com.intellij.psi.* import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.load.java.sources.JavaSourceElement import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.impl.* @@ -73,7 +74,7 @@ fun PsiMember.getJavaMemberDescriptor(): DeclarationDescriptor? { } public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? { - return getContainingScope(method)?.getFunctions(method.getName())?.findByJavaElement(method) + return getContainingScope(method)?.getFunctions(method.name, LookupLocation.NO_LOCATION_FROM_IDE)?.findByJavaElement(method) } public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? { @@ -81,7 +82,7 @@ public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructo } public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? { - return getContainingScope(field)?.getProperties(field.getName())?.findByJavaElement(field) as? PropertyDescriptor + return getContainingScope(field)?.getProperties(field.name, LookupLocation.NO_LOCATION_FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor } private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): JetScope? { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt index 47467719f73..54e6eb66765 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt @@ -16,11 +16,9 @@ package org.jetbrains.kotlin.idea.util -import com.intellij.openapi.util.Key import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement -import com.intellij.psi.PsiRecursiveElementVisitor import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.analyzer.analyzeInContext import org.jetbrains.kotlin.descriptors.ClassDescriptor @@ -32,10 +30,10 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport import org.jetbrains.kotlin.idea.imports.getImportableTargets import org.jetbrains.kotlin.idea.util.ShortenReferences.Options +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext @@ -275,7 +273,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options. val typeReference = type.getStrictParentOfType()!! val scope = bindingContext[BindingContext.TYPE_RESOLUTION_SCOPE, typeReference]!! val name = target.getName() - val targetByName = if (target is ClassifierDescriptor) scope.getClassifier(name) else scope.getPackage(name) + val targetByName = if (target is ClassifierDescriptor) scope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) else scope.getPackage(name) val canShortenNow = targetByName?.asString() == target.asString() processQualifiedElement(type, target, canShortenNow) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt index b6842b0d23c..ac3bafe7111 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.idea.JetDescriptorIconProvider import org.jetbrains.kotlin.idea.completion.* +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.resolve.BindingContext @@ -89,7 +90,7 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext, private fun variableInScope(parameter: ValueParameterDescriptor, scope: JetScope): VariableDescriptor? { val name = parameter.getName() //TODO: there can be more than one property with such name in scope and we should be able to select one (but we need API for this) - val variable = scope.getLocalVariable(name) ?: scope.getProperties(name).singleOrNull() ?: return null + val variable = scope.getLocalVariable(name) ?: scope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).singleOrNull() ?: return null return if (smartCastCalculator.types(variable).any { JetTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) }) variable else diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index b995d6c2578..a9ba273f8e6 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMethodsHandler import org.jetbrains.kotlin.idea.core.psiClassToDescriptor import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor import org.jetbrains.kotlin.platform.JavaToKotlinClassMap import org.jetbrains.kotlin.psi.JetClassOrObject @@ -253,7 +254,7 @@ class TypeInstantiationItems( is ClassDescriptor -> container.getStaticScope() else -> return } - val samConstructor = scope.getFunctions(`class`.getName()) + val samConstructor = scope.getFunctions(`class`.name, LookupLocation.NO_LOCATION_FROM_IDE) .filterIsInstance() .singleOrNull() ?: return val lookupElement = lookupElementFactory.createLookupElement(samConstructor, bindingContext, false) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt index a08366ff98b..ef752abd14a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt @@ -16,21 +16,21 @@ package org.jetbrains.kotlin.idea.completion.smart -import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.resolve.scopes.JetScope -import java.util.HashMap -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.types.TypeUtils -import org.jetbrains.kotlin.types.typeUtil.nullability -import org.jetbrains.kotlin.types.typeUtil.TypeNullability -import org.jetbrains.kotlin.idea.util.FuzzyType -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.ModuleDescriptor import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.idea.completion.HeuristicSignatures +import org.jetbrains.kotlin.idea.util.FuzzyType import org.jetbrains.kotlin.idea.util.nullability +import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.scopes.JetScope +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.typeUtil.TypeNullability +import java.util.HashMap class TypesWithContainsDetector( private val scope: JetScope, @@ -43,7 +43,7 @@ class TypesWithContainsDetector( private val containsName = Name.identifier("contains") private val booleanType = KotlinBuiltIns.getInstance().getBooleanType() - private val typesWithExtensionContains: Collection = scope.getFunctions(containsName) + private val typesWithExtensionContains: Collection = scope.getFunctions(containsName, LookupLocation.NO_LOCATION_FROM_IDE) .filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) } .map { it.getExtensionReceiverParameter()!!.getType() } @@ -52,7 +52,8 @@ class TypesWithContainsDetector( } private fun hasContainsNoCache(type: FuzzyType): Boolean { - return type.nullability() != TypeNullability.NULLABLE && type.type.getMemberScope().getFunctions(containsName).any { isGoodContainsFunction(it, type.freeParameters) } + return type.nullability() != TypeNullability.NULLABLE && + type.type.memberScope.getFunctions(containsName, LookupLocation.NO_LOCATION_FROM_IDE).any { isGoodContainsFunction(it, type.freeParameters) } || typesWithExtensionContains.any { type.checkIsSubtypeOf(it) != null } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetector.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetector.kt index 3a3a8e0a361..15ed9b366bd 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetector.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/IterableTypesDetector.kt @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.frontend.di.createContainerForMacros import org.jetbrains.kotlin.idea.util.FuzzyType +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.resolve.BindingTraceContext @@ -41,7 +42,7 @@ public class IterableTypesDetector( private val cache = HashMap() private val iteratorName = Name.identifier("iterator") - private val typesWithExtensionIterator: Collection = scope.getFunctions(iteratorName) + private val typesWithExtensionIterator: Collection = scope.getFunctions(iteratorName, LookupLocation.NO_LOCATION_FROM_IDE) .map { it.getExtensionReceiverParameter() } .filterNotNull() .map { it.getType() } @@ -74,6 +75,7 @@ public class IterableTypesDetector( } private fun canBeIterable(type: FuzzyType): Boolean { - return type.type.getMemberScope().getFunctions(iteratorName).isNotEmpty() || typesWithExtensionIterator.any { type.checkIsSubtypeOf(it) != null } + return type.type.memberScope.getFunctions(iteratorName, LookupLocation.NO_LOCATION_FROM_IDE).isNotEmpty() || + typesWithExtensionIterator.any { type.checkIsSubtypeOf(it) != null } } -} \ No newline at end of file +} diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt index 13008275240..e7e6eb36b7c 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/NameValidators.kt @@ -21,13 +21,13 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.allChildren import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.psi.psiUtil.siblings -import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.JetScope @@ -96,8 +96,12 @@ public class NewDeclarationNameValidator( } return when(target) { - Target.VARIABLES -> getProperties(name).any { !it.isExtension && it.isVisible() } || getLocalVariable(name) != null - Target.FUNCTIONS_AND_CLASSES -> getFunctions(name).any { !it.isExtension && it.isVisible() } || getClassifier(name)?.let { it.isVisible() } ?: false + Target.VARIABLES -> + getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).any { !it.isExtension && it.isVisible() } || + getLocalVariable(name) != null + Target.FUNCTIONS_AND_CLASSES -> + getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE).any { !it.isExtension && it.isVisible() } || + getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE)?.let { it.isVisible() } ?: false } } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt index 2cb8b806d32..e957d30d0f9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinCopyPasteReferenceProcessor.kt @@ -42,9 +42,13 @@ import org.jetbrains.kotlin.idea.conversion.copy.range import org.jetbrains.kotlin.idea.conversion.copy.start import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport import org.jetbrains.kotlin.idea.imports.importableFqName -import org.jetbrains.kotlin.idea.references.* +import org.jetbrains.kotlin.idea.references.JetMultiReference +import org.jetbrains.kotlin.idea.references.JetReference +import org.jetbrains.kotlin.idea.references.JetSimpleNameReference +import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.application.runWriteAction +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.elementsInRange @@ -234,10 +238,12 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor = when (descriptor) { - is FunctionDescriptor -> packageDescriptor.memberScope.getFunctions(descriptor.getName()) - is PropertyDescriptor -> packageDescriptor.memberScope.getProperties(descriptor.getName()) + is FunctionDescriptor -> packageDescriptor.memberScope.getFunctions(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) + is PropertyDescriptor -> packageDescriptor.memberScope.getProperties(descriptor.name, LookupLocation.NO_LOCATION_FROM_IDE) else -> { reportError(topLevelDeclaration, descriptor) listOf() diff --git a/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt b/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt index 3c0a048c13a..cebeafc4be0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/imports/KotlinImportOptimizer.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings import org.jetbrains.kotlin.idea.references.JetReference import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.application.runWriteAction +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* @@ -198,7 +199,7 @@ public class KotlinImportOptimizer() : ImportOptimizer { val scope = fileWithImports.getResolutionFacade().getFileTopLevelScope(fileWithImports) for (fqName in classNamesToCheck) { - if (scope.getClassifier(fqName.shortName())?.importableFqNameSafe != fqName) { + if (scope.getClassifier(fqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE)?.importableFqNameSafe != fqName) { // add explicit import if failed to import with * (or from current package) importsToGenerate.add(ImportPath(fqName, false)) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index 19f3bb5481c..f3cbd3dcae8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -42,14 +42,15 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.search import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.idea.util.application.executeWriteCommand +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.types.typeUtil.supertypes import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.types.expressions.OperatorConventions +import org.jetbrains.kotlin.types.typeUtil.supertypes import java.util.ArrayList public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention(javaClass(), "Convert function to property"), LowPriorityAction { @@ -114,7 +115,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention, scope: JetScope): List { return typeParameters.filter { typeParameter -> - val classifier = scope.getClassifier(typeParameter.getName()) + val classifier = scope.getClassifier(typeParameter.name, LookupLocation.NO_LOCATION_FROM_IDE) classifier == null || classifier != typeParameter } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt index decb5d064a6..90a8e8c5a7d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getTyp import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement @@ -136,5 +137,5 @@ fun JetType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, conte else -> null } ?: return true - return typeParametersToAdd.any { scope.getClassifier(it.name) != it } + return typeParametersToAdd.any { scope.getClassifier(it.name, LookupLocation.NO_LOCATION_FROM_IDE) != it } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt index f2555aea6db..3dd14c1d748 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureData.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.core.CollectingNameValidator import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetCallableDefinitionUsage +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetCallableDeclaration import org.jetbrains.kotlin.psi.JetClass @@ -80,7 +81,7 @@ public class JetChangeSignatureData( val validator = bodyScope?.let { bodyScope -> CollectingNameValidator(paramNames) { val name = Name.identifier(it) - bodyScope.getLocalVariable(name) == null && bodyScope.getProperties(name).isEmpty() + bodyScope.getLocalVariable(name) == null && bodyScope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE).isEmpty() } } ?: CollectingNameValidator(paramNames) val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java index 068159396b1..8c0f028bcbf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java @@ -623,8 +623,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro if (!kind.getIsConstructor() && callableScope != null && !info.getNewName().isEmpty()) { Name newName = Name.identifier(info.getNewName()); Collection conflicts = oldDescriptor instanceof FunctionDescriptor - ? callableScope.getFunctions(newName, LookupLocation.NO_LOCATION) - : callableScope.getProperties(newName, LookupLocation.NO_LOCATION); + ? callableScope.getFunctions(newName, LookupLocation.NO_LOCATION_FROM_IDE) + : callableScope.getProperties(newName, LookupLocation.NO_LOCATION_FROM_IDE); for (CallableDescriptor conflict : conflicts) { if (conflict == oldDescriptor) continue; @@ -647,7 +647,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro } if (parametersScope != null) { if (kind == JetMethodDescriptor.Kind.PRIMARY_CONSTRUCTOR && valOrVar != JetValVar.None) { - for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName), LookupLocation.NO_LOCATION)) { + for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName), LookupLocation.NO_LOCATION_FROM_IDE)) { PsiElement propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property); if (propertyDeclaration != null && !(propertyDeclaration.getParent() instanceof JetParameterList)) { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt index c6542353df0..eb19cf39072 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt @@ -60,6 +60,7 @@ import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.approximateWithResolvableType import org.jetbrains.kotlin.idea.util.isResolvableInScope +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.renderer.DescriptorRenderer @@ -649,7 +650,7 @@ private fun ExtractionData.inferParametersInfo( options.captureLocalFunctions && originalRef.getReferencedName() == originalDescriptor.getName().asString() // to forbid calls by convention && originalDeclaration is JetNamedFunction && originalDeclaration.isLocal() - && (targetScope == null || originalDescriptor !in targetScope.getFunctions(originalDescriptor.getName())) + && (targetScope == null || originalDescriptor !in targetScope.getFunctions(originalDescriptor.name, LookupLocation.NO_LOCATION_FROM_IDE)) val descriptorToExtract = (if (extractThis) thisDescriptor else null) ?: originalDescriptor @@ -1024,4 +1025,4 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts return ExtractableCodeDescriptorWithConflicts(this, conflicts) } -private val LOG = Logger.getInstance(javaClass()) \ No newline at end of file +private val LOG = Logger.getInstance(javaClass()) diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt index 12ae2912a48..7673c0f40a2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt @@ -16,8 +16,6 @@ package org.jetbrains.kotlin.util -import com.intellij.codeInsight.CodeInsightSettings -import com.intellij.codeInsight.actions.OptimizeImportsProcessor import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.impl.PsiModificationTrackerImpl @@ -33,6 +31,7 @@ import org.jetbrains.kotlin.idea.project.ProjectStructureUtil import org.jetbrains.kotlin.idea.refactoring.fqName.isImported import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper.ImportDescriptorResult +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* @@ -121,11 +120,24 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert // check if import is not needed when (target) { - is ClassDescriptor -> { if (topLevelScope.getClassifier(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED } - is PackageViewDescriptor -> { if (topLevelScope.getPackage(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED } - is FunctionDescriptor -> { if (topLevelScope.getFunctions(name).map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED } - is PropertyDescriptor -> { if (topLevelScope.getProperties(name).map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED } - else -> return ImportDescriptorResult.FAIL + is ClassDescriptor -> { + val classifier = topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) + if (classifier?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED + } + is PackageViewDescriptor -> { + if (topLevelScope.getPackage(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED + } + is FunctionDescriptor -> { + val functions = topLevelScope.getFunctions(name, LookupLocation.NO_LOCATION_FROM_IDE) + if (functions.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED + } + is PropertyDescriptor -> { + val properties = topLevelScope.getProperties(name, LookupLocation.NO_LOCATION_FROM_IDE) + if (properties.map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED + } + else -> { + return ImportDescriptorResult.FAIL + } } if (!mayImportByCodeStyle(descriptor)) { @@ -139,7 +151,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert // check there is an explicit import of a class/package with the same name already val conflict = when (target) { - is ClassDescriptor -> topLevelScope.getClassifier(name) + is ClassDescriptor -> topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) is PackageViewDescriptor -> topLevelScope.getPackage(name) else -> null } @@ -156,7 +168,9 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert val tryStarImport = shouldTryStarImport(packageFqName, imports) && when (target) { - is ClassDescriptor -> topLevelScope.getClassifier(name) == null // this check does not give a guarantee that import with * will import the class - for example, there can be classes with conflicting name in more than one import with * + // this check does not give a guarantee that import with * will import the class - for example, + // there can be classes with conflicting name in more than one import with * + is ClassDescriptor -> topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) == null is PackageViewDescriptor -> false is FunctionDescriptor, is PropertyDescriptor -> true else -> throw Exception() @@ -222,12 +236,14 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert val topLevelScope = resolutionFacade.getFileTopLevelScope(file) val conflictCandidates: List = classNamesToImport .flatMap { - importedScopes.map { scope -> scope.getClassifier(it) }.filterNotNull() + importedScopes.map { scope -> scope.getClassifier(it, LookupLocation.NO_LOCATION_FROM_IDE) }.filterNotNull() } .filter { importedClass -> isVisible(importedClass) - && topLevelScope.getClassifier(importedClass.getName()) == importedClass /* check that class is really imported */ - && imports.all { it.getImportPath() != ImportPath(importedClass.importableFqNameSafe, false) } /* and not yet imported explicitly */ + // check that class is really imported + && topLevelScope.getClassifier(importedClass.name, LookupLocation.NO_LOCATION_FROM_IDE) == importedClass + // and not yet imported explicitly + && imports.all { it.importPath != ImportPath(importedClass.importableFqNameSafe, false) } } val conflicts = detectNeededImports(conflictCandidates) @@ -235,7 +251,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert if (target is ClassDescriptor) { val newTopLevelScope = resolutionFacade.getFileTopLevelScope(file) - val resolvedTo = newTopLevelScope.getClassifier(target.getName()) + val resolvedTo = newTopLevelScope.getClassifier(target.name, LookupLocation.NO_LOCATION_FROM_IDE) if (resolvedTo?.importableFqNameSafe != targetFqName) { addedImport.delete() return ImportDescriptorResult.FAIL @@ -258,7 +274,8 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert } val parentScope = getMemberScope(fqName.parent(), moduleDescriptor) ?: return null - val classDescriptor = parentScope.getClassifier(fqName.shortName()) as? ClassDescriptor ?: return null + val classifier = parentScope.getClassifier(fqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) + val classDescriptor = classifier as? ClassDescriptor ?: return null return classDescriptor.getDefaultType().getMemberScope() } @@ -269,7 +286,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert // check if there is a conflicting class imported with * import // (not with explicit import - explicit imports are checked before this method invocation) - val classifier = topLevelScope.getClassifier(name) + val classifier = topLevelScope.getClassifier(name, LookupLocation.NO_LOCATION_FROM_IDE) if (classifier != null && detectNeededImports(listOf(classifier)).isNotEmpty()) { return ImportDescriptorResult.FAIL } @@ -298,7 +315,8 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert if (importsToCheck.isNotEmpty()) { val topLevelScope = resolutionFacade.getFileTopLevelScope(file) for (classFqName in importsToCheck) { - if (topLevelScope.getClassifier(classFqName.shortName())?.importableFqNameSafe != classFqName) { + val classifier = topLevelScope.getClassifier(classFqName.shortName(), LookupLocation.NO_LOCATION_FROM_IDE) + if (classifier?.importableFqNameSafe != classFqName) { addImport(classFqName, false) // restore explicit import } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt index df96bdc109d..e070d6ec382 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt @@ -18,8 +18,9 @@ package org.jetbrains.kotlin.idea.kdoc import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetFile import org.junit.Assert @@ -42,7 +43,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() { myFixture.configureByFile(getTestName(false) + ".kt") val declaration = (myFixture.getFile() as JetFile).getDeclarations().single { it.getName() == "Bar" } val descriptor = declaration.resolveToDescriptor() as ClassDescriptor - val overriddenFunctionDescriptor = descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("xyzzy")).single() + val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getFunctions(Name.identifier("xyzzy"), LookupLocation.NO_LOCATION_FROM_TEST).single() val doc = KDocFinder.findKDoc(overriddenFunctionDescriptor) Assert.assertEquals("Doc for method xyzzy", doc!!.getContent()) } @@ -51,7 +52,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() { myFixture.configureByFile(getTestName(false) + ".kt") val declaration = (myFixture.getFile() as JetFile).getDeclarations().single { it.getName() == "Bar" } val descriptor = declaration.resolveToDescriptor() as ClassDescriptor - val overriddenFunctionDescriptor = descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("xyzzy")).single() + val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getFunctions(Name.identifier("xyzzy"), LookupLocation.NO_LOCATION_FROM_TEST).single() val doc = KDocFinder.findKDoc(overriddenFunctionDescriptor) Assert.assertEquals("Doc for method xyzzy", doc!!.getContent()) } @@ -60,7 +61,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() { myFixture.configureByFile(getTestName(false) + ".kt") val declaration = (myFixture.getFile() as JetFile).getDeclarations().single { it.getName() == "Foo" } val descriptor = declaration.resolveToDescriptor() as ClassDescriptor - val propertyDescriptor = descriptor.getDefaultType().getMemberScope().getProperties(Name.identifier("xyzzy")).single() + val propertyDescriptor = descriptor.defaultType.memberScope.getProperties(Name.identifier("xyzzy"), LookupLocation.NO_LOCATION_FROM_TEST).single() val doc = KDocFinder.findKDoc(propertyDescriptor) Assert.assertEquals("Doc for property xyzzy", doc!!.getContent()) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt index b2ff687f103..136cfb78f5a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt @@ -47,6 +47,7 @@ import org.jetbrains.kotlin.idea.search.allScope import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.* import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType @@ -185,13 +186,13 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() { private fun renameKotlinFunctionTest(renameParamsObject: JsonObject, context: TestContext) { val oldMethodName = Name.identifier(renameParamsObject.getString("oldName")) - doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getFunctions(oldMethodName).first() } + doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getFunctions(oldMethodName, LookupLocation.NO_LOCATION_FROM_TEST).first() } } private fun renameKotlinPropertyTest(renameParamsObject: JsonObject, context: TestContext) { val oldPropertyName = Name.identifier(renameParamsObject.getString("oldName")) - doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getProperties(oldPropertyName).first() } + doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getProperties(oldPropertyName, LookupLocation.NO_LOCATION_FROM_TEST).first() } } private fun renameKotlinClassTest(renameParamsObject: JsonObject, context: TestContext) { diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/ManglingUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/ManglingUtils.java index c6613b63508..d9259b87f8c 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/ManglingUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/ManglingUtils.java @@ -249,7 +249,7 @@ public class ManglingUtils { @NotNull public static String getStableMangledNameForDescriptor(@NotNull ClassDescriptor descriptor, @NotNull String functionName) { Collection functions = - descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier(functionName), LookupLocation.NO_LOCATION); + descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier(functionName), LookupLocation.NO_LOCATION_FROM_BACKEND); assert functions.size() == 1 : "Can't select a single function: " + functionName + " in " + descriptor; return getSuggestedName((DeclarationDescriptor) functions.iterator().next()); }