Reformat: KotlinInlineCallableProcessor
This commit is contained in:
+33
-35
@@ -29,19 +29,18 @@ import com.intellij.usageView.UsageViewDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy
|
import org.jetbrains.kotlin.idea.codeInliner.UsageReplacementStrategy
|
||||||
import org.jetbrains.kotlin.idea.codeInliner.replaceUsages
|
import org.jetbrains.kotlin.idea.codeInliner.replaceUsages
|
||||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
|
||||||
class KotlinInlineCallableProcessor(
|
class KotlinInlineCallableProcessor(
|
||||||
project: Project,
|
project: Project,
|
||||||
private val replacementStrategy: UsageReplacementStrategy,
|
private val replacementStrategy: UsageReplacementStrategy,
|
||||||
private val declaration: KtCallableDeclaration,
|
private val declaration: KtCallableDeclaration,
|
||||||
private val reference: KtSimpleNameReference?,
|
private val reference: KtSimpleNameReference?,
|
||||||
private val inlineThisOnly: Boolean,
|
private val inlineThisOnly: Boolean,
|
||||||
private val deleteAfter: Boolean,
|
private val deleteAfter: Boolean,
|
||||||
private val statementToDelete: KtBinaryExpression? = null
|
private val statementToDelete: KtBinaryExpression? = null
|
||||||
) : BaseRefactoringProcessor(project) {
|
) : BaseRefactoringProcessor(project) {
|
||||||
|
|
||||||
private val kind = when (declaration) {
|
private val kind = when (declaration) {
|
||||||
@@ -64,34 +63,33 @@ class KotlinInlineCallableProcessor(
|
|||||||
override fun performRefactoring(usages: Array<out UsageInfo>) {
|
override fun performRefactoring(usages: Array<out UsageInfo>) {
|
||||||
val simpleNameUsages = usages.mapNotNull { it.element as? KtSimpleNameExpression }
|
val simpleNameUsages = usages.mapNotNull { it.element as? KtSimpleNameExpression }
|
||||||
replacementStrategy.replaceUsages(
|
replacementStrategy.replaceUsages(
|
||||||
simpleNameUsages,
|
simpleNameUsages,
|
||||||
declaration,
|
declaration,
|
||||||
myProject,
|
myProject,
|
||||||
commandName,
|
commandName,
|
||||||
postAction = {
|
postAction = {
|
||||||
if (deleteAfter) {
|
if (deleteAfter) {
|
||||||
if (usages.size == simpleNameUsages.size) {
|
if (usages.size == simpleNameUsages.size) {
|
||||||
val containingClass = declaration.containingClassOrObject
|
val containingClass = declaration.containingClassOrObject
|
||||||
if (containingClass is KtObjectDeclaration
|
if (containingClass is KtObjectDeclaration
|
||||||
&& containingClass.isCompanion()
|
&& containingClass.isCompanion()
|
||||||
&& containingClass.declarations.size == 1) {
|
&& containingClass.declarations.size == 1) {
|
||||||
containingClass.delete()
|
containingClass.delete()
|
||||||
} else {
|
} else {
|
||||||
declaration.delete()
|
declaration.delete()
|
||||||
}
|
|
||||||
statementToDelete?.delete()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
CommonRefactoringUtil.showErrorHint(
|
|
||||||
declaration.project,
|
|
||||||
null,
|
|
||||||
"Cannot inline ${usages.size - simpleNameUsages.size}/${usages.size} usages",
|
|
||||||
"Inline $kind",
|
|
||||||
null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
statementToDelete?.delete()
|
||||||
|
} else {
|
||||||
|
CommonRefactoringUtil.showErrorHint(
|
||||||
|
declaration.project,
|
||||||
|
null,
|
||||||
|
"Cannot inline ${usages.size - simpleNameUsages.size}/${usages.size} usages",
|
||||||
|
"Inline $kind",
|
||||||
|
null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +98,10 @@ class KotlinInlineCallableProcessor(
|
|||||||
override fun createUsageViewDescriptor(usages: Array<out UsageInfo>): UsageViewDescriptor {
|
override fun createUsageViewDescriptor(usages: Array<out UsageInfo>): UsageViewDescriptor {
|
||||||
return object : UsageViewDescriptor {
|
return object : UsageViewDescriptor {
|
||||||
override fun getCommentReferencesText(usagesCount: Int, filesCount: Int) =
|
override fun getCommentReferencesText(usagesCount: Int, filesCount: Int) =
|
||||||
RefactoringBundle.message("comments.elements.header", UsageViewBundle.getOccurencesString(usagesCount, filesCount))
|
RefactoringBundle.message("comments.elements.header", UsageViewBundle.getOccurencesString(usagesCount, filesCount))
|
||||||
|
|
||||||
override fun getCodeReferencesText(usagesCount: Int, filesCount: Int) =
|
override fun getCodeReferencesText(usagesCount: Int, filesCount: Int) =
|
||||||
RefactoringBundle.message("invocations.to.be.inlined", UsageViewBundle.getReferencesString(usagesCount, filesCount))
|
RefactoringBundle.message("invocations.to.be.inlined", UsageViewBundle.getReferencesString(usagesCount, filesCount))
|
||||||
|
|
||||||
override fun getElements() = arrayOf(declaration)
|
override fun getElements() = arrayOf(declaration)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user