From 7b6f83815ce8218e66467f115f5dcc7a64c961e5 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 3 Mar 2015 12:38:31 +0300 Subject: [PATCH] Unified obtaining psi element for descriptor. Now code for finding effective descriptors of fake override and finding source element for original declarations are separated. Old method DescriptorToSourceUtils.descriptorToDeclaration is still there, because it has ~90 usages. --- .../kotlin/codegen/ExpressionCodegen.java | 2 +- .../kotlin/codegen/FunctionCodegen.java | 8 +- ...FactoryForDuplicateSignatureDiagnostics.kt | 4 +- .../kotlin/codegen/state/JetTypeMapper.java | 2 +- .../kotlin/resolve/BindingContextUtils.java | 4 +- .../resolve/DescriptorToSourceUtils.java | 90 +++++++------------ .../kotlin/resolve/LibrarySourceHacks.kt | 4 +- .../DescriptorToDeclarationUtil.kt | 43 ++++----- .../navigation/DecompiledNavigationUtils.java | 15 +--- .../references/BuiltInsReferenceResolver.java | 18 ++-- .../debugger/KotlinSmartStepIntoHandler.kt | 9 +- .../quickfix/ChangeFunctionSignatureFix.java | 4 +- .../changeSignature/beforeNotEditable.kt | 12 +++ .../idea/quickfix/QuickFixTestGenerated.java | 6 ++ .../BuiltInsReferenceResolverTest.java | 4 +- 15 files changed, 94 insertions(+), 131 deletions(-) create mode 100644 idea/testData/quickfix/changeSignature/beforeNotEditable.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index fcc4f00fda8..f8e9f258d9e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1817,7 +1817,7 @@ public class ExpressionCodegen extends JetVisitor implem } PsiElement element = bindingContext.get(LABEL_TARGET, expression.getTargetLabel()); - if (element != DescriptorToSourceUtils.callableDescriptorToDeclaration(context.getContextDescriptor())) { + if (element != DescriptorToSourceUtils.getSourceFromDescriptor(context.getContextDescriptor())) { DeclarationDescriptor elementDescriptor = typeMapper.getBindingContext().get(DECLARATION_TO_DESCRIPTOR, element); assert element != null : "Expression should be not null " + expression.getText(); assert elementDescriptor != null : "Descriptor should be not null: " + element.getText(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 8beb2d42eeb..168d586455d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -73,7 +73,7 @@ import static org.jetbrains.kotlin.codegen.JvmSerializationBindings.*; import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.isLocalNamedFun; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION; import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.OLD_JET_VALUE_PARAMETER_ANNOTATION; -import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.callableDescriptorToDeclaration; +import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.getSourceFromDescriptor; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isFunctionLiteral; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait; import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE; @@ -498,7 +498,7 @@ public class FunctionCodegen { ); if (!bridgesToGenerate.isEmpty()) { - PsiElement origin = descriptor.getKind() == DECLARATION ? callableDescriptorToDeclaration(descriptor) : null; + PsiElement origin = descriptor.getKind() == DECLARATION ? getSourceFromDescriptor(descriptor) : null; for (Bridge bridge : bridgesToGenerate) { generateBridge(origin, descriptor, bridge.getFrom(), bridge.getTo()); } @@ -628,12 +628,12 @@ public class FunctionCodegen { if (this.owner instanceof PackageFacadeContext) { mv.visitCode(); generatePackageDelegateMethodBody(mv, defaultMethod, (PackageFacadeContext) this.owner); - endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor)); + endVisit(mv, "default method delegation", getSourceFromDescriptor(functionDescriptor)); } else { mv.visitCode(); generateDefaultImplBody(owner, functionDescriptor, mv, loadStrategy, function, memberCodegen); - endVisit(mv, "default method", callableDescriptorToDeclaration(functionDescriptor)); + endVisit(mv, "default method", getSourceFromDescriptor(functionDescriptor)); } } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/BuilderFactoryForDuplicateSignatureDiagnostics.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/BuilderFactoryForDuplicateSignatureDiagnostics.kt index 627a2f01bf0..87916de4be1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/BuilderFactoryForDuplicateSignatureDiagnostics.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/BuilderFactoryForDuplicateSignatureDiagnostics.kt @@ -101,9 +101,9 @@ class BuilderFactoryForDuplicateSignatureDiagnostics( if (member.getKind() != DELEGATION) { // Delegates don't have declarations in the code - memberElement = origin.element ?: DescriptorToSourceUtils.callableDescriptorToDeclaration(member) + memberElement = origin.element ?: DescriptorToSourceUtils.descriptorToDeclaration(member) if (memberElement == null && member is PropertyAccessorDescriptor) { - memberElement = DescriptorToSourceUtils.callableDescriptorToDeclaration(member.getCorrespondingProperty()) + memberElement = DescriptorToSourceUtils.descriptorToDeclaration(member.getCorrespondingProperty()) } } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java index ecd9ad4aeab..24a0f0d0456 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java @@ -619,7 +619,7 @@ public class JetTypeMapper { return "invoke"; } else if (descriptor instanceof AnonymousFunctionDescriptor) { - PsiElement element = DescriptorToSourceUtils.callableDescriptorToDeclaration(descriptor); + PsiElement element = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor); if (element instanceof JetFunctionLiteral) { PsiElement expression = element.getParent(); if (expression instanceof JetFunctionLiteralExpression) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.java index 3bb636fd557..ccc714d3f11 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContextUtils.java @@ -175,11 +175,11 @@ public class BindingContextUtils { ) { FunctionDescriptor containingFunctionDescriptor = DescriptorUtils.getParentOfType(startDescriptor, FunctionDescriptor.class, strict); PsiElement containingFunction = - containingFunctionDescriptor != null ? DescriptorToSourceUtils.callableDescriptorToDeclaration(containingFunctionDescriptor) : null; + containingFunctionDescriptor != null ? DescriptorToSourceUtils.getSourceFromDescriptor(containingFunctionDescriptor) : null; while (containingFunction instanceof JetFunctionLiteral) { containingFunctionDescriptor = DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class); containingFunction = containingFunctionDescriptor != null ? DescriptorToSourceUtils - .callableDescriptorToDeclaration(containingFunctionDescriptor) : null; + .getSourceFromDescriptor(containingFunctionDescriptor) : null; } return new Pair(containingFunctionDescriptor, containingFunction); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.java index aaee4c70529..af78ec98ca7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorToSourceUtils.java @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.resolve; -import com.google.common.collect.Lists; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; @@ -26,87 +25,58 @@ import org.jetbrains.kotlin.psi.JetFile; import org.jetbrains.kotlin.resolve.source.SourcePackage; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Set; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED; public final class DescriptorToSourceUtils { + private static void collectEffectiveReferencedDescriptors(@NotNull List result, @NotNull DeclarationDescriptor descriptor) { + if (descriptor instanceof CallableMemberDescriptor) { + CallableMemberDescriptor.Kind kind = ((CallableMemberDescriptor) descriptor).getKind(); + if (kind != DECLARATION && kind != SYNTHESIZED) { + for (DeclarationDescriptor overridden: ((CallableMemberDescriptor) descriptor).getOverriddenDescriptors()) { + collectEffectiveReferencedDescriptors(result, overridden.getOriginal()); + } + return; + } + } + result.add(descriptor); + } + + @NotNull + public static Collection getEffectiveReferencedDescriptors(@NotNull DeclarationDescriptor descriptor) { + List result = new ArrayList(); + collectEffectiveReferencedDescriptors(result, descriptor.getOriginal()); + return result; + } @Nullable - private static PsiElement doGetDescriptorToDeclaration(@NotNull DeclarationDescriptor descriptor) { - DeclarationDescriptor original = descriptor.getOriginal(); - if (!(original instanceof DeclarationDescriptorWithSource)) { + public static PsiElement getSourceFromDescriptor(@NotNull DeclarationDescriptor descriptor) { + if (!(descriptor instanceof DeclarationDescriptorWithSource)) { return null; } - return SourcePackage.getPsi(((DeclarationDescriptorWithSource) original).getSource()); + return SourcePackage.getPsi(((DeclarationDescriptorWithSource) descriptor).getSource()); } // NOTE this is also used by KDoc @Nullable public static PsiElement descriptorToDeclaration(@NotNull DeclarationDescriptor descriptor) { - if (descriptor instanceof CallableMemberDescriptor) { - return callableDescriptorToDeclaration((CallableMemberDescriptor) descriptor); - } - else if (descriptor instanceof ClassDescriptor) { - return classDescriptorToDeclaration((ClassDescriptor) descriptor); - } - else { - return doGetDescriptorToDeclaration(descriptor); - } - } - - @NotNull - public static List descriptorToDeclarations(@NotNull DeclarationDescriptor descriptor) { - if (descriptor instanceof CallableMemberDescriptor) { - return callableDescriptorToDeclarations((CallableMemberDescriptor) descriptor); - } - else { - PsiElement psiElement = descriptorToDeclaration(descriptor); - if (psiElement != null) { - return Lists.newArrayList(psiElement); - } else { - return Lists.newArrayList(); + for (DeclarationDescriptor declarationDescriptor : getEffectiveReferencedDescriptors(descriptor.getOriginal())) { + PsiElement source = getSourceFromDescriptor(declarationDescriptor); + if (source != null) { + return source; } } - } - - @Nullable - public static PsiElement callableDescriptorToDeclaration(@NotNull CallableMemberDescriptor callable) { - if (callable.getKind() == DECLARATION || callable.getKind() == SYNTHESIZED) { - return doGetDescriptorToDeclaration(callable); - } - //TODO: should not use this method for fake_override and delegation - Set overriddenDescriptors = callable.getOverriddenDescriptors(); - if (overriddenDescriptors.size() == 1) { - return callableDescriptorToDeclaration(overriddenDescriptors.iterator().next()); - } return null; } - @NotNull - public static List callableDescriptorToDeclarations(@NotNull CallableMemberDescriptor callable) { - if (callable.getKind() == DECLARATION || callable.getKind() == SYNTHESIZED) { - PsiElement psiElement = doGetDescriptorToDeclaration(callable); - return psiElement != null ? Lists.newArrayList(psiElement) : Lists.newArrayList(); - } - - List r = new ArrayList(); - Set overriddenDescriptors = callable.getOverriddenDescriptors(); - for (CallableMemberDescriptor overridden : overriddenDescriptors) { - r.addAll(callableDescriptorToDeclarations(overridden)); - } - return r; - } - @Nullable public static PsiElement classDescriptorToDeclaration(@NotNull ClassDescriptor clazz) { - return doGetDescriptorToDeclaration(clazz); + return getSourceFromDescriptor(clazz); } - private DescriptorToSourceUtils() {} - @Nullable public static JetFile getContainingFile(@NotNull DeclarationDescriptor declarationDescriptor) { // declarationDescriptor may describe a synthesized element which doesn't have PSI @@ -133,6 +103,6 @@ public final class DescriptorToSourceUtils { } return descriptor; } + + private DescriptorToSourceUtils() {} } - - diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LibrarySourceHacks.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LibrarySourceHacks.kt index 643292693ad..21cb79cab3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LibrarySourceHacks.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LibrarySourceHacks.kt @@ -21,8 +21,6 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.callableDescriptorToDeclaration - public object LibrarySourceHacks { public val SKIP_TOP_LEVEL_MEMBERS: Key = Key.create("SKIP_TOP_LEVEL_MEMBERS") // used when analyzing library source @@ -31,7 +29,7 @@ public object LibrarySourceHacks { if (original.getContainingDeclaration() !is PackageFragmentDescriptor) return false - val declaration = callableDescriptorToDeclaration(original) ?: return false + val declaration = DescriptorToSourceUtils.getSourceFromDescriptor(original) ?: return false val file = declaration.getContainingFile() return file != null && (file.getUserData(SKIP_TOP_LEVEL_MEMBERS) ?: false) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToDeclarationUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToDeclarationUtil.kt index 4c02a99eaca..bd45ad48f6d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToDeclarationUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/codeInsight/DescriptorToDeclarationUtil.kt @@ -18,38 +18,38 @@ package org.jetbrains.kotlin.idea.codeInsight import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.idea.decompiler.navigation.DecompiledNavigationUtils import org.jetbrains.kotlin.idea.references.BuiltInsReferenceResolver -import java.util.HashSet -import org.jetbrains.kotlin.descriptors.PackageViewDescriptor import com.intellij.psi.JavaPsiFacade import org.jetbrains.kotlin.idea.search.allScope import org.jetbrains.kotlin.utils.addIfNotNull +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.* +import java.util.* +import org.jetbrains.kotlin.descriptors.* +// TODO rename it it DescriptorToSourceIde public object DescriptorToDeclarationUtil { public fun getDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? { - var elements: Collection = DescriptorToSourceUtils.descriptorToDeclarations(descriptor) - if (elements.isEmpty()) { - elements = findDecompiledAndBuiltInDeclarations(project, descriptor) - } - - return elements.firstOrNull() + // TODO optimize it! + return resolveToPsiElements(project, descriptor).firstOrNull() } public fun resolveToPsiElements(project: Project, targetDescriptor: DeclarationDescriptor): Collection { val result = HashSet() - // todo: remove getOriginal() - val originalDescriptor = targetDescriptor.getOriginal() - result.addAll(DescriptorToSourceUtils.descriptorToDeclarations(originalDescriptor)) - result.addAll(DescriptorToDeclarationUtil.findDecompiledAndBuiltInDeclarations(project, originalDescriptor)) + val effectiveReferencedDescriptors: Collection = DescriptorToSourceUtils.getEffectiveReferencedDescriptors(targetDescriptor) - if (originalDescriptor is PackageViewDescriptor) { + for (descriptor in effectiveReferencedDescriptors) { + result.addIfNotNull(DescriptorToSourceUtils.getSourceFromDescriptor(descriptor)) + result.addIfNotNull(findBuiltinDeclaration(project, descriptor)) + result.addIfNotNull(DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, descriptor)) + } + + if (targetDescriptor is PackageViewDescriptor) { val psiFacade = JavaPsiFacade.getInstance(project) - val fqName = originalDescriptor.getFqName().asString() + val fqName = targetDescriptor.getFqName().asString() result.addIfNotNull(psiFacade.findPackage(fqName)) result.addIfNotNull(psiFacade.findClass(fqName, project.allScope())) } @@ -58,17 +58,8 @@ public object DescriptorToDeclarationUtil { return result.filter { element -> result.none { element != it && it.getNavigationElement() == element } } } - private fun findDecompiledAndBuiltInDeclarations(project: Project, descriptor: DeclarationDescriptor): Collection { + private fun findBuiltinDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? { val libraryReferenceResolver = project.getComponent(javaClass()) - val elements = libraryReferenceResolver!!.resolveBuiltInSymbol(descriptor) - if (elements.isNotEmpty()) { - return elements - } - - val decompiledDeclaration = DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, descriptor) - if (decompiledDeclaration != null) { - return setOf(decompiledDeclaration) - } - return setOf() + return libraryReferenceResolver!!.resolveBuiltInSymbol(descriptor) } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/DecompiledNavigationUtils.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/DecompiledNavigationUtils.java index cd9f337aa53..187370aa887 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/DecompiledNavigationUtils.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/DecompiledNavigationUtils.java @@ -45,8 +45,7 @@ public final class DecompiledNavigationUtils { @NotNull Project project, @NotNull DeclarationDescriptor referencedDescriptor ) { - DeclarationDescriptor effectiveReferencedDescriptor = getEffectiveReferencedDescriptor(referencedDescriptor); - VirtualFile virtualFile = findVirtualFileContainingDescriptor(project, effectiveReferencedDescriptor); + VirtualFile virtualFile = findVirtualFileContainingDescriptor(project, referencedDescriptor); if (virtualFile == null || !DecompilerPackage.isKotlinCompiledFile(virtualFile)) return null; @@ -55,19 +54,9 @@ public final class DecompiledNavigationUtils { return null; } - return ((JetClsFile) psiFile).getDeclarationForDescriptor(effectiveReferencedDescriptor); + return ((JetClsFile) psiFile).getDeclarationForDescriptor(referencedDescriptor); } - //TODO: should be done via some generic mechanism - @NotNull - private static DeclarationDescriptor getEffectiveReferencedDescriptor(@NotNull DeclarationDescriptor descriptor) { - if (descriptor instanceof CallableMemberDescriptor) { - return DescriptorUtils.unwrapFakeOverride((CallableMemberDescriptor) descriptor); - } - return descriptor; - } - - /* Find virtual file which contains the declaration of descriptor we're navigating to. */ diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolver.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolver.java index b07ac2bc734..ac6f5a4b546 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolver.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolver.java @@ -57,7 +57,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.*; -import static org.jetbrains.kotlin.resolve.DescriptorUtils.unwrapFakeOverride; import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getClassId; import static org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage.findClassAcrossModuleDependencies; @@ -186,11 +185,6 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent { @Nullable private DeclarationDescriptor findCurrentDescriptorForMember(@NotNull MemberDescriptor originalDescriptor) { - if (originalDescriptor instanceof CallableMemberDescriptor && - ((CallableMemberDescriptor) originalDescriptor).getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { - return findCurrentDescriptorForMember(unwrapFakeOverride((CallableMemberDescriptor) originalDescriptor).getOriginal()); - } - if (!isFromBuiltinModule(originalDescriptor)) return null; DeclarationDescriptor containingDeclaration = findCurrentDescriptor(originalDescriptor.getContainingDeclaration()); @@ -240,17 +234,17 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent { return KotlinBuiltIns.getInstance().getBuiltInsModule() == DescriptorUtils.getContainingModule(originalDescriptor); } - @NotNull - public Collection resolveBuiltInSymbol(@NotNull DeclarationDescriptor declarationDescriptor) { + @Nullable + public PsiElement resolveBuiltInSymbol(@NotNull DeclarationDescriptor declarationDescriptor) { if (moduleDescriptor == null) { - return Collections.emptyList(); + return null; } - DeclarationDescriptor descriptor = findCurrentDescriptor(declarationDescriptor.getOriginal()); + DeclarationDescriptor descriptor = findCurrentDescriptor(declarationDescriptor); if (descriptor != null) { - return DescriptorToSourceUtils.descriptorToDeclarations(descriptor); + return DescriptorToSourceUtils.getSourceFromDescriptor(descriptor); } - return Collections.emptyList(); + return null; } public static boolean isFromBuiltIns(@NotNull PsiElement element) { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinSmartStepIntoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinSmartStepIntoHandler.kt index 5d945c9d510..302d15a4c25 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinSmartStepIntoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/KotlinSmartStepIntoHandler.kt @@ -34,12 +34,12 @@ import com.intellij.debugger.engine.BasicStepMethodFilter import com.intellij.debugger.engine.DebugProcessImpl import com.sun.jdi.Location import com.intellij.psi.PsiMethod -import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import com.intellij.psi.PsiDocumentManager import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.codeInsight.* public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { @@ -132,7 +132,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { if (getterDescriptor != null && !getterDescriptor.isDefault()) { val delegatedResolvedCall = bindingContext[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor] if (delegatedResolvedCall == null) { - val getter = DescriptorToSourceUtils.callableDescriptorToDeclaration(getterDescriptor) + val getter = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), getterDescriptor) if (getter is JetPropertyAccessor && (getter.getBodyExpression() != null || getter.getEqualsToken() != null)) { val psiMethod = LightClassUtil.getLightClassAccessorMethod(getter) if (psiMethod != null) { @@ -143,7 +143,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { else { val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor() if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) { - val function = DescriptorToSourceUtils.callableDescriptorToDeclaration(delegatedPropertyGetterDescriptor) + val function = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), delegatedPropertyGetterDescriptor) if (function is JetNamedFunction) { val psiMethod = LightClassUtil.getLightClassMethod(function) if (psiMethod != null) { @@ -164,7 +164,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() { val descriptor = resolvedCall.getResultingDescriptor() if (descriptor is CallableMemberDescriptor) { - val function = DescriptorToSourceUtils.callableDescriptorToDeclaration(descriptor) + // TODO doesn't work for libraries + val function = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), descriptor) if (function is JetNamedFunction) { val psiMethod = LightClassUtil.getLightClassMethod(function) if (psiMethod != null) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java index c7a6d313007..ec57b1bb499 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters2; import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.idea.JetBundle; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; +import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil; import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester; import org.jetbrains.kotlin.idea.refactoring.JetNameValidator; import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo; @@ -44,6 +45,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.checker.JetTypeChecker; +import java.util.Collection; import java.util.List; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED; @@ -80,7 +82,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction declarations = DescriptorToSourceUtils.callableDescriptorToDeclarations(functionDescriptor); + Collection declarations = DescriptorToDeclarationUtil.INSTANCE$.resolveToPsiElements(project, functionDescriptor); if (declarations.isEmpty()) { return false; } diff --git a/idea/testData/quickfix/changeSignature/beforeNotEditable.kt b/idea/testData/quickfix/changeSignature/beforeNotEditable.kt new file mode 100644 index 00000000000..b371f1c2599 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeNotEditable.kt @@ -0,0 +1,12 @@ +// "class org.jetbrains.kotlin.idea.quickfix.RemoveFunctionParametersFix" "false" +//ERROR: No value passed for parameter other + +trait StringComparable { + public fun compareTo(other: String): Int = 0 +} + +class X: Comparable, StringComparable + +fun main(args: Array) { + X().compareTo() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 9baf16da3f0..c7dc7fc6f65 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -546,6 +546,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeNotEditable.kt") + public void testNotEditable() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/beforeNotEditable.kt"); + doTest(fileName); + } + @TestMetadata("beforeRemoveConstructorParameter.kt") public void testRemoveConstructorParameter() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/changeSignature/beforeRemoveConstructorParameter.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java b/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java index 6d214f38a13..ca6f0be6415 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies; import org.jetbrains.kotlin.idea.PluginTestCaseBase; +import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde; import org.jetbrains.kotlin.test.JetTestUtils; import java.util.ArrayList; @@ -86,9 +87,8 @@ public class BuiltInsReferenceResolverTest extends ResolveTestCase { } public void testAllReferencesResolved() { - BuiltInsReferenceResolver referenceResolver = getProject().getComponent(BuiltInsReferenceResolver.class); for (DeclarationDescriptor descriptor : getAllStandardDescriptors()) { - assertNotNull("Can't resolve " + descriptor, referenceResolver.resolveBuiltInSymbol(descriptor)); + assertNotNull("Can't resolve " + descriptor, DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(getProject(), descriptor)); } }