Enable replace for deprecated alias in whole project (KT-14929)

#KT-14929 Fixed
This commit is contained in:
Nikolay Krasko
2017-07-25 18:05:58 +03:00
parent 5df2698f77
commit 732d1129ab
8 changed files with 65 additions and 2 deletions
@@ -21,10 +21,10 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy
import org.jetbrains.kotlin.idea.codeInliner.replaceUsagesInWholeProject
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.DescriptorRenderer
@@ -57,6 +57,7 @@ class DeprecatedSymbolUsageInWholeProjectFix(
return when (referenceTarget) {
is KtNamedFunction -> referenceTarget
is KtProperty -> referenceTarget
is KtTypeAlias -> referenceTarget
is KtConstructor<*> -> referenceTarget.getContainingClassOrObject() //TODO: constructor can be deprecated itself
else -> null
}
@@ -1,5 +1,6 @@
// "Replace with 'NewClass'" "false"
// ACTION: Introduce local variable
// ACTION: Replace usages of 'typealias Old = OldClass' in whole project
// ACTION: Replace with 'New'
@@ -1,6 +1,7 @@
// "Replace with 'New'" "false"
// ACTION: Convert to block body
// ACTION: Introduce local variable
// ACTION: Replace usages of '<init>(): Old /* = OldClass */' in whole project
// ACTION: Replace with 'NewClass(12)'
@Deprecated("Use NewClass", replaceWith = ReplaceWith("NewClass"))
@@ -0,0 +1,9 @@
package dependency.d
class A<T>
@Deprecated("", ReplaceWith("A<Int>", "dependency.d.A"))
typealias OldAlias = A<Int>
val usage: A<Int>? = null
@@ -0,0 +1,9 @@
// "Replace usages of 'typealias OldAlias = A<Int>' in whole project" "true"
package test
import dependency.d.A
fun foo(a: <caret>A<Int>): A<Int>? = null
val usage: A<Int> = A()
@@ -0,0 +1,9 @@
package dependency.d
class A<T>
@Deprecated("", ReplaceWith("A<Int>", "dependency.d.A"))
typealias OldAlias = A<Int>
val usage: OldAlias? = null
@@ -0,0 +1,9 @@
// "Replace usages of 'typealias OldAlias = A<Int>' in whole project" "true"
package test
import dependency.d.OldAlias
fun foo(a: <caret>OldAlias): OldAlias? = null
val usage: OldAlias = OldAlias()
@@ -1601,6 +1601,30 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
}
}
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class TypeAliases extends AbstractQuickFixMultiFileTest {
public void testAllFilesPresentInTypeAliases() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
}
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/wholeProject")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class WholeProject extends AbstractQuickFixMultiFileTest {
public void testAllFilesPresentInWholeProject() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/wholeProject"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
}
@TestMetadata("typealias.before.Main.kt")
public void testTypealias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/typeAliases/wholeProject/typealias.before.Main.kt");
doTestWithExtraFile(fileName);
}
}
}
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/typeArguments")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)