Refactoring of JetSelfTargetingInspection
This commit is contained in:
+11
-18
@@ -16,22 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.codeInspection.*
|
||||||
import org.jetbrains.kotlin.psi.JetElement
|
|
||||||
import com.intellij.psi.PsiElementVisitor
|
|
||||||
import com.intellij.codeInspection.LocalInspectionToolSession
|
|
||||||
import com.intellij.codeInspection.ProblemsHolder
|
|
||||||
import com.intellij.codeInspection.ProblemHighlightType
|
|
||||||
import com.intellij.codeInspection.LocalQuickFix
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.codeInspection.ProblemDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
|
||||||
import com.intellij.openapi.editor.EditorFactory
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.editor.EditorFactory
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiElementVisitor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.psi.JetElement
|
||||||
|
|
||||||
public abstract class IntentionBasedInspection<T: JetElement>(
|
public abstract class IntentionBasedInspection<T: JetElement>(
|
||||||
protected val intention: JetSelfTargetingIntention<T>
|
protected val intention: JetSelfTargetingOffsetIndependentIntention<T>
|
||||||
) : AbstractKotlinInspection() {
|
) : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
return object: PsiElementVisitor() {
|
return object: PsiElementVisitor() {
|
||||||
@@ -70,11 +66,8 @@ public abstract class IntentionBasedInspection<T: JetElement>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun PsiElement.getOrCreateEditor(): Editor? {
|
private fun PsiElement.getOrCreateEditor(): Editor? {
|
||||||
val file = getContainingFile()?.getVirtualFile()
|
val file = getContainingFile()?.getVirtualFile() ?: return null
|
||||||
if (file == null) return null
|
val document = FileDocumentManager.getInstance().getDocument(file) ?: return null
|
||||||
|
|
||||||
val document = FileDocumentManager.getInstance()!!.getDocument(file)
|
|
||||||
if (document == null) return null
|
|
||||||
|
|
||||||
val editorFactory = EditorFactory.getInstance()!!
|
val editorFactory = EditorFactory.getInstance()!!
|
||||||
|
|
||||||
|
|||||||
+24
-9
@@ -37,27 +37,42 @@ public abstract class JetSelfTargetingIntention<T: JetElement>(
|
|||||||
this.text = text
|
this.text = text
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getText() = text
|
final override fun getText() = text
|
||||||
override fun getFamilyName() = familyName
|
final override fun getFamilyName() = familyName
|
||||||
|
|
||||||
|
public abstract fun isApplicableTo(element: T, caretOffset: Int): Boolean
|
||||||
|
|
||||||
public abstract fun isApplicableTo(element: T): Boolean
|
|
||||||
public open fun isApplicableTo(element: T, editor: Editor): Boolean = isApplicableTo(element)
|
|
||||||
public abstract fun applyTo(element: T, editor: Editor)
|
public abstract fun applyTo(element: T, editor: Editor)
|
||||||
|
|
||||||
protected fun getTarget(editor: Editor, file: PsiFile): T? {
|
private fun getTarget(editor: Editor, file: PsiFile): T? {
|
||||||
val offset = editor.getCaretModel().getOffset()
|
val offset = editor.getCaretModel().getOffset()
|
||||||
return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) }
|
return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, offset) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isAvailable(project: Project, editor: Editor, file: PsiFile)
|
final override fun isAvailable(project: Project, editor: Editor, file: PsiFile)
|
||||||
= getTarget(editor, file) != null
|
= getTarget(editor, file) != null
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit {
|
final override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit {
|
||||||
val target = getTarget(editor, file) ?: error("Intention is not applicable")
|
val target = getTarget(editor, file) ?: error("Intention is not applicable")
|
||||||
applyTo(target, editor)
|
applyTo(target, editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startInWriteAction(): Boolean = true
|
override fun startInWriteAction() = true
|
||||||
|
|
||||||
override fun toString(): String = getText()
|
override fun toString(): String = getText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract class JetSelfTargetingOffsetIndependentIntention<T: JetElement>(
|
||||||
|
elementType: Class<T>,
|
||||||
|
text: String,
|
||||||
|
familyName: String)
|
||||||
|
: JetSelfTargetingIntention<T>(elementType, text, familyName) {
|
||||||
|
|
||||||
|
deprecated("Use primary constructor, no need to use i18n")
|
||||||
|
public constructor(key: String, elementType: Class<T>) : this(elementType, JetBundle.message(key), JetBundle.message(key + ".family")) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract fun isApplicableTo(element: T): Boolean
|
||||||
|
|
||||||
|
override final fun isApplicableTo(element: T, caretOffset: Int): Boolean = isApplicableTo(element)
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>("operator.to.function", javaClass()) {
|
public class OperatorToFunctionIntention : JetSelfTargetingOffsetIndependentIntention<JetExpression>("operator.to.function", javaClass()) {
|
||||||
companion object {
|
companion object {
|
||||||
private fun isApplicablePrefix(element: JetPrefixExpression): Boolean {
|
private fun isApplicablePrefix(element: JetPrefixExpression): Boolean {
|
||||||
return when (element.getOperationReference().getReferencedNameElementType()) {
|
return when (element.getOperationReference().getReferencedNameElementType()) {
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.idea.util.approximateFlexibleTypes
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgumentList>(
|
public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention<JetTypeArgumentList>(
|
||||||
"remove.explicit.type.arguments", javaClass()) {
|
"remove.explicit.type.arguments", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetTypeArgumentList): Boolean {
|
override fun isApplicableTo(element: JetTypeArgumentList): Boolean {
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.JetPsiUtil
|
|||||||
import org.jetbrains.kotlin.idea.JetBundle
|
import org.jetbrains.kotlin.idea.JetBundle
|
||||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||||
|
|
||||||
public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingIntention<JetPrefixExpression>("simplify.negated.binary.expression", javaClass()) {
|
public class SimplifyNegatedBinaryExpressionIntention : JetSelfTargetingOffsetIndependentIntention<JetPrefixExpression>("simplify.negated.binary.expression", javaClass()) {
|
||||||
|
|
||||||
private fun JetPrefixExpression.unparenthesize(): JetExpression? {
|
private fun JetPrefixExpression.unparenthesize(): JetExpression? {
|
||||||
return (this.getBaseExpression() as? JetParenthesizedExpression)?.getExpression()
|
return (this.getBaseExpression() as? JetParenthesizedExpression)?.getExpression()
|
||||||
|
|||||||
@@ -24,16 +24,10 @@ import org.jetbrains.kotlin.JetNodeTypes
|
|||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
|
||||||
public class AddBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("add.braces", javaClass()) {
|
public class AddBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("add.braces", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetExpressionImpl): Boolean {
|
override fun isApplicableTo(element: JetExpressionImpl, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
val expressionKind = element.getExpressionKind(caretOffset) ?: return false
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetExpressionImpl, editor: Editor): Boolean {
|
if (element.findBlockInExpression(expressionKind) != null) return false
|
||||||
val expressionKind = element.getExpressionKind(editor.getCaretModel().getOffset())
|
|
||||||
if (expressionKind == null) return false
|
|
||||||
|
|
||||||
val jetBlockElement = element.findBlockInExpression(expressionKind)
|
|
||||||
if (jetBlockElement != null) return false
|
|
||||||
|
|
||||||
setText("Add braces to '${expressionKind.text}' statement")
|
setText("Add braces to '${expressionKind.text}' statement")
|
||||||
return true
|
return true
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.JetThrowExpression
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.replaced
|
import org.jetbrains.kotlin.psi.psiUtil.replaced
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
|
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingOffsetIndependentIntention<JetCallExpression>(
|
||||||
"convert.assert.to.if.with.throw", javaClass()) {
|
"convert.assert.to.if.with.throw", javaClass()) {
|
||||||
|
|
||||||
private var messageIsAFunction : Boolean by Delegates.notNull()
|
private var messageIsAFunction : Boolean by Delegates.notNull()
|
||||||
|
|||||||
@@ -190,12 +190,8 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
|
|||||||
|
|
||||||
override fun startInWriteAction(): Boolean = false
|
override fun startInWriteAction(): Boolean = false
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetNamedFunction): Boolean {
|
override fun isApplicableTo(element: JetNamedFunction, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
val elementAtCaret = element.getContainingFile().findElementAt(caretOffset)
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetNamedFunction, editor: Editor): Boolean {
|
|
||||||
val elementAtCaret = element.getContainingFile().findElementAt(editor.getCaretModel().getOffset())
|
|
||||||
if (!(element.getNameIdentifier()?.isAncestor(elementAtCaret) ?: false)) return false
|
if (!(element.getNameIdentifier()?.isAncestor(elementAtCaret) ?: false)) return false
|
||||||
|
|
||||||
if (element.getValueParameters().isNotEmpty() || element.isLocal()) return false
|
if (element.getValueParameters().isNotEmpty() || element.isLocal()) return false
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class ConvertIfWithThrowToAssertIntention :
|
public class ConvertIfWithThrowToAssertIntention :
|
||||||
JetSelfTargetingIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) {
|
JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("convert.if.with.throw.to.assert", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
||||||
if (element.getElse() != null) return false
|
if (element.getElse() != null) return false
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.JetPsiUtil
|
|||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
|
|
||||||
|
|
||||||
public class ConvertNegatedBooleanSequenceIntention : JetSelfTargetingIntention<JetBinaryExpression>(
|
public class ConvertNegatedBooleanSequenceIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(
|
||||||
"convert.negated.boolean.sequence", javaClass()) {
|
"convert.negated.boolean.sequence", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
|||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import org.jetbrains.kotlin.idea.JetBundle
|
import org.jetbrains.kotlin.idea.JetBundle
|
||||||
|
|
||||||
public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetingIntention<JetPrefixExpression>(
|
public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetingOffsetIndependentIntention<JetPrefixExpression>(
|
||||||
"convert.negated.expression.with.demorgans.law", javaClass()
|
"convert.negated.expression.with.demorgans.law", javaClass()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetMethodDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||||
|
|
||||||
public class ConvertParameterToReceiverIntention: JetSelfTargetingIntention<JetParameter>("convert.parameter.to.receiver.intention", javaClass()) {
|
public class ConvertParameterToReceiverIntention: JetSelfTargetingOffsetIndependentIntention<JetParameter>("convert.parameter.to.receiver.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetParameter): Boolean {
|
override fun isApplicableTo(element: JetParameter): Boolean {
|
||||||
if (element.isVarArg()) return false
|
if (element.isVarArg()) return false
|
||||||
val function = element.getStrictParentOfType<JetNamedFunction>() ?: return false
|
val function = element.getStrictParentOfType<JetNamedFunction>() ?: return false
|
||||||
|
|||||||
@@ -182,12 +182,8 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<JetP
|
|||||||
|
|
||||||
override fun startInWriteAction(): Boolean = false
|
override fun startInWriteAction(): Boolean = false
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetProperty): Boolean {
|
override fun isApplicableTo(element: JetProperty, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
val elementAtCaret = element.getContainingFile().findElementAt(caretOffset)
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetProperty, editor: Editor): Boolean {
|
|
||||||
val elementAtCaret = element.getContainingFile().findElementAt(editor.getCaretModel().getOffset())
|
|
||||||
if (!(element.getNameIdentifier()?.isAncestor(elementAtCaret) ?: false)) return false
|
if (!(element.getNameIdentifier()?.isAncestor(elementAtCaret) ?: false)) return false
|
||||||
|
|
||||||
return element.getDelegate() == null && !element.isVar() && !element.isLocal()
|
return element.getDelegate() == null && !element.isVar() && !element.isLocal()
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetChangeSignatureC
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetMethodDescriptor
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetMethodDescriptor
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify
|
||||||
|
|
||||||
public class ConvertReceiverToParameterIntention: JetSelfTargetingIntention<JetTypeReference>("convert.receiver.to.parameter.intention", javaClass()) {
|
public class ConvertReceiverToParameterIntention: JetSelfTargetingOffsetIndependentIntention<JetTypeReference>("convert.receiver.to.parameter.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetTypeReference): Boolean {
|
override fun isApplicableTo(element: JetTypeReference): Boolean {
|
||||||
return (element.getParent() as? JetNamedFunction)?.getReceiverTypeReference() == element
|
return (element.getParent() as? JetNamedFunction)?.getReceiverTypeReference() == element
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.JetIfExpression
|
|||||||
import org.jetbrains.kotlin.psi.JetBlockExpression
|
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class ConvertToConcatenatedStringIntention : JetSelfTargetingIntention<JetStringTemplateExpression>("convert.to.concatenated.string.intention", javaClass()) {
|
public class ConvertToConcatenatedStringIntention : JetSelfTargetingOffsetIndependentIntention<JetStringTemplateExpression>("convert.to.concatenated.string.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetStringTemplateExpression): Boolean {
|
override fun isApplicableTo(element: JetStringTemplateExpression): Boolean {
|
||||||
return element.getEntries().any { it is JetStringTemplateEntryWithExpression }
|
return element.getEntries().any { it is JetStringTemplateEntryWithExpression }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.JetElement
|
|||||||
import org.jetbrains.kotlin.psi.JetParameter
|
import org.jetbrains.kotlin.psi.JetParameter
|
||||||
import org.jetbrains.kotlin.psi.JetOperationExpression
|
import org.jetbrains.kotlin.psi.JetOperationExpression
|
||||||
|
|
||||||
public class ConvertToForEachFunctionCallIntention : JetSelfTargetingIntention<JetForExpression>("convert.to.for.each.function.call.intention", javaClass()) {
|
public class ConvertToForEachFunctionCallIntention : JetSelfTargetingOffsetIndependentIntention<JetForExpression>("convert.to.for.each.function.call.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetForExpression): Boolean {
|
override fun isApplicableTo(element: JetForExpression): Boolean {
|
||||||
return element.getLoopRange() != null && element.getLoopParameter() != null && element.getBody() != null
|
return element.getLoopRange() != null && element.getLoopParameter() != null && element.getBody() != null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.JetParenthesizedExpression
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class ConvertToForEachLoopIntention : JetSelfTargetingIntention<JetExpression>("convert.to.for.each.loop.intention", javaClass()) {
|
public class ConvertToForEachLoopIntention : JetSelfTargetingOffsetIndependentIntention<JetExpression>("convert.to.for.each.loop.intention", javaClass()) {
|
||||||
private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? {
|
private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? {
|
||||||
val argument = when (element) {
|
val argument = when (element) {
|
||||||
is JetDotQualifiedExpression -> {
|
is JetDotQualifiedExpression -> {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
|
|
||||||
public class ConvertToStringTemplateIntention : JetSelfTargetingIntention<JetBinaryExpression>("convert.to.string.template", javaClass()) {
|
public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>("convert.to.string.template", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||||
if (element.getOperationToken() != JetTokens.PLUS) return false
|
if (element.getOperationToken() != JetTokens.PLUS) return false
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import org.jetbrains.kotlin.psi.JetSimpleNameStringTemplateEntry
|
import org.jetbrains.kotlin.psi.JetSimpleNameStringTemplateEntry
|
||||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||||
|
|
||||||
public class InsertCurlyBracesToTemplateIntention : JetSelfTargetingIntention<JetSimpleNameStringTemplateEntry>(
|
public class InsertCurlyBracesToTemplateIntention : JetSelfTargetingOffsetIndependentIntention<JetSimpleNameStringTemplateEntry>(
|
||||||
"insert.curly.brackets.to.string.template", javaClass()) {
|
"insert.curly.brackets.to.string.template", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetSimpleNameStringTemplateEntry): Boolean = true
|
override fun isApplicableTo(element: JetSimpleNameStringTemplateEntry): Boolean = true
|
||||||
|
|||||||
@@ -29,16 +29,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>(
|
public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpression>(
|
||||||
"insert.explicit.type.arguments", javaClass()) {
|
"insert.explicit.type.arguments", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetCallExpression): Boolean {
|
override fun isApplicableTo(element: JetCallExpression, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetCallExpression, editor: Editor): Boolean {
|
|
||||||
if (!element.getTypeArguments().isEmpty()) return false
|
if (!element.getTypeArguments().isEmpty()) return false
|
||||||
if (element.getText() == null) return false
|
if (element.getText() == null) return false
|
||||||
|
|
||||||
val textRange = element.getCalleeExpression()?.getTextRange()
|
val textRange = element.getCalleeExpression()?.getTextRange()
|
||||||
if (textRange == null || !textRange.contains(editor.getCaretModel().getOffset())) return false
|
if (textRange == null || !textRange.contains(caretOffset)) return false
|
||||||
|
|
||||||
val context = element.analyze()
|
val context = element.analyze()
|
||||||
val resolvedCall = element.getResolvedCall(context)
|
val resolvedCall = element.getResolvedCall(context)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.lexer.JetKeywordToken
|
|||||||
import org.jetbrains.kotlin.psi.JetNamedFunction
|
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.JetBlockExpression
|
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||||
|
|
||||||
public class InvertIfConditionIntention : JetSelfTargetingIntention<JetIfExpression>("invert.if.condition", javaClass()) {
|
public class InvertIfConditionIntention : JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("invert.if.condition", javaClass()) {
|
||||||
fun checkForNegation(element: JetUnaryExpression): Boolean {
|
fun checkForNegation(element: JetUnaryExpression): Boolean {
|
||||||
return element.getOperationReference().getReferencedName().equals("!")
|
return element.getOperationReference().getReferencedName().equals("!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,18 +29,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFunctionLiteralExpression>(
|
public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFunctionLiteralExpression>(
|
||||||
"make.type.explicit.in.lambda", javaClass()) {
|
"make.type.explicit.in.lambda", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean {
|
override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean {
|
|
||||||
val openBraceOffset = element.getLeftCurlyBrace().getStartOffset()
|
val openBraceOffset = element.getLeftCurlyBrace().getStartOffset()
|
||||||
val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset()
|
val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset()
|
||||||
val caretLocation = editor.getCaretModel().getOffset()
|
|
||||||
val arrow = element.getFunctionLiteral().getArrowNode()
|
val arrow = element.getFunctionLiteral().getArrowNode()
|
||||||
if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) &&
|
if (arrow != null && !(openBraceOffset < caretOffset && caretOffset < arrow.getStartOffset() + 2) &&
|
||||||
caretLocation != closeBraceOffset) return false
|
caretOffset != closeBraceOffset) return false
|
||||||
else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false
|
else if (arrow == null && caretOffset != openBraceOffset + 1 && caretOffset != closeBraceOffset) return false
|
||||||
|
|
||||||
val context = element.analyze()
|
val context = element.analyze()
|
||||||
val func = context[BindingContext.FUNCTION, element.getFunctionLiteral()]
|
val func = context[BindingContext.FUNCTION, element.getFunctionLiteral()]
|
||||||
|
|||||||
@@ -23,18 +23,13 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
|||||||
|
|
||||||
public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention<JetFunctionLiteralExpression>(
|
public class MakeTypeImplicitInLambdaIntention : JetSelfTargetingIntention<JetFunctionLiteralExpression>(
|
||||||
"make.type.implicit.in.lambda", javaClass()) {
|
"make.type.implicit.in.lambda", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetFunctionLiteralExpression): Boolean {
|
override fun isApplicableTo(element: JetFunctionLiteralExpression, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetFunctionLiteralExpression, editor: Editor): Boolean {
|
|
||||||
val openBraceOffset = element.getLeftCurlyBrace().getStartOffset()
|
val openBraceOffset = element.getLeftCurlyBrace().getStartOffset()
|
||||||
val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset()
|
val closeBraceOffset = element.getRightCurlyBrace()?.getStartOffset()
|
||||||
val caretLocation = editor.getCaretModel().getOffset()
|
|
||||||
val arrow = element.getFunctionLiteral().getArrowNode()
|
val arrow = element.getFunctionLiteral().getArrowNode()
|
||||||
if (arrow != null && !(openBraceOffset < caretLocation && caretLocation < arrow.getStartOffset() + 2) &&
|
if (arrow != null && !(openBraceOffset < caretOffset && caretOffset < arrow.getStartOffset() + 2) &&
|
||||||
caretLocation != closeBraceOffset) return false
|
caretOffset != closeBraceOffset) return false
|
||||||
else if (arrow == null && caretLocation != openBraceOffset + 1 && caretLocation != closeBraceOffset) return false
|
else if (arrow == null && caretOffset != openBraceOffset + 1 && caretOffset != closeBraceOffset) return false
|
||||||
return hasExplicitReturnType(element) || hasExplicitReceiverType(element) || hasExplicitParamType(element)
|
return hasExplicitReturnType(element) || hasExplicitReceiverType(element) || hasExplicitParamType(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.psi.JetFunctionLiteralArgument
|
|||||||
import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParentheses
|
import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParentheses
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||||
|
|
||||||
public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingIntention<JetFunctionLiteralArgument>(
|
public class MoveLambdaInsideParenthesesIntention : JetSelfTargetingOffsetIndependentIntention<JetFunctionLiteralArgument>(
|
||||||
"move.lambda.inside.parentheses", javaClass()) {
|
"move.lambda.inside.parentheses", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetFunctionLiteralArgument): Boolean = true
|
override fun isApplicableTo(element: JetFunctionLiteralArgument): Boolean = true
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.JetExpression
|
|||||||
import org.jetbrains.kotlin.psi.JetLabeledExpression
|
import org.jetbrains.kotlin.psi.JetLabeledExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
|
||||||
|
|
||||||
public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingIntention<JetCallExpression>(
|
public class MoveLambdaOutsideParenthesesIntention : JetSelfTargetingOffsetIndependentIntention<JetCallExpression>(
|
||||||
"move.lambda.outside.parentheses", javaClass()) {
|
"move.lambda.outside.parentheses", javaClass()) {
|
||||||
|
|
||||||
private fun isLambdaOrLabeledLambda(expression: JetExpression?): Boolean =
|
private fun isLambdaOrLabeledLambda(expression: JetExpression?): Boolean =
|
||||||
|
|||||||
@@ -24,16 +24,10 @@ import com.intellij.psi.PsiWhiteSpace
|
|||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
|
|
||||||
public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("remove.braces", javaClass()) {
|
public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("remove.braces", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetExpressionImpl): Boolean {
|
override fun isApplicableTo(element: JetExpressionImpl, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
val expressionKind = element.getExpressionKind(caretOffset) ?: return false
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetExpressionImpl, editor: Editor): Boolean {
|
val jetBlockElement = element.findBlockInExpression(expressionKind) ?: return false
|
||||||
val expressionKind = element.getExpressionKind(editor.getCaretModel().getOffset())
|
|
||||||
if (expressionKind == null) return false
|
|
||||||
|
|
||||||
val jetBlockElement = element.findBlockInExpression(expressionKind)
|
|
||||||
if (jetBlockElement == null) return false
|
|
||||||
|
|
||||||
if (jetBlockElement.getStatements().size == 1) {
|
if (jetBlockElement.getStatements().size == 1) {
|
||||||
setText("Remove braces from '${expressionKind.text}' statement")
|
setText("Remove braces from '${expressionKind.text}' statement")
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.JetPsiFactory
|
|||||||
import java.util.regex.*
|
import java.util.regex.*
|
||||||
import org.jetbrains.kotlin.psi.JetStringTemplateEntryWithExpression
|
import org.jetbrains.kotlin.psi.JetStringTemplateEntryWithExpression
|
||||||
|
|
||||||
public class RemoveCurlyBracesFromTemplateIntention : JetSelfTargetingIntention<JetBlockStringTemplateEntry>(
|
public class RemoveCurlyBracesFromTemplateIntention : JetSelfTargetingOffsetIndependentIntention<JetBlockStringTemplateEntry>(
|
||||||
"remove.unnecessary.curly.brackets.from.string.template", javaClass()) {
|
"remove.unnecessary.curly.brackets.from.string.template", javaClass()) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import org.jetbrains.kotlin.psi.JetParenthesizedExpression
|
import org.jetbrains.kotlin.psi.JetParenthesizedExpression
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
|
||||||
public class RemoveUnnecessaryParenthesesIntention : JetSelfTargetingIntention<JetParenthesizedExpression>(
|
public class RemoveUnnecessaryParenthesesIntention : JetSelfTargetingOffsetIndependentIntention<JetParenthesizedExpression>(
|
||||||
"remove.unnecessary.parentheses", javaClass()
|
"remove.unnecessary.parentheses", javaClass()
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: JetParenthesizedExpression): Boolean = JetPsiUtil.areParenthesesUseless(element)
|
override fun isApplicableTo(element: JetParenthesizedExpression): Boolean = JetPsiUtil.areParenthesesUseless(element)
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression
|
|||||||
import org.jetbrains.kotlin.psi.JetParenthesizedExpression
|
import org.jetbrains.kotlin.psi.JetParenthesizedExpression
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
|
||||||
public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.dot.qualified.method.call.intention", javaClass()) {
|
public class ReplaceWithDotQualifiedMethodCallIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>("replace.with.dot.qualified.method.call.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||||
return element.getLeft() != null && element.getRight() != null && element.getOperationToken() == JetTokens.IDENTIFIER
|
return element.getLeft() != null && element.getRight() != null && element.getOperationToken() == JetTokens.IDENTIFIER
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -30,20 +30,14 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
|
public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntention<JetCallExpression>("replace.with.infix.function.call.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetCallExpression): Boolean {
|
override fun isApplicableTo(element: JetCallExpression, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpressionImpl, Editor) should be called instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetCallExpression, editor: Editor): Boolean {
|
|
||||||
val caretLocation = editor.getCaretModel().getOffset()
|
|
||||||
|
|
||||||
val calleeExpr = element.getCalleeExpression()
|
val calleeExpr = element.getCalleeExpression()
|
||||||
if (calleeExpr == null) return false
|
if (calleeExpr == null) return false
|
||||||
|
|
||||||
val textRange = calleeExpr.getTextRange()
|
val textRange = calleeExpr.getTextRange()
|
||||||
if (textRange == null) return false
|
if (textRange == null) return false
|
||||||
|
|
||||||
if (caretLocation !in textRange) return false
|
if (caretOffset !in textRange) return false
|
||||||
|
|
||||||
val parent = element.getParent()
|
val parent = element.getParent()
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.operator.assign.intention", javaClass()) {
|
public class ReplaceWithOperatorAssignIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>("replace.with.operator.assign.intention", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||||
fun isWellFormedAssignment(element : JetBinaryExpression): Boolean {
|
fun isWellFormedAssignment(element : JetBinaryExpression): Boolean {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
|||||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUnparsingUtils
|
import org.jetbrains.kotlin.psi.JetPsiUnparsingUtils
|
||||||
|
|
||||||
public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingIntention<JetBinaryExpression>("replace.with.traditional.assignment.intention", javaClass()) {
|
public class ReplaceWithTraditionalAssignmentIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>("replace.with.traditional.assignment.intention", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
|
||||||
fun checkForNullSafety(element: JetBinaryExpression): Boolean = element.getLeft() != null && element.getRight() != null && element.getOperationToken() != null
|
fun checkForNullSafety(element: JetBinaryExpression): Boolean = element.getLeft() != null && element.getRight() != null && element.getOperationToken() != null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.copied
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.replaced
|
import org.jetbrains.kotlin.psi.psiUtil.replaced
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
|
||||||
public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingIntention<JetBinaryExpression>(
|
public class SimplifyBooleanWithConstantsIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(
|
||||||
"simplify.boolean.with.constants", javaClass()) {
|
"simplify.boolean.with.constants", javaClass()) {
|
||||||
|
|
||||||
private var topParent : JetBinaryExpression? = null
|
private var topParent : JetBinaryExpression? = null
|
||||||
|
|||||||
@@ -28,11 +28,7 @@ import org.jetbrains.kotlin.psi.JetExpression
|
|||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
|
||||||
public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.if", javaClass()) {
|
public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.if", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetExpression): Boolean {
|
override fun isApplicableTo(element: JetExpression, caretOffset: Int): Boolean {
|
||||||
throw IllegalStateException("isApplicableTo(JetExpression, Editor) should be called instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetExpression, editor: Editor): Boolean {
|
|
||||||
if (element !is JetSimpleNameExpression && element !is JetIfExpression) return false
|
if (element !is JetSimpleNameExpression && element !is JetIfExpression) return false
|
||||||
|
|
||||||
if (element is JetSimpleNameExpression) {
|
if (element is JetSimpleNameExpression) {
|
||||||
@@ -40,7 +36,7 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element is JetIfExpression) {
|
if (element is JetIfExpression) {
|
||||||
if (!isCursorOnIfKeyword(element, editor)) return false
|
if (!isCursorOnIfKeyword(element, caretOffset)) return false
|
||||||
if (getFirstValidOperator(element) == null) return false
|
if (getFirstValidOperator(element) == null) return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -54,7 +50,7 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
|||||||
|
|
||||||
val ifExpression = currentElement!!.getNonStrictParentOfType<JetIfExpression>()
|
val ifExpression = currentElement!!.getNonStrictParentOfType<JetIfExpression>()
|
||||||
val expression = currentElement.getParent() as JetBinaryExpression
|
val expression = currentElement.getParent() as JetBinaryExpression
|
||||||
val rightExpression = getRight(expression, ifExpression!!.getCondition() as JetExpression)
|
val rightExpression = getRight(expression, ifExpression!!.getCondition())
|
||||||
val leftExpression = expression.getLeft()
|
val leftExpression = expression.getLeft()
|
||||||
val elseExpression = ifExpression.getElse()
|
val elseExpression = ifExpression.getElse()
|
||||||
val thenExpression = ifExpression.getThen()
|
val thenExpression = ifExpression.getThen()
|
||||||
@@ -75,7 +71,7 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRight(element: JetBinaryExpression, condition: JetExpression): JetExpression {
|
private fun getRight(element: JetBinaryExpression, condition: JetExpression): JetExpression {
|
||||||
//gets the textOffset of the right side of the JetBinaryExpression in context to condition
|
//gets the textOffset of the right side of the JetBinaryExpression in context to condition
|
||||||
val startOffset = element.getRight()!!.getTextOffset() - condition.getTextOffset()
|
val startOffset = element.getRight()!!.getTextOffset() - condition.getTextOffset()
|
||||||
val rightString = condition.getText()!![startOffset, condition.getTextLength()].toString()
|
val rightString = condition.getText()!![startOffset, condition.getTextLength()].toString()
|
||||||
@@ -83,20 +79,19 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
|||||||
return JetPsiFactory(element).createExpression(rightString)
|
return JetPsiFactory(element).createExpression(rightString)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isCursorOnIfKeyword(element: JetIfExpression, editor: Editor): Boolean {
|
private fun isCursorOnIfKeyword(element: JetIfExpression, offset: Int): Boolean {
|
||||||
val ifKeyword = JetPsiUtil.findChildByType(element, JetTokens.IF_KEYWORD) ?: return false
|
val ifKeyword = JetPsiUtil.findChildByType(element, JetTokens.IF_KEYWORD) ?: return false
|
||||||
val cursor = editor.getCaretModel().getOffset()
|
return (offset >= ifKeyword.getTextOffset() && offset <= ifKeyword.getTextOffset() + ifKeyword.getTextLength())
|
||||||
return (cursor >= ifKeyword.getTextOffset() && cursor <= ifKeyword.getTextOffset() + ifKeyword.getTextLength())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFirstValidOperator(element: JetIfExpression): JetSimpleNameExpression? {
|
private fun getFirstValidOperator(element: JetIfExpression): JetSimpleNameExpression? {
|
||||||
if (element.getCondition() == null) return null
|
if (element.getCondition() == null) return null
|
||||||
val condition = element.getCondition()
|
val condition = element.getCondition()
|
||||||
val childElements = PsiTreeUtil.findChildrenOfType(condition, javaClass<JetSimpleNameExpression>())
|
val childElements = PsiTreeUtil.findChildrenOfType(condition, javaClass<JetSimpleNameExpression>())
|
||||||
return childElements.firstOrNull { isOperatorValid(it) }
|
return childElements.firstOrNull { isOperatorValid(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isOperatorValid(element: JetSimpleNameExpression): Boolean {
|
private fun isOperatorValid(element: JetSimpleNameExpression): Boolean {
|
||||||
val operator = element.getReferencedNameElementType()
|
val operator = element.getReferencedNameElementType()
|
||||||
if (operator != JetTokens.ANDAND && operator != JetTokens.OROR) return false
|
if (operator != JetTokens.ANDAND && operator != JetTokens.OROR) return false
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.idea.util.JetPsiPrecedences
|
|||||||
import org.jetbrains.kotlin.lexer.JetTokens.*
|
import org.jetbrains.kotlin.lexer.JetTokens.*
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
|
|
||||||
public class SwapBinaryExpression : JetSelfTargetingIntention<JetBinaryExpression>(
|
public class SwapBinaryExpression : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>(
|
||||||
"swap.binary.expression", javaClass()
|
"swap.binary.expression", javaClass()
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+11
-11
@@ -16,23 +16,23 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.attributeCallReplacements
|
package org.jetbrains.kotlin.idea.intentions.attributeCallReplacements
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
import com.intellij.codeInsight.hint.HintManager
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.psi.ValueArgument
|
|
||||||
import org.jetbrains.kotlin.idea.JetBundle
|
import org.jetbrains.kotlin.idea.JetBundle
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.idea.util.Maybe
|
import org.jetbrains.kotlin.idea.util.Maybe
|
||||||
import org.jetbrains.kotlin.idea.util.MaybeError
|
import org.jetbrains.kotlin.idea.util.MaybeError
|
||||||
import org.jetbrains.kotlin.idea.util.MaybeValue
|
import org.jetbrains.kotlin.idea.util.MaybeValue
|
||||||
import com.intellij.codeInsight.hint.HintManager
|
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetQualifiedExpression
|
||||||
|
import org.jetbrains.kotlin.psi.ValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
||||||
|
|
||||||
// Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription.
|
// Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription.
|
||||||
public class CallDescription internal (
|
public class CallDescription internal (
|
||||||
@@ -97,7 +97,7 @@ public fun JetQualifiedExpression.toCallDescription(): CallDescription? {
|
|||||||
return CallDescription(this, callExpression, resolvedCall)
|
return CallDescription(this, callExpression, resolvedCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingIntention<JetDotQualifiedExpression>(name, javaClass()) {
|
public abstract class AttributeCallReplacementIntention(private val name: String) : JetSelfTargetingOffsetIndependentIntention<JetDotQualifiedExpression>(name, javaClass()) {
|
||||||
|
|
||||||
protected abstract fun isApplicableToCall(call: CallDescription): Boolean
|
protected abstract fun isApplicableToCall(call: CallDescription): Boolean
|
||||||
|
|
||||||
|
|||||||
+13
-19
@@ -16,30 +16,24 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
import com.intellij.codeInsight.template.Template
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.codeInsight.template.TemplateBuilderImpl
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
|
||||||
import org.jetbrains.kotlin.psi.JetPostfixExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetTypeLookupExpression
|
|
||||||
import com.intellij.codeInsight.template.TemplateEditingAdapter
|
import com.intellij.codeInsight.template.TemplateEditingAdapter
|
||||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
||||||
import com.intellij.codeInsight.template.Template
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.idea.JetBundle
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition
|
|
||||||
import org.jetbrains.kotlin.psi.JetThrowExpression
|
|
||||||
import com.intellij.codeInsight.template.TemplateBuilderImpl
|
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.apache.commons.lang.StringEscapeUtils.escapeJava
|
import org.apache.commons.lang.StringEscapeUtils.escapeJava
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNullExpression
|
import org.jetbrains.kotlin.idea.JetBundle
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.NULL_PTR_EXCEPTION
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.KOTLIN_NULL_PTR_EXCEPTION
|
import org.jetbrains.kotlin.idea.intentions.JetTypeLookupExpression
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
||||||
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
import org.jetbrains.kotlin.psi.JetPostfixExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
import org.jetbrains.kotlin.psi.JetThrowExpression
|
||||||
|
|
||||||
public class DoubleBangToIfThenIntention : JetSelfTargetingIntention<JetPostfixExpression>("double.bang.to.if.then", javaClass()) {
|
public class DoubleBangToIfThenIntention : JetSelfTargetingOffsetIndependentIntention<JetPostfixExpression>("double.bang.to.if.then", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetPostfixExpression): Boolean =
|
override fun isApplicableTo(element: JetPostfixExpression): Boolean =
|
||||||
element.getOperationToken() == JetTokens.EXCLEXCL
|
element.getOperationToken() == JetTokens.EXCLEXCL
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canEliminateSubject
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.eliminateSubject
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public class EliminateWhenSubjectIntention : JetSelfTargetingIntention<JetWhenExpression>("eliminate.when.subject", javaClass()) {
|
public class EliminateWhenSubjectIntention : JetSelfTargetingOffsetIndependentIntention<JetWhenExpression>("eliminate.when.subject", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canEliminateSubject()
|
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canEliminateSubject()
|
||||||
|
|
||||||
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
||||||
|
|||||||
+5
-5
@@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
||||||
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||||
|
|
||||||
public class ElvisToIfThenIntention : JetSelfTargetingIntention<JetBinaryExpression>("elvis.to.if.then", javaClass()) {
|
public class ElvisToIfThenIntention : JetSelfTargetingOffsetIndependentIntention<JetBinaryExpression>("elvis.to.if.then", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetBinaryExpression): Boolean =
|
override fun isApplicableTo(element: JetBinaryExpression): Boolean =
|
||||||
element.getOperationToken() == JetTokens.ELVIS
|
element.getOperationToken() == JetTokens.ELVIS
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canFlatten
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.flatten
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public class FlattenWhenIntention : JetSelfTargetingIntention<JetWhenExpression>("flatten.when", javaClass()) {
|
public class FlattenWhenIntention : JetSelfTargetingOffsetIndependentIntention<JetWhenExpression>("flatten.when", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canFlatten()
|
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canFlatten()
|
||||||
|
|
||||||
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
||||||
|
|||||||
+4
-4
@@ -16,18 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedFoldingUtils
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedFoldingUtils
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.FoldableKind
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.FoldableKind
|
||||||
import com.intellij.openapi.editor.Editor
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import org.jetbrains.kotlin.psi.JetIfExpression
|
import org.jetbrains.kotlin.psi.JetIfExpression
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public open class FoldBranchedExpressionIntention<T: JetExpression>(
|
public open class FoldBranchedExpressionIntention<T: JetExpression>(
|
||||||
val kind: FoldableKind, elementType: Class<T>
|
val kind: FoldableKind, elementType: Class<T>
|
||||||
) : JetSelfTargetingIntention<T>(kind.getKey(), elementType) {
|
) : JetSelfTargetingOffsetIndependentIntention<T>(kind.getKey(), elementType) {
|
||||||
override fun isApplicableTo(element: T): Boolean = BranchedFoldingUtils.getFoldableExpressionKind(element) == kind
|
override fun isApplicableTo(element: T): Boolean = BranchedFoldingUtils.getFoldableExpressionKind(element) == kind
|
||||||
|
|
||||||
override fun applyTo(element: T, editor: Editor) {
|
override fun applyTo(element: T, editor: Editor) {
|
||||||
|
|||||||
+8
-17
@@ -16,26 +16,17 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetIfExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
|
||||||
import org.jetbrains.kotlin.psi.JetPostfixExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineBaseExpressionIfApplicableWithPrompt
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle
|
|
||||||
import org.jetbrains.kotlin.psi.JetThrowExpression
|
|
||||||
import org.jetbrains.kotlin.idea.JetBundle
|
import org.jetbrains.kotlin.idea.JetBundle
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpressionOrEmptyBlock
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.throwsNullPointerExceptionWithNoArguments
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetIfExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetPostfixExpression
|
||||||
|
import org.jetbrains.kotlin.psi.JetThrowExpression
|
||||||
|
|
||||||
public class IfThenToDoubleBangIntention : JetSelfTargetingIntention<JetIfExpression>("if.then.to.double.bang", javaClass()) {
|
public class IfThenToDoubleBangIntention : JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("if.then.to.double.bang", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
||||||
val condition = element.getCondition()
|
val condition = element.getCondition()
|
||||||
|
|||||||
+4
-16
@@ -16,25 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetIfExpression
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNotNullExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineLeftSideIfApplicableWithPrompt
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.throwsNullPointerExceptionWithNoArguments
|
|
||||||
import org.jetbrains.kotlin.psi.JetThrowExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
|
||||||
|
|
||||||
public class IfThenToElvisIntention : JetSelfTargetingIntention<JetIfExpression>("if.then.to.elvis", javaClass()) {
|
public class IfThenToElvisIntention : JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("if.then.to.elvis", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
||||||
val condition = element.getCondition()
|
val condition = element.getCondition()
|
||||||
|
|||||||
+4
-14
@@ -16,23 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetIfExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
|
||||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.extractExpressionIfSingle
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.comparesNonNullToNull
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.getNonNullExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpressionOrEmptyBlock
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.replace
|
|
||||||
import org.jetbrains.kotlin.psi.JetSafeQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.inlineReceiverIfApplicableWithPrompt
|
|
||||||
|
|
||||||
public class IfThenToSafeAccessIntention : JetSelfTargetingIntention<JetIfExpression>("if.then.to.safe.access", javaClass()) {
|
public class IfThenToSafeAccessIntention : JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("if.then.to.safe.access", javaClass()) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
override fun isApplicableTo(element: JetIfExpression): Boolean {
|
||||||
val condition = element.getCondition()
|
val condition = element.getCondition()
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.psi.JetIfExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canTransformToWhen
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.transformToWhen
|
||||||
|
import org.jetbrains.kotlin.psi.JetIfExpression
|
||||||
|
|
||||||
public class IfToWhenIntention : JetSelfTargetingIntention<JetIfExpression>("if.to.when", javaClass()) {
|
public class IfToWhenIntention : JetSelfTargetingOffsetIndependentIntention<JetIfExpression>("if.to.when", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetIfExpression): Boolean = element.canTransformToWhen()
|
override fun isApplicableTo(element: JetIfExpression): Boolean = element.canTransformToWhen()
|
||||||
|
|
||||||
override fun applyTo(element: JetIfExpression, editor: Editor) {
|
override fun applyTo(element: JetIfExpression, editor: Editor) {
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canIntroduceSubject
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceSubject
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public class IntroduceWhenSubjectIntention : JetSelfTargetingIntention<JetWhenExpression>("introduce.when.subject", javaClass()) {
|
public class IntroduceWhenSubjectIntention : JetSelfTargetingOffsetIndependentIntention<JetWhenExpression>("introduce.when.subject", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canIntroduceSubject()
|
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canIntroduceSubject()
|
||||||
|
|
||||||
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canMergeWithNext
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.mergeWithNext
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public class MergeWhenIntention : JetSelfTargetingIntention<JetWhenExpression>("merge.when", javaClass()) {
|
public class MergeWhenIntention : JetSelfTargetingOffsetIndependentIntention<JetWhenExpression>("merge.when", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canMergeWithNext()
|
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canMergeWithNext()
|
||||||
|
|
||||||
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
||||||
|
|||||||
+3
-7
@@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetSafeQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.convertToIfNotNullExpression
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.introduceValueForCondition
|
||||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStableVariable
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isStatement
|
||||||
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
public class SafeAccessToIfThenIntention : JetSelfTargetingIntention<JetSafeQualifiedExpression>("safe.access.to.if.then", javaClass()) {
|
public class SafeAccessToIfThenIntention : JetSelfTargetingOffsetIndependentIntention<JetSafeQualifiedExpression>("safe.access.to.if.then", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetSafeQualifiedExpression): Boolean = true
|
override fun isApplicableTo(element: JetSafeQualifiedExpression): Boolean = true
|
||||||
|
|
||||||
override fun applyTo(element: JetSafeQualifiedExpression, editor: Editor) {
|
override fun applyTo(element: JetSafeQualifiedExpression, editor: Editor) {
|
||||||
|
|||||||
+5
-8
@@ -16,18 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetBinaryExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils
|
||||||
import org.jetbrains.kotlin.psi.JetReturnExpression
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.UnfoldableKind
|
||||||
import org.jetbrains.kotlin.psi.JetProperty
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
public open class UnfoldBranchedExpressionIntention<T: JetExpression>(
|
public open class UnfoldBranchedExpressionIntention<T: JetExpression>(
|
||||||
val kind: UnfoldableKind, elementType: Class<T>
|
val kind: UnfoldableKind, elementType: Class<T>
|
||||||
) : JetSelfTargetingIntention<T>(kind.getKey(), elementType) {
|
) : JetSelfTargetingOffsetIndependentIntention<T>(kind.getKey(), elementType) {
|
||||||
override fun isApplicableTo(element: T): Boolean = BranchedUnfoldingUtils.getUnfoldableExpressionKind(element) == kind
|
override fun isApplicableTo(element: T): Boolean = BranchedUnfoldingUtils.getUnfoldableExpressionKind(element) == kind
|
||||||
|
|
||||||
override fun applyTo(element: T, editor: Editor) {
|
override fun applyTo(element: T, editor: Editor) {
|
||||||
|
|||||||
+5
-4
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
import org.jetbrains.kotlin.psi.JetWhenExpression
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.canTransformToIf
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.transformToIf
|
||||||
|
import org.jetbrains.kotlin.psi.JetWhenExpression
|
||||||
|
|
||||||
public class WhenToIfIntention : JetSelfTargetingIntention<JetWhenExpression>("when.to.if", javaClass()) {
|
public class WhenToIfIntention : JetSelfTargetingOffsetIndependentIntention<JetWhenExpression>("when.to.if", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canTransformToIf()
|
override fun isApplicableTo(element: JetWhenExpression): Boolean = element.canTransformToIf()
|
||||||
|
|
||||||
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
override fun applyTo(element: JetWhenExpression, editor: Editor) {
|
||||||
|
|||||||
+2
-2
@@ -17,10 +17,10 @@
|
|||||||
package org.jetbrains.kotlin.idea.intentions.declarations
|
package org.jetbrains.kotlin.idea.intentions.declarations
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention
|
||||||
import org.jetbrains.kotlin.psi.JetProperty
|
import org.jetbrains.kotlin.psi.JetProperty
|
||||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingIntention
|
|
||||||
|
|
||||||
public class SplitPropertyDeclarationIntention : JetSelfTargetingIntention<JetProperty>("split.property.declaration", javaClass()) {
|
public class SplitPropertyDeclarationIntention : JetSelfTargetingOffsetIndependentIntention<JetProperty>("split.property.declaration", javaClass()) {
|
||||||
override fun isApplicableTo(element: JetProperty): Boolean = DeclarationUtils.checkSplitProperty(element)
|
override fun isApplicableTo(element: JetProperty): Boolean = DeclarationUtils.checkSplitProperty(element)
|
||||||
|
|
||||||
override fun applyTo(element: JetProperty, editor: Editor) {
|
override fun applyTo(element: JetProperty, editor: Editor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user