Clean up intentions package
This commit is contained in:
@@ -31,14 +31,10 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
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.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.refactoring.reportDeclarationConflict
|
import org.jetbrains.kotlin.idea.refactoring.*
|
||||||
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.KtSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
@@ -182,7 +178,7 @@ class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamedFunctio
|
|||||||
callables.forEach {
|
callables.forEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
is KtNamedFunction -> convertFunction(it, psiFactory)
|
is KtNamedFunction -> convertFunction(it, psiFactory)
|
||||||
is PsiMethod -> it.setName(newGetterName)
|
is PsiMethod -> it.name = newGetterName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention<
|
|||||||
property.add(getter)
|
property.add(getter)
|
||||||
}
|
}
|
||||||
|
|
||||||
property.setInitializer(null)
|
property.initializer = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
callables.forEach {
|
callables.forEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
is KtProperty -> convertProperty(it, kotlinPsiFactory)
|
is KtProperty -> convertProperty(it, kotlinPsiFactory)
|
||||||
is PsiMethod -> it.setName(newName)
|
is PsiMethod -> it.name = newName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,19 +24,21 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.openapi.module.ModuleUtilCore
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.JavaDirectoryService
|
||||||
import com.intellij.refactoring.rename.PsiElementRenameHandler
|
import com.intellij.refactoring.rename.PsiElementRenameHandler
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
|
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
|
||||||
import org.jetbrains.kotlin.idea.refactoring.getOrCreateKotlinFile
|
import org.jetbrains.kotlin.idea.refactoring.getOrCreateKotlinFile
|
||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory.ClassHeaderBuilder
|
import org.jetbrains.kotlin.psi.KtPsiFactory.ClassHeaderBuilder
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.resolve.ModifiersChecker
|
import org.jetbrains.kotlin.resolve.ModifiersChecker
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
private const val IMPL_SUFFIX = "Impl"
|
private const val IMPL_SUFFIX = "Impl"
|
||||||
|
|
||||||
@@ -131,7 +133,7 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
|
|||||||
val dlg = chooseSubclassToCreate(baseClass, baseName) ?: return
|
val dlg = chooseSubclassToCreate(baseClass, baseName) ?: return
|
||||||
val targetName = dlg.className
|
val targetName = dlg.className
|
||||||
val file = getOrCreateKotlinFile("$targetName.kt", dlg.targetDirectory)!!
|
val file = getOrCreateKotlinFile("$targetName.kt", dlg.targetDirectory)!!
|
||||||
val builder = buildClassHeader(targetName, baseClass, "${baseClass.fqName!!.asString()}")
|
val builder = buildClassHeader(targetName, baseClass, baseClass.fqName!!.asString())
|
||||||
file.add(factory.createClass(builder.asString()))
|
file.add(factory.createClass(builder.asString()))
|
||||||
val klass = file.getChildOfType<KtClass>()!!
|
val klass = file.getChildOfType<KtClass>()!!
|
||||||
ShortenReferences.DEFAULT.process(klass)
|
ShortenReferences.DEFAULT.process(klass)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class IntroduceBackingPropertyIntention(): SelfTargetingIntention<KtProperty>(Kt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property.setInitializer(null)
|
property.initializer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createGetter(element: KtProperty) {
|
private fun createGetter(element: KtProperty) {
|
||||||
|
|||||||
+2
-4
@@ -18,10 +18,8 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
|
|
||||||
class ReplaceSubstringWithSubstringAfterIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringAfter' call") {
|
class ReplaceSubstringWithSubstringAfterIntention : ReplaceSubstringIntention("Replace 'substring' call with 'substringAfter' call") {
|
||||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
|
||||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
|
||||||
|
|
||||||
class ReplaceSubstringWithTakeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'take' call") {
|
class ReplaceSubstringWithTakeIntention : ReplaceSubstringIntention("Replace 'substring' call with 'take' call") {
|
||||||
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
override fun applicabilityRangeInner(element: KtDotQualifiedExpression): TextRange? {
|
||||||
|
|||||||
@@ -147,11 +147,11 @@ class SimplifyForIntention : SelfTargetingRangeIntention<KtForExpression>(
|
|||||||
val applicableUsage = getDataIfUsageIsApplicable(it, context)
|
val applicableUsage = getDataIfUsageIsApplicable(it, context)
|
||||||
if (applicableUsage != null) {
|
if (applicableUsage != null) {
|
||||||
val descriptorName = applicableUsage.descriptor.name.asString()
|
val descriptorName = applicableUsage.descriptor.name.asString()
|
||||||
if (descriptorName.equals("key") || descriptorName.equals("getKey")) {
|
if (descriptorName == "key" || descriptorName == "getKey") {
|
||||||
process(0, applicableUsage)
|
process(0, applicableUsage)
|
||||||
return@forEach true
|
return@forEach true
|
||||||
}
|
}
|
||||||
else if (descriptorName.equals("value") || descriptorName.equals("getValue")) {
|
else if (descriptorName == "value" || descriptorName == "getValue") {
|
||||||
process(1, applicableUsage)
|
process(1, applicableUsage)
|
||||||
return@forEach true
|
return@forEach true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
|||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
|
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
|
||||||
import org.jetbrains.kotlin.idea.util.isResolvableInScope
|
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.util.getResolvableApproximations
|
import org.jetbrains.kotlin.idea.util.getResolvableApproximations
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.isFlexible
|
import org.jetbrains.kotlin.types.isFlexible
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
|
|
||||||
fun KtCallableDeclaration.setType(type: KotlinType, shortenReferences: Boolean = true) {
|
fun KtCallableDeclaration.setType(type: KotlinType, shortenReferences: Boolean = true) {
|
||||||
if (type.isError) return
|
if (type.isError) return
|
||||||
@@ -92,7 +93,7 @@ fun splitPropertyDeclaration(property: KtProperty): KtBinaryExpression {
|
|||||||
assignment = parent.addAfter(assignment, property) as KtBinaryExpression
|
assignment = parent.addAfter(assignment, property) as KtBinaryExpression
|
||||||
parent.addAfter(psiFactory.createNewLine(), property)
|
parent.addAfter(psiFactory.createNewLine(), property)
|
||||||
|
|
||||||
property.setInitializer(null)
|
property.initializer = null
|
||||||
|
|
||||||
if (explicitTypeToSet != null) {
|
if (explicitTypeToSet != null) {
|
||||||
property.setType(explicitTypeToSet)
|
property.setType(explicitTypeToSet)
|
||||||
|
|||||||
+1
-4
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiComment
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
|
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
|
||||||
@@ -152,9 +151,7 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
|
|||||||
|
|
||||||
val result = element.replace(whenExpression)
|
val result = element.replace(whenExpression)
|
||||||
(if (applyFullCommentSaver) fullCommentSaver else elementCommentSaver).restore(result)
|
(if (applyFullCommentSaver) fullCommentSaver else elementCommentSaver).restore(result)
|
||||||
toDelete.forEach {
|
toDelete.forEach(PsiElement::delete)
|
||||||
it.delete()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MutableList<KtExpression>.addOrBranches(expression: KtExpression): List<KtExpression> {
|
private fun MutableList<KtExpression>.addOrBranches(expression: KtExpression): List<KtExpression> {
|
||||||
|
|||||||
-3
@@ -18,13 +18,10 @@ package org.jetbrains.kotlin.idea.intentions.conventionNameCalls
|
|||||||
|
|
||||||
import com.intellij.codeInsight.intention.HighPriorityAction
|
import com.intellij.codeInsight.intention.HighPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde.getAnyDeclaration
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.*
|
import org.jetbrains.kotlin.idea.intentions.*
|
||||||
import org.jetbrains.kotlin.idea.refactoring.canRefactor
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
|||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.ImplicitSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.ImplicitSmartCasts
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
|
|
||||||
object MatcherRegistrar {
|
object MatcherRegistrar {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ fun generateLambda(expression: KtExpression, vararg inputVariables: KtCallableDe
|
|||||||
private fun KtLambdaExpression.findParameterUsages(lambdaParam: KtParameter, context: KtExpression): Collection<KtNameReferenceExpression> {
|
private fun KtLambdaExpression.findParameterUsages(lambdaParam: KtParameter, context: KtExpression): Collection<KtNameReferenceExpression> {
|
||||||
val bindingContext = analyzeInContext(context)
|
val bindingContext = analyzeInContext(context)
|
||||||
val lambdaParamDescriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, lambdaParam]
|
val lambdaParamDescriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, lambdaParam]
|
||||||
return collectDescendantsOfType<KtNameReferenceExpression> {
|
return collectDescendantsOfType {
|
||||||
it.mainReference.resolveToDescriptors(bindingContext).singleOrNull() == lambdaParamDescriptor
|
it.mainReference.resolveToDescriptors(bindingContext).singleOrNull() == lambdaParamDescriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,11 +356,11 @@ fun KtExpression.isStableInLoop(loop: KtLoopExpression, checkNoOtherUsagesInLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KtExpression.containsEmbeddedBreakOrContinue(): Boolean {
|
fun KtExpression.containsEmbeddedBreakOrContinue(): Boolean {
|
||||||
return anyDescendantOfType<KtExpressionWithLabel>(::isEmbeddedBreakOrContinue)
|
return anyDescendantOfType(::isEmbeddedBreakOrContinue)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtExpression.countEmbeddedBreaksAndContinues(): Int {
|
fun KtExpression.countEmbeddedBreaksAndContinues(): Int {
|
||||||
return collectDescendantsOfType<KtExpressionWithLabel>(::isEmbeddedBreakOrContinue).size
|
return collectDescendantsOfType(::isEmbeddedBreakOrContinue).size
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isEmbeddedBreakOrContinue(expression: KtExpressionWithLabel): Boolean {
|
private fun isEmbeddedBreakOrContinue(expression: KtExpressionWithLabel): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user