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:
Dmitry Jemerov
2015-04-29 19:40:31 +02:00
parent 0582d1947d
commit b1c4a5670a
9 changed files with 57 additions and 41 deletions
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -134,4 +136,13 @@ public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed impl
public FqName getFqName() {
return null;
}
@NotNull
@Override
public SearchScope getUseScope() {
JetElement enclosingBlock = JetPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
if (enclosingBlock != null) return new LocalSearchScope(enclosingBlock);
return super.getUseScope();
}
}
@@ -36,7 +36,8 @@ public class JetFindUsagesProvider : FindUsagesProvider {
is JetNamedFunction -> "function"
is JetClass -> "class"
is JetParameter -> "parameter"
is JetProperty -> "property"
is JetProperty -> if (element.isLocal()) "variable" else "property"
is JetMultiDeclarationEntry -> "variable"
is JetTypeParameter -> "type parameter"
is JetSecondaryConstructor -> "constructor"
is JetObjectDeclaration -> "object"
@@ -40,9 +40,10 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
is JetObjectDeclaration -> "object"
is JetNamedFunction -> "function"
is JetSecondaryConstructor -> "constructor"
is JetProperty -> "property"
is JetProperty -> if (targetElement.isLocal()) "variable" else "property"
is JetTypeParameter -> "type parameter"
is JetParameter -> "parameter"
is JetMultiDeclarationEntry -> "variable"
else -> null
}
@@ -30,55 +30,44 @@ import org.jetbrains.kotlin.idea.refactoring.safeDelete.*
import org.jetbrains.kotlin.psi.*
public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
override fun isSafeDeleteAvailable(element: PsiElement): Boolean {
return element.canDeleteElement()
}
override fun isSafeDeleteAvailable(element: PsiElement) = element.canDeleteElement()
override fun getIntroduceVariableHandler(): RefactoringActionHandler? {
return KotlinIntroduceVariableHandler()
}
override fun getIntroduceVariableHandler() = KotlinIntroduceVariableHandler()
override fun getIntroduceParameterHandler(): RefactoringActionHandler? {
return KotlinIntroduceParameterHandler()
}
override fun getIntroduceParameterHandler() = KotlinIntroduceParameterHandler()
public fun getIntroduceLambdaParameterHandler(): RefactoringActionHandler {
return KotlinIntroduceLambdaParameterHandler()
}
public fun getIntroduceLambdaParameterHandler(): RefactoringActionHandler = KotlinIntroduceLambdaParameterHandler()
public fun getIntroducePropertyHandler(): RefactoringActionHandler {
return KotlinIntroducePropertyHandler()
}
public fun getIntroducePropertyHandler(): RefactoringActionHandler = KotlinIntroducePropertyHandler()
public fun getExtractFunctionHandler(): RefactoringActionHandler {
return ExtractKotlinFunctionHandler()
}
public fun getExtractFunctionHandler(): RefactoringActionHandler =
ExtractKotlinFunctionHandler()
public fun getExtractFunctionToScopeHandler(): RefactoringActionHandler {
return ExtractKotlinFunctionHandler(true, ExtractKotlinFunctionHandler.InteractiveExtractionHelper)
}
public fun getExtractFunctionToScopeHandler(): RefactoringActionHandler =
ExtractKotlinFunctionHandler(true, ExtractKotlinFunctionHandler.InteractiveExtractionHelper)
override fun isInplaceRenameAvailable(element: PsiElement, context: PsiElement?): Boolean {
if (element 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
when (element) {
is JetProperty -> {
if (element.isLocal()) return true
}
if (parent is JetParameterList) {
val grandparent = parent.getParent()
return grandparent is JetCatchClause || grandparent is JetFunctionLiteral
is JetMultiDeclarationEntry -> return true
is JetFunction -> {
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
}
override fun getChangeSignatureHandler(): ChangeSignatureHandler? {
return JetChangeSignatureHandler()
}
override fun getChangeSignatureHandler() = JetChangeSignatureHandler()
}
@@ -1,4 +1,4 @@
Class a.Test uses package-private class 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 property a.bar.t
Package-private class a.Test will no longer be accessible from variable a.bar.t
@@ -1,4 +1,4 @@
Object a.Test uses package-private class 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 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")
}
public fun testMultiDeclaration() {
doTestInplaceRename("foo")
}
private fun doTestInplaceRename(newName: String?) {
configureByFile(getTestName(false) + ".kt")
val element = TargetElementUtilBase.findTargetElement(