provide element type name for multi-declaration entries; enable in-place rename for those; show local properties as "variable"
#KT-7627 Fixed
This commit is contained in:
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.psi;
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.search.LocalSearchScope;
|
||||||
|
import com.intellij.psi.search.SearchScope;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
import com.intellij.psi.tree.TokenSet;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -134,4 +136,13 @@ public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed impl
|
|||||||
public FqName getFqName() {
|
public FqName getFqName() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public SearchScope getUseScope() {
|
||||||
|
JetElement enclosingBlock = JetPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
|
||||||
|
if (enclosingBlock != null) return new LocalSearchScope(enclosingBlock);
|
||||||
|
|
||||||
|
return super.getUseScope();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -36,7 +36,8 @@ public class JetFindUsagesProvider : FindUsagesProvider {
|
|||||||
is JetNamedFunction -> "function"
|
is JetNamedFunction -> "function"
|
||||||
is JetClass -> "class"
|
is JetClass -> "class"
|
||||||
is JetParameter -> "parameter"
|
is JetParameter -> "parameter"
|
||||||
is JetProperty -> "property"
|
is JetProperty -> if (element.isLocal()) "variable" else "property"
|
||||||
|
is JetMultiDeclarationEntry -> "variable"
|
||||||
is JetTypeParameter -> "type parameter"
|
is JetTypeParameter -> "type parameter"
|
||||||
is JetSecondaryConstructor -> "constructor"
|
is JetSecondaryConstructor -> "constructor"
|
||||||
is JetObjectDeclaration -> "object"
|
is JetObjectDeclaration -> "object"
|
||||||
|
|||||||
@@ -40,9 +40,10 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
|||||||
is JetObjectDeclaration -> "object"
|
is JetObjectDeclaration -> "object"
|
||||||
is JetNamedFunction -> "function"
|
is JetNamedFunction -> "function"
|
||||||
is JetSecondaryConstructor -> "constructor"
|
is JetSecondaryConstructor -> "constructor"
|
||||||
is JetProperty -> "property"
|
is JetProperty -> if (targetElement.isLocal()) "variable" else "property"
|
||||||
is JetTypeParameter -> "type parameter"
|
is JetTypeParameter -> "type parameter"
|
||||||
is JetParameter -> "parameter"
|
is JetParameter -> "parameter"
|
||||||
|
is JetMultiDeclarationEntry -> "variable"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-37
@@ -30,55 +30,44 @@ import org.jetbrains.kotlin.idea.refactoring.safeDelete.*
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
|
public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
|
||||||
override fun isSafeDeleteAvailable(element: PsiElement): Boolean {
|
override fun isSafeDeleteAvailable(element: PsiElement) = element.canDeleteElement()
|
||||||
return element.canDeleteElement()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getIntroduceVariableHandler(): RefactoringActionHandler? {
|
override fun getIntroduceVariableHandler() = KotlinIntroduceVariableHandler()
|
||||||
return KotlinIntroduceVariableHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getIntroduceParameterHandler(): RefactoringActionHandler? {
|
override fun getIntroduceParameterHandler() = KotlinIntroduceParameterHandler()
|
||||||
return KotlinIntroduceParameterHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getIntroduceLambdaParameterHandler(): RefactoringActionHandler {
|
public fun getIntroduceLambdaParameterHandler(): RefactoringActionHandler = KotlinIntroduceLambdaParameterHandler()
|
||||||
return KotlinIntroduceLambdaParameterHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getIntroducePropertyHandler(): RefactoringActionHandler {
|
public fun getIntroducePropertyHandler(): RefactoringActionHandler = KotlinIntroducePropertyHandler()
|
||||||
return KotlinIntroducePropertyHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getExtractFunctionHandler(): RefactoringActionHandler {
|
public fun getExtractFunctionHandler(): RefactoringActionHandler =
|
||||||
return ExtractKotlinFunctionHandler()
|
ExtractKotlinFunctionHandler()
|
||||||
}
|
|
||||||
|
|
||||||
public fun getExtractFunctionToScopeHandler(): RefactoringActionHandler {
|
public fun getExtractFunctionToScopeHandler(): RefactoringActionHandler =
|
||||||
return ExtractKotlinFunctionHandler(true, ExtractKotlinFunctionHandler.InteractiveExtractionHelper)
|
ExtractKotlinFunctionHandler(true, ExtractKotlinFunctionHandler.InteractiveExtractionHelper)
|
||||||
}
|
|
||||||
|
|
||||||
override fun isInplaceRenameAvailable(element: PsiElement, context: PsiElement?): Boolean {
|
override fun isInplaceRenameAvailable(element: PsiElement, context: PsiElement?): Boolean {
|
||||||
if (element is JetProperty) {
|
when (element) {
|
||||||
if (element.isLocal()) return true
|
is JetProperty -> {
|
||||||
}
|
if (element.isLocal()) return true
|
||||||
else if (element is JetFunction) {
|
|
||||||
if (element.isLocal()) return true
|
|
||||||
}
|
|
||||||
else if (element is JetParameter) {
|
|
||||||
val parent = element.getParent()
|
|
||||||
if (parent is JetForExpression) {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
if (parent is JetParameterList) {
|
is JetMultiDeclarationEntry -> return true
|
||||||
val grandparent = parent.getParent()
|
is JetFunction -> {
|
||||||
return grandparent is JetCatchClause || grandparent is JetFunctionLiteral
|
if (element.isLocal()) return true
|
||||||
|
}
|
||||||
|
is JetParameter -> {
|
||||||
|
val parent = element.getParent()
|
||||||
|
if (parent is JetForExpression) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (parent is JetParameterList) {
|
||||||
|
val grandparent = parent.getParent()
|
||||||
|
return grandparent is JetCatchClause || grandparent is JetFunctionLiteral
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChangeSignatureHandler(): ChangeSignatureHandler? {
|
override fun getChangeSignatureHandler() = JetChangeSignatureHandler()
|
||||||
return JetChangeSignatureHandler()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Class a.Test uses package-private class a.Foo
|
Class a.Test uses package-private class a.Foo
|
||||||
Class a.Test uses package-private function a.foo
|
Class a.Test uses package-private function a.foo
|
||||||
Package-private class a.Test will no longer be accessible from method J.bar()
|
Package-private class a.Test will no longer be accessible from method J.bar()
|
||||||
Package-private class a.Test will no longer be accessible from property a.bar.t
|
Package-private class a.Test will no longer be accessible from variable a.bar.t
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Object a.Test uses package-private class a.Foo
|
Object a.Test uses package-private class a.Foo
|
||||||
Object a.Test uses package-private function a.foo
|
Object a.Test uses package-private function a.foo
|
||||||
Package-private object a.Test will no longer be accessible from method J.bar()
|
Package-private object a.Test will no longer be accessible from method J.bar()
|
||||||
Package-private object a.Test will no longer be accessible from property a.bar.t
|
Package-private object a.Test will no longer be accessible from variable a.bar.t
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun xyzzy(x: Pair<Int, String>) {
|
||||||
|
val (bar, ba<caret>z) = x
|
||||||
|
println(baz)
|
||||||
|
println(baz.length())
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun xyzzy(x: Pair<Int, String>) {
|
||||||
|
val (bar, foo) = x
|
||||||
|
println(foo)
|
||||||
|
println(foo.length())
|
||||||
|
}
|
||||||
@@ -128,6 +128,10 @@ public class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
|
|||||||
doTestInplaceRename("foo")
|
doTestInplaceRename("foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun testMultiDeclaration() {
|
||||||
|
doTestInplaceRename("foo")
|
||||||
|
}
|
||||||
|
|
||||||
private fun doTestInplaceRename(newName: String?) {
|
private fun doTestInplaceRename(newName: String?) {
|
||||||
configureByFile(getTestName(false) + ".kt")
|
configureByFile(getTestName(false) + ".kt")
|
||||||
val element = TargetElementUtilBase.findTargetElement(
|
val element = TargetElementUtilBase.findTargetElement(
|
||||||
|
|||||||
Reference in New Issue
Block a user