Convert Property to Function Intention: Search occurrences using progress dialog
#KT-14569 Fixed
This commit is contained in:
@@ -216,6 +216,14 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
|||||||
+ [`KT-12389`](https://youtrack.jetbrains.com/issue/KT-12389) Do not exit from REPL when toString() of user class throws an exception
|
+ [`KT-12389`](https://youtrack.jetbrains.com/issue/KT-12389) Do not exit from REPL when toString() of user class throws an exception
|
||||||
+ [`KT-12129`](https://youtrack.jetbrains.com/issue/KT-12129) Fixed link on api reference page in KDoc
|
+ [`KT-12129`](https://youtrack.jetbrains.com/issue/KT-12129) Fixed link on api reference page in KDoc
|
||||||
|
|
||||||
|
## 1.0.6
|
||||||
|
|
||||||
|
### IDE
|
||||||
|
|
||||||
|
#### Intention actions, inspections and quickfixes
|
||||||
|
|
||||||
|
- [`KT-14569`](https://youtrack.jetbrains.com/issue/KT-14569) Convert Property to Function Intention: Search occurrences using progress dialog
|
||||||
|
|
||||||
## 1.0.5
|
## 1.0.5
|
||||||
|
|
||||||
### IDE
|
### IDE
|
||||||
|
|||||||
+61
-58
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.progress.ProgressManager
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
@@ -28,11 +29,7 @@ import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||||
import org.jetbrains.kotlin.idea.refactoring.checkConflictsInteractively
|
import org.jetbrains.kotlin.idea.refactoring.*
|
||||||
import org.jetbrains.kotlin.idea.refactoring.reportDeclarationConflict
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.CallableRefactoring
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.getAffectedCallables
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.getContainingScope
|
|
||||||
import org.jetbrains.kotlin.idea.references.KtReference
|
import org.jetbrains.kotlin.idea.references.KtReference
|
||||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
@@ -93,66 +90,72 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
val kotlinRefsToReplaceWithCall = ArrayList<KtSimpleNameExpression>()
|
val kotlinRefsToReplaceWithCall = ArrayList<KtSimpleNameExpression>()
|
||||||
val refsToRename = ArrayList<PsiReference>()
|
val refsToRename = ArrayList<PsiReference>()
|
||||||
val javaRefsToReplaceWithCall = ArrayList<PsiReferenceExpression>()
|
val javaRefsToReplaceWithCall = ArrayList<PsiReferenceExpression>()
|
||||||
for (callable in callables) {
|
|
||||||
if (callable !is PsiNamedElement) continue
|
|
||||||
|
|
||||||
if (!checkModifiable(callable)) {
|
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
|
||||||
val renderedCallable = RefactoringUIUtil.getDescription(callable, true).capitalize()
|
val progressStep = 1.0/callables.size
|
||||||
conflicts.putValue(callable, "Can't modify $renderedCallable")
|
for ((i, callable) in callables.withIndex()) {
|
||||||
}
|
ProgressManager.getInstance().progressIndicator.fraction = (i + 1)*progressStep
|
||||||
|
|
||||||
if (callable is KtProperty) {
|
if (callable !is PsiNamedElement) continue
|
||||||
callableDescriptor.getContainingScope()
|
|
||||||
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
|
|
||||||
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
|
||||||
}
|
|
||||||
else if (callable is PsiMethod) {
|
|
||||||
callable.containingClass
|
|
||||||
?.findMethodsByName(propertyName, true)
|
|
||||||
// as is necessary here: see KT-10386
|
|
||||||
?.firstOrNull { it.parameterList.parametersCount == 0 && !callables.contains(it.namedUnwrappedElement as PsiElement?) }
|
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
|
||||||
}
|
|
||||||
|
|
||||||
val usages = ReferencesSearch.search(callable)
|
if (!checkModifiable(callable)) {
|
||||||
for (usage in usages) {
|
val renderedCallable = RefactoringUIUtil.getDescription(callable, true).capitalize()
|
||||||
if (usage is KtReference) {
|
conflicts.putValue(callable, "Can't modify $renderedCallable")
|
||||||
if (usage is KtSimpleNameReference) {
|
|
||||||
val expression = usage.expression
|
|
||||||
if (expression.getCall(expression.analyze(BodyResolveMode.PARTIAL)) != null
|
|
||||||
&& expression.getStrictParentOfType<KtCallableReferenceExpression>() == null) {
|
|
||||||
kotlinRefsToReplaceWithCall.add(expression)
|
|
||||||
}
|
|
||||||
else if (nameChanged) {
|
|
||||||
refsToRename.add(usage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val refElement = usage.element
|
|
||||||
conflicts.putValue(
|
|
||||||
refElement,
|
|
||||||
"Unrecognized reference will be skipped: " + StringUtil.htmlEmphasize(refElement.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val refElement = usage.element
|
if (callable is KtProperty) {
|
||||||
|
callableDescriptor.getContainingScope()
|
||||||
if (refElement.text.endsWith(getterName)) continue
|
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
|
||||||
|
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||||
if (usage is PsiJavaReference) {
|
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
||||||
if (usage.resolve() is PsiField && usage is PsiReferenceExpression) {
|
}
|
||||||
javaRefsToReplaceWithCall.add(usage)
|
else if (callable is PsiMethod) {
|
||||||
}
|
callable.containingClass
|
||||||
continue
|
?.findMethodsByName(propertyName, true)
|
||||||
|
// as is necessary here: see KT-10386
|
||||||
|
?.firstOrNull { it.parameterList.parametersCount == 0 && !callables.contains(it.namedUnwrappedElement as PsiElement?) }
|
||||||
|
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
conflicts.putValue(
|
val usages = ReferencesSearch.search(callable)
|
||||||
refElement,
|
for (usage in usages) {
|
||||||
"Can't replace foreign reference with call expression: " + StringUtil.htmlEmphasize(refElement.text)
|
if (usage is KtReference) {
|
||||||
)
|
if (usage is KtSimpleNameReference) {
|
||||||
|
val expression = usage.expression
|
||||||
|
if (expression.getCall(expression.analyze(BodyResolveMode.PARTIAL)) != null
|
||||||
|
&& expression.getStrictParentOfType<KtCallableReferenceExpression>() == null) {
|
||||||
|
kotlinRefsToReplaceWithCall.add(expression)
|
||||||
|
}
|
||||||
|
else if (nameChanged) {
|
||||||
|
refsToRename.add(usage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val refElement = usage.element
|
||||||
|
conflicts.putValue(
|
||||||
|
refElement,
|
||||||
|
"Unrecognized reference will be skipped: " + StringUtil.htmlEmphasize(refElement.text)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val refElement = usage.element
|
||||||
|
|
||||||
|
if (refElement.text.endsWith(getterName)) continue
|
||||||
|
|
||||||
|
if (usage is PsiJavaReference) {
|
||||||
|
if (usage.resolve() is PsiField && usage is PsiReferenceExpression) {
|
||||||
|
javaRefsToReplaceWithCall.add(usage)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
conflicts.putValue(
|
||||||
|
refElement,
|
||||||
|
"Can't replace foreign reference with call expression: " + StringUtil.htmlEmphasize(refElement.text)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user