Fixed deprecated symbol usage fix for functions with optional parameters from libraries
#KT-8525 Fixed
This commit is contained in:
+12
-5
@@ -23,10 +23,7 @@ import com.intellij.psi.PsiManager;
|
|||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
|
||||||
import org.jetbrains.kotlin.idea.decompiler.DecompilerPackage;
|
import org.jetbrains.kotlin.idea.decompiler.DecompilerPackage;
|
||||||
import org.jetbrains.kotlin.idea.decompiler.KotlinClsFileBase;
|
import org.jetbrains.kotlin.idea.decompiler.KotlinClsFileBase;
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope;
|
import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope;
|
||||||
@@ -51,7 +48,8 @@ public final class DecompiledNavigationUtils {
|
|||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@NotNull DeclarationDescriptor referencedDescriptor
|
@NotNull DeclarationDescriptor referencedDescriptor
|
||||||
) {
|
) {
|
||||||
if (DescriptorUtils.isLocal(referencedDescriptor)) return null;
|
if (isLocal(referencedDescriptor)) return null;
|
||||||
|
|
||||||
VirtualFile virtualFile = findVirtualFileContainingDescriptor(project, referencedDescriptor);
|
VirtualFile virtualFile = findVirtualFileContainingDescriptor(project, referencedDescriptor);
|
||||||
|
|
||||||
if (virtualFile == null ||
|
if (virtualFile == null ||
|
||||||
@@ -66,6 +64,15 @@ public final class DecompiledNavigationUtils {
|
|||||||
return ((KotlinClsFileBase) psiFile).getDeclarationForDescriptor(referencedDescriptor);
|
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.
|
Find virtual file which contains the declaration of descriptor we're navigating to.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Replace with 'prefix + joinTo(StringBuilder(), separator, "", postfix, limit, truncated, transform)'" "true"
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
listOf(1, 2, 3).<caret>joinToString(limit = 10)
|
||||||
|
}
|
||||||
Vendored
+5
@@ -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)
|
||||||
|
}
|
||||||
+22
-9
@@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix;
|
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 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.JetLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor
|
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.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
|
||||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||||
@@ -33,20 +37,29 @@ import org.junit.runner.RunWith
|
|||||||
TestMetadata("idea/testData/quickfix.special")
|
TestMetadata("idea/testData/quickfix.special")
|
||||||
TestDataPath("\$PROJECT_ROOT")
|
TestDataPath("\$PROJECT_ROOT")
|
||||||
RunWith(JUnit3RunnerWithInners::class)
|
RunWith(JUnit3RunnerWithInners::class)
|
||||||
public class QuickFixSpecialTest : JetLightCodeInsightFixtureTestCase() {
|
public class DeprecatedSymbolUsageFixSpecialTest : JetLightCodeInsightFixtureTestCase() {
|
||||||
override fun getTestDataPath() = JetTestUtils.getHomeDirectory()
|
override fun getTestDataPath() = JetTestUtils.getHomeDirectory()
|
||||||
override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE
|
||||||
|
|
||||||
TestMetadata("deprecatedMemberInCompiledClass.kt")
|
private val TEST_DATA_DIR = "idea/testData/quickfix.special/deprecatedSymbolUsage"
|
||||||
public fun testDeprecatedMemberInCompiledClass() {
|
|
||||||
val testPath = JetTestUtils.navigationMetadata("idea/testData/quickfix.special/deprecatedMemberInCompiledClass.kt")
|
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)
|
myFixture.configureByFile(testPath)
|
||||||
|
|
||||||
val offset = getEditor().getCaretModel().getOffset()
|
val offset = getEditor().caretModel.offset
|
||||||
val element = getFile().findElementAt(offset)
|
val element = getFile().findElementAt(offset)
|
||||||
val nameExpression = element!!.parents.firstIsInstance<JetSimpleNameExpression>()
|
val nameExpression = element!!.parents.firstIsInstance<JetSimpleNameExpression>()
|
||||||
getProject().executeWriteCommand("") {
|
getProject().executeWriteCommand("") {
|
||||||
DeprecatedSymbolUsageFix(nameExpression, ReplaceWith("matches(input)")).invoke(getProject(), getEditor(), getFile())
|
DeprecatedSymbolUsageFix(nameExpression, ReplaceWith(pattern)).invoke(getProject(), getEditor(), getFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
myFixture.checkResultByFile("$testPath.after")
|
myFixture.checkResultByFile("$testPath.after")
|
||||||
Reference in New Issue
Block a user