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 3203b0c4ef0..834750e0df8 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 @@ -23,10 +23,7 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.ClassDescriptor; -import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor; -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; -import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; +import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.idea.decompiler.DecompilerPackage; import org.jetbrains.kotlin.idea.decompiler.KotlinClsFileBase; import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope; @@ -51,7 +48,8 @@ public final class DecompiledNavigationUtils { @NotNull Project project, @NotNull DeclarationDescriptor referencedDescriptor ) { - if (DescriptorUtils.isLocal(referencedDescriptor)) return null; + if (isLocal(referencedDescriptor)) return null; + VirtualFile virtualFile = findVirtualFileContainingDescriptor(project, referencedDescriptor); if (virtualFile == null || @@ -66,6 +64,15 @@ public final class DecompiledNavigationUtils { return ((KotlinClsFileBase) psiFile).getDeclarationForDescriptor(referencedDescriptor); } + private static boolean isLocal(DeclarationDescriptor descriptor) { + if (descriptor instanceof ParameterDescriptor) { + return isLocal(descriptor.getContainingDeclaration()); + } + else { + return DescriptorUtils.isLocal(descriptor); + } + } + /* Find virtual file which contains the declaration of descriptor we're navigating to. */ diff --git a/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt b/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt new file mode 100644 index 00000000000..6b79b5a0d55 --- /dev/null +++ b/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt @@ -0,0 +1,5 @@ +// "Replace with 'prefix + joinTo(StringBuilder(), separator, "", postfix, limit, truncated, transform)'" "true" + +fun foo() { + listOf(1, 2, 3).joinToString(limit = 10) +} \ No newline at end of file diff --git a/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt.after b/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt.after new file mode 100644 index 00000000000..4700d1d235a --- /dev/null +++ b/idea/testData/quickfix.special/deprecatedSymbolUsage/defaultParameterValuesFromLibrary.kt.after @@ -0,0 +1,5 @@ +// "Replace with 'prefix + joinTo(StringBuilder(), separator, "", postfix, limit, truncated, transform)'" "true" + +fun foo() { + "" + listOf(1, 2, 3).joinTo(StringBuilder(), ", ", "", limit = 10) +} \ No newline at end of file diff --git a/idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt b/idea/testData/quickfix.special/deprecatedSymbolUsage/memberInCompiledClass.kt similarity index 100% rename from idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt rename to idea/testData/quickfix.special/deprecatedSymbolUsage/memberInCompiledClass.kt diff --git a/idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt.after b/idea/testData/quickfix.special/deprecatedSymbolUsage/memberInCompiledClass.kt.after similarity index 100% rename from idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt.after rename to idea/testData/quickfix.special/deprecatedSymbolUsage/memberInCompiledClass.kt.after diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedInCompiledClassTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt similarity index 62% rename from idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedInCompiledClassTest.kt rename to idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt index d6272ee856f..bc1361e6112 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedInCompiledClassTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt @@ -16,12 +16,16 @@ package org.jetbrains.kotlin.idea.quickfix; -import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.openapi.projectRoots.JavaSdk +import com.intellij.openapi.projectRoots.Sdk +import com.intellij.testFramework.LightPlatformTestCase import com.intellij.testFramework.TestDataPath +import org.apache.commons.lang.SystemUtils +import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources import org.jetbrains.kotlin.idea.util.application.executeWriteCommand -import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.JetSimpleNameExpression import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.test.JUnit3RunnerWithInners @@ -33,20 +37,29 @@ import org.junit.runner.RunWith TestMetadata("idea/testData/quickfix.special") TestDataPath("\$PROJECT_ROOT") RunWith(JUnit3RunnerWithInners::class) -public class QuickFixSpecialTest : JetLightCodeInsightFixtureTestCase() { +public class DeprecatedSymbolUsageFixSpecialTest : JetLightCodeInsightFixtureTestCase() { override fun getTestDataPath() = JetTestUtils.getHomeDirectory() - override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE + override fun getProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE - TestMetadata("deprecatedMemberInCompiledClass.kt") - public fun testDeprecatedMemberInCompiledClass() { - val testPath = JetTestUtils.navigationMetadata("idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt") + private val TEST_DATA_DIR = "idea/testData/quickfix.special/deprecatedSymbolUsage" + + public fun testMemberInCompiledClass() { + doTest("matches(input)") + } + + public fun testDefaultParameterValuesFromLibrary() { + doTest("""prefix + joinTo(StringBuilder(), separator, "", postfix, limit, truncated, transform)""") + } + + private fun doTest(pattern: String) { + val testPath = JetTestUtils.navigationMetadata(TEST_DATA_DIR + "/" + getTestName(true) + ".kt") myFixture.configureByFile(testPath) - val offset = getEditor().getCaretModel().getOffset() + val offset = getEditor().caretModel.offset val element = getFile().findElementAt(offset) val nameExpression = element!!.parents.firstIsInstance() getProject().executeWriteCommand("") { - DeprecatedSymbolUsageFix(nameExpression, ReplaceWith("matches(input)")).invoke(getProject(), getEditor(), getFile()) + DeprecatedSymbolUsageFix(nameExpression, ReplaceWith(pattern)).invoke(getProject(), getEditor(), getFile()) } myFixture.checkResultByFile("$testPath.after")