i18n: make text from intention lazy
#KT-37483
This commit is contained in:
+6
-6
@@ -28,11 +28,10 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
class OperatorToFunctionIntention :
|
class OperatorToFunctionIntention : SelfTargetingIntention<KtExpression>(
|
||||||
SelfTargetingIntention<KtExpression>(
|
KtExpression::class.java,
|
||||||
KtExpression::class.java,
|
KotlinIdeaAnalysisBundle.lazyMessage("replace.overloaded.operator.with.function.call"),
|
||||||
KotlinIdeaAnalysisBundle.message("replace.overloaded.operator.with.function.call")
|
) {
|
||||||
) {
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean {
|
private fun isApplicableUnary(element: KtUnaryExpression, caretOffset: Int): Boolean {
|
||||||
if (element.baseExpression == null) return false
|
if (element.baseExpression == null) return false
|
||||||
@@ -65,7 +64,8 @@ class OperatorToFunctionIntention :
|
|||||||
return when (opRef.getReferencedNameElementType()) {
|
return when (opRef.getReferencedNameElementType()) {
|
||||||
KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE,
|
KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE,
|
||||||
KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ,
|
KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ,
|
||||||
KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ -> true
|
KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ
|
||||||
|
-> true
|
||||||
KtTokens.EQEQ, KtTokens.EXCLEQ -> listOf(element.left, element.right).none { it?.node?.elementType == KtNodeTypes.NULL }
|
KtTokens.EQEQ, KtTokens.EXCLEQ -> listOf(element.left, element.right).none { it?.node?.elementType == KtNodeTypes.NULL }
|
||||||
KtTokens.EQ -> element.left is KtArrayAccessExpression
|
KtTokens.EQ -> element.left is KtArrayAccessExpression
|
||||||
else -> false
|
else -> false
|
||||||
|
|||||||
+3
-3
@@ -30,7 +30,7 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
|
|||||||
@Nls private val familyNameGetter: () -> String = textGetter,
|
@Nls private val familyNameGetter: () -> String = textGetter,
|
||||||
) : IntentionAction {
|
) : IntentionAction {
|
||||||
|
|
||||||
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingIntention(elementType, { text }, { familyName })"))
|
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingIntention<TElement>(elementType, { text }, { familyName })"))
|
||||||
constructor(
|
constructor(
|
||||||
elementType: Class<TElement>,
|
elementType: Class<TElement>,
|
||||||
@Nls text: String,
|
@Nls text: String,
|
||||||
@@ -130,7 +130,7 @@ abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
|
|||||||
@Nls familyNameGetter: () -> String = textGetter,
|
@Nls familyNameGetter: () -> String = textGetter,
|
||||||
) : SelfTargetingIntention<TElement>(elementType, textGetter, familyNameGetter) {
|
) : SelfTargetingIntention<TElement>(elementType, textGetter, familyNameGetter) {
|
||||||
|
|
||||||
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingRangeIntention(elementType, { text }, { familyName })"))
|
@Deprecated("Replace with primary constructor", ReplaceWith("SelfTargetingRangeIntention<TElement>(elementType, { text }, { familyName })"))
|
||||||
constructor(
|
constructor(
|
||||||
elementType: Class<TElement>,
|
elementType: Class<TElement>,
|
||||||
@Nls text: String,
|
@Nls text: String,
|
||||||
@@ -153,7 +153,7 @@ abstract class SelfTargetingOffsetIndependentIntention<TElement : KtElement>(
|
|||||||
|
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"Replace with primary constructor",
|
"Replace with primary constructor",
|
||||||
ReplaceWith("SelfTargetingOffsetIndependentIntention(elementType, { text }, { familyName })")
|
ReplaceWith("SelfTargetingOffsetIndependentIntention<TElement>(elementType, { text }, { familyName })")
|
||||||
)
|
)
|
||||||
constructor(
|
constructor(
|
||||||
elementType: Class<TElement>,
|
elementType: Class<TElement>,
|
||||||
|
|||||||
@@ -2181,4 +2181,7 @@ inspection.trailing.comma.add.trailing.comma=Add trailing comma
|
|||||||
inspection.trailing.comma.missing.trailing.comma=Missing trailing comma
|
inspection.trailing.comma.missing.trailing.comma=Missing trailing comma
|
||||||
inspection.trailing.comma.fix.comma.position=Fix comma position
|
inspection.trailing.comma.fix.comma.position=Fix comma position
|
||||||
inspection.trailing.comma.comma.loses.the.advantages.in.this.position=Comma loses the advantages in this position
|
inspection.trailing.comma.comma.loses.the.advantages.in.this.position=Comma loses the advantages in this position
|
||||||
inspection.redundant.label.text=Redundant label
|
inspection.redundant.label.text=Redundant label
|
||||||
|
intention.convert.lambda.line=Convert to {0,choice,0#single|1#multi}-line lambda
|
||||||
|
intention.trailing.comma.custom.text={0,choice,0#Enable|1#Disable} a trailing comma by default in the formatter
|
||||||
|
intention.trailing.comma.text=Enable/disable a trailing comma in the formatter
|
||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -103,10 +92,10 @@ abstract class AbstractAddAccessorsIntention(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFamilyName(addGetter: Boolean, addSetter: Boolean): String = when {
|
private fun createFamilyName(addGetter: Boolean, addSetter: Boolean): () -> String = when {
|
||||||
addGetter && addSetter -> KotlinBundle.message("text.add.getter.and.setter")
|
addGetter && addSetter -> KotlinBundle.lazyMessage("text.add.getter.and.setter")
|
||||||
addGetter -> KotlinBundle.message("text.add.getter")
|
addGetter -> KotlinBundle.lazyMessage("text.add.getter")
|
||||||
addSetter -> KotlinBundle.message("text.add.setter")
|
addSetter -> KotlinBundle.lazyMessage("text.add.setter")
|
||||||
else -> throw AssertionError("At least one from (addGetter, addSetter) should be true")
|
else -> throw AssertionError("At least one from (addGetter, addSetter) should be true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -26,14 +26,15 @@ import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
|
||||||
class AddAnnotationUseSiteTargetIntention : SelfTargetingIntention<KtAnnotationEntry>(
|
class AddAnnotationUseSiteTargetIntention : SelfTargetingIntention<KtAnnotationEntry>(
|
||||||
KtAnnotationEntry::class.java, KotlinBundle.message("add.use.site.target")
|
KtAnnotationEntry::class.java,
|
||||||
|
KotlinBundle.lazyMessage("add.use.site.target")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtAnnotationEntry, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtAnnotationEntry, caretOffset: Int): Boolean {
|
||||||
val useSiteTargets = element.applicableUseSiteTargets()
|
val useSiteTargets = element.applicableUseSiteTargets()
|
||||||
if (useSiteTargets.isEmpty()) return false
|
if (useSiteTargets.isEmpty()) return false
|
||||||
if (useSiteTargets.size == 1) {
|
if (useSiteTargets.size == 1) {
|
||||||
text = KotlinBundle.message("text.add.use.site.target.0", useSiteTargets.first().renderName)
|
setTextGetter(KotlinBundle.lazyMessage("text.add.use.site.target.0", useSiteTargets.first().renderName))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -28,7 +17,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
|
|
||||||
class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("add.braces")) {
|
class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.lazyMessage("add.braces")) {
|
||||||
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
|
||||||
val expression = element.getTargetExpression(caretOffset) ?: return false
|
val expression = element.getTargetExpression(caretOffset) ?: return false
|
||||||
if (expression is KtBlockExpression) return false
|
if (expression is KtBlockExpression) return false
|
||||||
@@ -36,11 +25,11 @@ class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.ja
|
|||||||
return when (val parent = expression.parent) {
|
return when (val parent = expression.parent) {
|
||||||
is KtContainerNode -> {
|
is KtContainerNode -> {
|
||||||
val description = parent.description() ?: return false
|
val description = parent.description() ?: return false
|
||||||
text = KotlinBundle.message("add.braces.to.0.statement", description)
|
setTextGetter(KotlinBundle.lazyMessage("add.braces.to.0.statement", description))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
is KtWhenEntry -> {
|
is KtWhenEntry -> {
|
||||||
text = KotlinBundle.message("add.braces.to.when.entry")
|
setTextGetter(KotlinBundle.lazyMessage("add.braces.to.when.entry"))
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2014 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -34,9 +23,8 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
|
|
||||||
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(
|
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(
|
||||||
KtForExpression::class.java,
|
KtForExpression::class.java,
|
||||||
KotlinBundle.message("add.indices.to.for.loop")
|
KotlinBundle.lazyMessage("add.indices.to.for.loop"),
|
||||||
),
|
), LowPriorityAction {
|
||||||
LowPriorityAction {
|
|
||||||
private val WITH_INDEX_NAME = "withIndex"
|
private val WITH_INDEX_NAME = "withIndex"
|
||||||
private val WITH_INDEX_FQ_NAMES: Set<String> by lazy {
|
private val WITH_INDEX_FQ_NAMES: Set<String> by lazy {
|
||||||
sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet()
|
sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet()
|
||||||
@@ -88,8 +76,7 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(
|
|||||||
val templateBuilder = TemplateBuilderImpl(forExpression)
|
val templateBuilder = TemplateBuilderImpl(forExpression)
|
||||||
templateBuilder.replaceElement(indexVariable, ChooseStringExpression(listOf("index", "i")))
|
templateBuilder.replaceElement(indexVariable, ChooseStringExpression(listOf("index", "i")))
|
||||||
|
|
||||||
val body = forExpression.body
|
when (val body = forExpression.body) {
|
||||||
when (body) {
|
|
||||||
is KtBlockExpression -> {
|
is KtBlockExpression -> {
|
||||||
val statement = body.statements.firstOrNull()
|
val statement = body.statements.firstOrNull()
|
||||||
if (statement != null) {
|
if (statement != null) {
|
||||||
@@ -107,10 +94,9 @@ class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(
|
|||||||
templateBuilder.run(editor, true)
|
templateBuilder.run(editor, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createWithIndexExpression(originalExpression: KtExpression, reformat: Boolean): KtExpression {
|
private fun createWithIndexExpression(originalExpression: KtExpression, reformat: Boolean): KtExpression =
|
||||||
return KtPsiFactory(originalExpression).createExpressionByPattern(
|
KtPsiFactory(originalExpression).createExpressionByPattern(
|
||||||
"$0.$WITH_INDEX_NAME()", originalExpression,
|
"$0.$WITH_INDEX_NAME()", originalExpression,
|
||||||
reformat = reformat
|
reformat = reformat
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
private val annotationFqName = FqName("kotlin.jvm.JvmOverloads")
|
private val annotationFqName = FqName("kotlin.jvm.JvmOverloads")
|
||||||
|
|
||||||
class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
|
class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
|
||||||
KtModifierListOwner::class.java, KotlinBundle.message("add.jvmoverloads.annotation")
|
KtModifierListOwner::class.java,
|
||||||
|
KotlinBundle.lazyMessage("add.jvmoverloads.annotation"),
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtModifierListOwner, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtModifierListOwner, caretOffset: Int): Boolean {
|
||||||
val (targetName, parameters) = when (element) {
|
val (targetName, parameters) = when (element) {
|
||||||
is KtNamedFunction -> {
|
is KtNamedFunction -> {
|
||||||
@@ -59,7 +59,7 @@ class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
|
|||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
|
|
||||||
text = KotlinBundle.message("add.jvmoverloads.annotation.to.0", targetName)
|
setTextGetter(KotlinBundle.lazyMessage("add.jvmoverloads.annotation.to.0", targetName))
|
||||||
|
|
||||||
return TargetPlatformDetector.getPlatform(element.containingKtFile).isJvm()
|
return TargetPlatformDetector.getPlatform(element.containingKtFile).isJvm()
|
||||||
&& parameters.any { it.hasDefaultValue() }
|
&& parameters.any { it.hasDefaultValue() }
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
|||||||
|
|
||||||
class AddJvmStaticIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
|
class AddJvmStaticIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
|
||||||
KtNamedDeclaration::class.java,
|
KtNamedDeclaration::class.java,
|
||||||
KotlinBundle.message("add.jvmstatic.annotation")
|
KotlinBundle.lazyMessage("add.jvmstatic.annotation")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
private val JvmStaticFqName = FqName("kotlin.jvm.JvmStatic")
|
private val JvmStaticFqName = FqName("kotlin.jvm.JvmStatic")
|
||||||
private val JvmFieldFqName = FqName("kotlin.jvm.JvmField")
|
private val JvmFieldFqName = FqName("kotlin.jvm.JvmField")
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
|||||||
|
|
||||||
class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention<KtBlockExpression>(
|
class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention<KtBlockExpression>(
|
||||||
KtBlockExpression::class.java,
|
KtBlockExpression::class.java,
|
||||||
KotlinBundle.message("add.labeled.return.to.last.expression.in.a.lambda")
|
{ KotlinBundle.message("add.labeled.return.to.last.expression.in.a.lambda") },
|
||||||
), LowPriorityAction {
|
{ text }), LowPriorityAction {
|
||||||
override fun applicabilityRange(element: KtBlockExpression): TextRange? {
|
override fun applicabilityRange(element: KtBlockExpression): TextRange? {
|
||||||
if (!isApplicableTo(element)) return null
|
if (!isApplicableTo(element)) return null
|
||||||
val labelName = element.getParentLambdaLabelName() ?: return null
|
val labelName = element.getParentLambdaLabelName() ?: return null
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,11 +16,10 @@ import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.createDestructuringDeclarationByPattern
|
import org.jetbrains.kotlin.psi.createDestructuringDeclarationByPattern
|
||||||
|
|
||||||
class AddMissingDestructuringIntention :
|
class AddMissingDestructuringIntention : SelfTargetingIntention<KtDestructuringDeclaration>(
|
||||||
SelfTargetingIntention<KtDestructuringDeclaration>(
|
KtDestructuringDeclaration::class.java,
|
||||||
KtDestructuringDeclaration::class.java,
|
KotlinBundle.lazyMessage("add.missing.component")
|
||||||
KotlinBundle.message("add.missing.component")
|
) {
|
||||||
) {
|
|
||||||
override fun isApplicableTo(element: KtDestructuringDeclaration, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtDestructuringDeclaration, caretOffset: Int): Boolean {
|
||||||
val entriesCount = element.entries.size
|
val entriesCount = element.entries.size
|
||||||
|
|
||||||
@@ -41,16 +40,18 @@ class AddMissingDestructuringIntention :
|
|||||||
)
|
)
|
||||||
|
|
||||||
val entriesSize = entries.size
|
val entriesSize = entries.size
|
||||||
val newEntries = entries.joinToString(postfix = if (entriesSize == 0) "" else ", ") { it.text } +
|
val newEntries = entries.joinToString(postfix = if (entriesSize == 0) "" else ", ") {
|
||||||
primaryParameters.asSequence().drop(entriesSize).joinToString {
|
it.text
|
||||||
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
|
} + primaryParameters.asSequence().drop(entriesSize).joinToString {
|
||||||
}
|
KotlinNameSuggester.suggestNameByName(it.name.asString(), nameValidator)
|
||||||
val initializer = element.initializer ?: return
|
}
|
||||||
|
|
||||||
|
val initializer = element.initializer ?: return
|
||||||
val newDestructuringDeclaration = factory.createDestructuringDeclarationByPattern(
|
val newDestructuringDeclaration = factory.createDestructuringDeclarationByPattern(
|
||||||
if (element.isVar) "var ($0) = $1" else "val ($0) = $1",
|
if (element.isVar) "var ($0) = $1" else "val ($0) = $1",
|
||||||
newEntries, initializer
|
newEntries, initializer
|
||||||
)
|
)
|
||||||
|
|
||||||
element.replace(newDestructuringDeclaration)
|
element.replace(newDestructuringDeclaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -38,9 +27,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
|
||||||
|
|
||||||
class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
||||||
KtValueArgument::class.java, KotlinBundle.message("add.name.to.argument")
|
KtValueArgument::class.java, KotlinBundle.lazyMessage("add.name.to.argument")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
|
||||||
val expression = element.getArgumentExpression() ?: return false
|
val expression = element.getArgumentExpression() ?: return false
|
||||||
val name = detectNameToAdd(
|
val name = detectNameToAdd(
|
||||||
@@ -48,7 +36,7 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
|||||||
shouldBeLastUnnamed = !element.languageVersionSettings.supportsFeature(LanguageFeature.MixedNamedArgumentsInTheirOwnPosition)
|
shouldBeLastUnnamed = !element.languageVersionSettings.supportsFeature(LanguageFeature.MixedNamedArgumentsInTheirOwnPosition)
|
||||||
) ?: return false
|
) ?: return false
|
||||||
|
|
||||||
text = KotlinBundle.message("add.0.to.argument", name)
|
setTextGetter(KotlinBundle.lazyMessage("add.0.to.argument", name))
|
||||||
|
|
||||||
if (expression is KtLambdaExpression) {
|
if (expression is KtLambdaExpression) {
|
||||||
val range = expression.textRange
|
val range = expression.textRange
|
||||||
@@ -58,8 +46,9 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun allowCaretInsideElement(element: PsiElement) =
|
override fun allowCaretInsideElement(element: PsiElement) = element !is KtValueArgumentList &&
|
||||||
element !is KtValueArgumentList && element !is KtContainerNode && super.allowCaretInsideElement(element)
|
element !is KtContainerNode &&
|
||||||
|
super.allowCaretInsideElement(element)
|
||||||
|
|
||||||
override fun applyTo(element: KtValueArgument, editor: Editor?) {
|
override fun applyTo(element: KtValueArgument, editor: Editor?) {
|
||||||
apply(element)
|
apply(element)
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.psi.KtValueArgument
|
|||||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||||
|
|
||||||
class AddNamesToFollowingArgumentsIntention : SelfTargetingIntention<KtValueArgument>(
|
class AddNamesToFollowingArgumentsIntention : SelfTargetingIntention<KtValueArgument>(
|
||||||
KtValueArgument::class.java, KotlinBundle.message("add.names.to.this.argument.and.following.arguments")
|
KtValueArgument::class.java, KotlinBundle.lazyMessage("add.names.to.this.argument.and.following.arguments")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
|
||||||
val argumentList = element.parent as? KtValueArgumentList ?: return false
|
val argumentList = element.parent as? KtValueArgumentList ?: return false
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,19 +16,16 @@ import org.jetbrains.kotlin.psi.KtProperty
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
|
||||||
class AddOpenModifierIntention : SelfTargetingIntention<KtCallableDeclaration>(
|
class AddOpenModifierIntention : SelfTargetingIntention<KtCallableDeclaration>(
|
||||||
KtCallableDeclaration::class.java, KotlinBundle.message("make.open")
|
KtCallableDeclaration::class.java, KotlinBundle.lazyMessage("make.open")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtCallableDeclaration, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtCallableDeclaration, caretOffset: Int): Boolean {
|
||||||
if (element !is KtProperty && element !is KtNamedFunction) {
|
if (element !is KtProperty && element !is KtNamedFunction) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (element.hasModifier(KtTokens.OPEN_KEYWORD)
|
if (element.hasModifier(KtTokens.OPEN_KEYWORD)
|
||||||
|| element.hasModifier(KtTokens.ABSTRACT_KEYWORD)
|
|| element.hasModifier(KtTokens.ABSTRACT_KEYWORD)
|
||||||
|| element.hasModifier(KtTokens.PRIVATE_KEYWORD)
|
|| element.hasModifier(KtTokens.PRIVATE_KEYWORD)
|
||||||
) {
|
) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
val implicitModality = element.implicitModality()
|
val implicitModality = element.implicitModality()
|
||||||
if (implicitModality == KtTokens.OPEN_KEYWORD || implicitModality == KtTokens.ABSTRACT_KEYWORD) return false
|
if (implicitModality == KtTokens.OPEN_KEYWORD || implicitModality == KtTokens.ABSTRACT_KEYWORD) return false
|
||||||
val ktClassOrObject = element.containingClassOrObject ?: return false
|
val ktClassOrObject = element.containingClassOrObject ?: return false
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -27,9 +27,8 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.getAbbreviatedType
|
import org.jetbrains.kotlin.types.getAbbreviatedType
|
||||||
|
|
||||||
class AddThrowsAnnotationIntention : SelfTargetingIntention<KtThrowExpression>(
|
class AddThrowsAnnotationIntention : SelfTargetingIntention<KtThrowExpression>(
|
||||||
KtThrowExpression::class.java, KotlinBundle.message("add.throws.annotation")
|
KtThrowExpression::class.java, KotlinBundle.lazyMessage("add.throws.annotation")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtThrowExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtThrowExpression, caretOffset: Int): Boolean {
|
||||||
if (!element.platform.isJvm()) return false
|
if (!element.platform.isJvm()) return false
|
||||||
val containingDeclaration = element.getContainingDeclaration() ?: return false
|
val containingDeclaration = element.getContainingDeclaration() ?: return false
|
||||||
@@ -115,19 +114,16 @@ private fun KtDeclaration.findThrowsAnnotation(context: BindingContext): KtAnnot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ValueArgument.hasType(type: KotlinType, context: BindingContext): Boolean {
|
private fun ValueArgument.hasType(type: KotlinType, context: BindingContext): Boolean =
|
||||||
val argumentExpression = getArgumentExpression()
|
when (val argumentExpression = getArgumentExpression()) {
|
||||||
val expressions = when (argumentExpression) {
|
|
||||||
is KtClassLiteralExpression -> listOf(argumentExpression)
|
is KtClassLiteralExpression -> listOf(argumentExpression)
|
||||||
is KtCollectionLiteralExpression -> argumentExpression.getInnerExpressions().filterIsInstance(KtClassLiteralExpression::class.java)
|
is KtCollectionLiteralExpression -> argumentExpression.getInnerExpressions().filterIsInstance(KtClassLiteralExpression::class.java)
|
||||||
is KtCallExpression -> argumentExpression.valueArguments.mapNotNull { it.getArgumentExpression() as? KtClassLiteralExpression }
|
is KtCallExpression -> argumentExpression.valueArguments.mapNotNull { it.getArgumentExpression() as? KtClassLiteralExpression }
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}
|
}.any { it.getType(context)?.arguments?.firstOrNull()?.type == type }
|
||||||
return expressions.any { it.getType(context)?.arguments?.firstOrNull()?.type == type }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun KtPsiFactory.createCollectionLiteral(expressions: List<KtExpression>, lastExpression: String): KtCollectionLiteralExpression {
|
private fun KtPsiFactory.createCollectionLiteral(expressions: List<KtExpression>, lastExpression: String): KtCollectionLiteralExpression =
|
||||||
return buildExpression {
|
buildExpression {
|
||||||
appendFixedText("[")
|
appendFixedText("[")
|
||||||
expressions.forEach {
|
expressions.forEach {
|
||||||
appendExpression(it)
|
appendExpression(it)
|
||||||
@@ -135,5 +131,4 @@ private fun KtPsiFactory.createCollectionLiteral(expressions: List<KtExpression>
|
|||||||
}
|
}
|
||||||
appendFixedText(lastExpression)
|
appendFixedText(lastExpression)
|
||||||
appendFixedText("]")
|
appendFixedText("]")
|
||||||
} as KtCollectionLiteralExpression
|
} as KtCollectionLiteralExpression
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.idea.quickfix.AddWhenRemainingBranchesFix
|
|||||||
import org.jetbrains.kotlin.psi.KtWhenExpression
|
import org.jetbrains.kotlin.psi.KtWhenExpression
|
||||||
|
|
||||||
class AddWhenRemainingBranchesIntention : SelfTargetingIntention<KtWhenExpression>(
|
class AddWhenRemainingBranchesIntention : SelfTargetingIntention<KtWhenExpression>(
|
||||||
KtWhenExpression::class.java, KotlinBundle.message("add.remaining.branches")
|
KtWhenExpression::class.java, KotlinBundle.lazyMessage("add.remaining.branches")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
||||||
if (element.entries.none { it.isElse }) return false
|
if (element.entries.none { it.isElse }) return false
|
||||||
|
|||||||
+13
-12
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
|||||||
class ConvertArrayParameterToVarargIntention : SelfTargetingIntention<KtParameter>(
|
class ConvertArrayParameterToVarargIntention : SelfTargetingIntention<KtParameter>(
|
||||||
KtParameter::class.java, DEFAULT_TEXT
|
KtParameter::class.java, DEFAULT_TEXT
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
||||||
val typeReference = element.getChildOfType<KtTypeReference>() ?: return false
|
val typeReference = element.getChildOfType<KtTypeReference>() ?: return false
|
||||||
if (element.parent.parent is KtFunctionLiteral) return false
|
if (element.parent.parent is KtFunctionLiteral) return false
|
||||||
@@ -26,20 +25,22 @@ class ConvertArrayParameterToVarargIntention : SelfTargetingIntention<KtParamete
|
|||||||
val type = element.descriptor?.type ?: return false
|
val type = element.descriptor?.type ?: return false
|
||||||
return when {
|
return when {
|
||||||
KotlinBuiltIns.isPrimitiveArray(type) -> {
|
KotlinBuiltIns.isPrimitiveArray(type) -> {
|
||||||
text = DEFAULT_TEXT
|
setTextGetter(DEFAULT_TEXT)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
KotlinBuiltIns.isArray(type) -> {
|
KotlinBuiltIns.isArray(type) -> {
|
||||||
val typeArgument = typeReference.typeElement?.typeArgumentsAsTypes?.firstOrNull()
|
val typeArgument = typeReference.typeElement?.typeArgumentsAsTypes?.firstOrNull()
|
||||||
val typeProjection = typeArgument?.parent as? KtTypeProjection
|
val typeProjection = typeArgument?.parent as? KtTypeProjection
|
||||||
if (typeProjection?.hasModifier(KtTokens.IN_KEYWORD) == false) {
|
if (typeProjection?.hasModifier(KtTokens.IN_KEYWORD) == false) {
|
||||||
text = if (!typeProjection.hasModifier(KtTokens.OUT_KEYWORD)
|
setTextGetter(
|
||||||
&& !KotlinBuiltIns.isPrimitiveType(element.builtIns.getArrayElementType(type))
|
if (!typeProjection.hasModifier(KtTokens.OUT_KEYWORD)
|
||||||
) {
|
&& !KotlinBuiltIns.isPrimitiveType(element.builtIns.getArrayElementType(type))
|
||||||
BREAKING_TEXT
|
) {
|
||||||
} else {
|
BREAKING_TEXT
|
||||||
DEFAULT_TEXT
|
} else {
|
||||||
}
|
DEFAULT_TEXT
|
||||||
|
}
|
||||||
|
)
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@@ -61,9 +62,9 @@ class ConvertArrayParameterToVarargIntention : SelfTargetingIntention<KtParamete
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DEFAULT_TEXT: String get() = KotlinBundle.message("convert.to.vararg.parameter")
|
private val DEFAULT_TEXT: () -> String get() = KotlinBundle.lazyMessage("convert.to.vararg.parameter")
|
||||||
|
|
||||||
private val BREAKING_TEXT: String get() = KotlinBundle.message("0.may.break.code", DEFAULT_TEXT)
|
private val BREAKING_TEXT: () -> String get() = KotlinBundle.lazyMessage("0.may.break.code", DEFAULT_TEXT)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,11 +14,9 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
|
||||||
class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention<PsiComment>(
|
class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention<PsiComment>(
|
||||||
PsiComment::class.java, KotlinBundle.message("replace.with.end.of.line.comment")
|
PsiComment::class.java, KotlinBundle.lazyMessage("replace.with.end.of.line.comment")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean = element.isBlockComment()
|
||||||
return element.isBlockComment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: PsiComment, editor: Editor?) {
|
override fun applyTo(element: PsiComment, editor: Editor?) {
|
||||||
val psiFactory = KtPsiFactory(element)
|
val psiFactory = KtPsiFactory(element)
|
||||||
@@ -36,6 +34,7 @@ class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention<PsiComm
|
|||||||
.trim()
|
.trim()
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.reversed()
|
.reversed()
|
||||||
|
|
||||||
val lastIndex = comments.size - 1
|
val lastIndex = comments.size - 1
|
||||||
val parent = element.parent
|
val parent = element.parent
|
||||||
comments.forEachIndexed { index, comment ->
|
comments.forEachIndexed { index, comment ->
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
|
|
||||||
class ConvertCollectionConstructorToFunction : SelfTargetingIntention<KtCallExpression>(
|
class ConvertCollectionConstructorToFunction : SelfTargetingIntention<KtCallExpression>(
|
||||||
KtCallExpression::class.java, KotlinBundle.message("convert.collection.constructor.to.function")
|
KtCallExpression::class.java, KotlinBundle.lazyMessage("convert.collection.constructor.to.function")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val functionMap = hashMapOf(
|
private val functionMap = hashMapOf(
|
||||||
|
|||||||
+3
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -58,7 +47,7 @@ import org.jetbrains.kotlin.types.typeUtil.supertypes
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ConvertFunctionToPropertyIntention :
|
class ConvertFunctionToPropertyIntention :
|
||||||
SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, KotlinBundle.message("convert.function.to.property")),
|
SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, KotlinBundle.lazyMessage("convert.function.to.property")),
|
||||||
LowPriorityAction {
|
LowPriorityAction {
|
||||||
private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD"))
|
private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD"))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiComment
|
import com.intellij.psi.PsiComment
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.idea.inspections.RedundantSemicolonInspection
|
import org.jetbrains.kotlin.idea.inspections.RedundantSemicolonInspection
|
||||||
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
|
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
@@ -17,7 +18,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
||||||
|
|
||||||
sealed class ConvertLambdaLineIntention(private val toMultiLine: Boolean) : SelfTargetingIntention<KtLambdaExpression>(
|
sealed class ConvertLambdaLineIntention(private val toMultiLine: Boolean) : SelfTargetingIntention<KtLambdaExpression>(
|
||||||
KtLambdaExpression::class.java, "Convert to ${if (toMultiLine) "multi" else "single"}-line lambda"
|
KtLambdaExpression::class.java,
|
||||||
|
KotlinBundle.lazyMessage("intention.convert.lambda.line", 1.takeIf { toMultiLine } ?: 0),
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
||||||
val functionLiteral = element.functionLiteral
|
val functionLiteral = element.functionLiteral
|
||||||
|
|||||||
+6
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,14 +19,12 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||||
|
|
||||||
class ConvertLateinitPropertyToNullableIntention : SelfTargetingIntention<KtProperty>(
|
class ConvertLateinitPropertyToNullableIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java, KotlinBundle.message("convert.to.nullable.var")
|
KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.nullable.var")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = element.hasModifier(KtTokens.LATEINIT_KEYWORD)
|
||||||
return element.hasModifier(KtTokens.LATEINIT_KEYWORD)
|
&& element.isVar
|
||||||
&& element.isVar
|
&& element.typeReference?.typeElement !is KtNullableType
|
||||||
&& element.typeReference?.typeElement !is KtNullableType
|
&& element.initializer == null
|
||||||
&& element.initializer == null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: KtProperty, editor: Editor?) {
|
override fun applyTo(element: KtProperty, editor: Editor?) {
|
||||||
val typeReference: KtTypeReference = element.typeReference ?: return
|
val typeReference: KtTypeReference = element.typeReference ?: return
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
|
|
||||||
class ConvertLazyPropertyToOrdinaryIntention : SelfTargetingIntention<KtProperty>(
|
class ConvertLazyPropertyToOrdinaryIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java, KotlinBundle.message("convert.to.ordinary.property")
|
KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.ordinary.property")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
||||||
val delegateExpression = element.delegate?.expression as? KtCallExpression ?: return false
|
val delegateExpression = element.delegate?.expression as? KtCallExpression ?: return false
|
||||||
|
|||||||
+6
-11
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,12 +16,11 @@ import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
||||||
|
|
||||||
class ConvertLineCommentToBlockCommentIntention : SelfTargetingIntention<PsiComment>(
|
class ConvertLineCommentToBlockCommentIntention : SelfTargetingIntention<PsiComment>(
|
||||||
PsiComment::class.java, KotlinBundle.message("replace.with.block.comment")
|
PsiComment::class.java,
|
||||||
|
KotlinBundle.lazyMessage("replace.with.block.comment")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean = element.isEndOfLineComment()
|
||||||
return element.isEndOfLineComment()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: PsiComment, editor: Editor?) {
|
override fun applyTo(element: PsiComment, editor: Editor?) {
|
||||||
val project = element.project
|
val project = element.project
|
||||||
@@ -59,11 +58,7 @@ private fun PsiElement.isEndOfLineComment() = node.elementType == KtTokens.EOL_C
|
|||||||
|
|
||||||
private fun PsiComment.commentText() = text.substring(2).replace("/*", "/ *").replace("*/", "* /").trim()
|
private fun PsiComment.commentText() = text.substring(2).replace("/*", "/ *").replace("*/", "* /").trim()
|
||||||
|
|
||||||
private fun PsiComment.nextComment(): PsiComment? {
|
private fun PsiComment.nextComment(): PsiComment? = (getNextSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() }
|
||||||
return (getNextSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun PsiComment.prevComment(): PsiComment? {
|
private fun PsiComment.prevComment(): PsiComment? = (getPrevSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() }
|
||||||
return (getPrevSiblingIgnoringWhitespace() as? PsiComment)?.takeIf { it.isEndOfLineComment() }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.TypeUtils
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
|
|
||||||
class ConvertNullablePropertyToLateinitIntention : SelfTargetingIntention<KtProperty>(
|
class ConvertNullablePropertyToLateinitIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java, KotlinBundle.message("convert.to.lateinit.var")
|
KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.lateinit.var")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
||||||
if (element.hasModifier(KtTokens.LATEINIT_KEYWORD) || element.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return false
|
if (element.hasModifier(KtTokens.LATEINIT_KEYWORD) || element.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return false
|
||||||
|
|||||||
+5
-6
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -15,11 +15,10 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
|
|||||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||||
|
|
||||||
class ConvertOrdinaryPropertyToLazyIntention : SelfTargetingIntention<KtProperty>(
|
class ConvertOrdinaryPropertyToLazyIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java, KotlinBundle.message("convert.to.lazy.property")
|
KtProperty::class.java, KotlinBundle.lazyMessage("convert.to.lazy.property")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean =
|
||||||
return !element.isVar && element.initializer != null && element.getter == null && !element.isLocal
|
!element.isVar && element.initializer != null && element.getter == null && !element.isLocal
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: KtProperty, editor: Editor?) {
|
override fun applyTo(element: KtProperty, editor: Editor?) {
|
||||||
val initializer = element.initializer ?: return
|
val initializer = element.initializer ?: return
|
||||||
|
|||||||
+5
-17
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -31,7 +20,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
|||||||
|
|
||||||
class ConvertParameterToReceiverIntention : SelfTargetingIntention<KtParameter>(
|
class ConvertParameterToReceiverIntention : SelfTargetingIntention<KtParameter>(
|
||||||
KtParameter::class.java,
|
KtParameter::class.java,
|
||||||
KotlinBundle.message("convert.parameter.to.receiver")
|
KotlinBundle.lazyMessage("convert.parameter.to.receiver")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
||||||
val identifier = element.nameIdentifier ?: return false
|
val identifier = element.nameIdentifier ?: return false
|
||||||
@@ -41,15 +30,14 @@ class ConvertParameterToReceiverIntention : SelfTargetingIntention<KtParameter>(
|
|||||||
return function.valueParameterList == element.parent && function.receiverTypeReference == null
|
return function.valueParameterList == element.parent && function.receiverTypeReference == null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureChangeSignature(parameterIndex: Int): KotlinChangeSignatureConfiguration {
|
private fun configureChangeSignature(parameterIndex: Int): KotlinChangeSignatureConfiguration =
|
||||||
return object : KotlinChangeSignatureConfiguration {
|
object : KotlinChangeSignatureConfiguration {
|
||||||
override fun configure(originalDescriptor: KotlinMethodDescriptor): KotlinMethodDescriptor {
|
override fun configure(originalDescriptor: KotlinMethodDescriptor): KotlinMethodDescriptor {
|
||||||
return originalDescriptor.modify { it.receiver = originalDescriptor.parameters[parameterIndex] }
|
return originalDescriptor.modify { it.receiver = originalDescriptor.parameters[parameterIndex] }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun performSilently(affectedFunctions: Collection<PsiElement>) = true
|
override fun performSilently(affectedFunctions: Collection<PsiElement>) = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun startInWriteAction() = false
|
override fun startInWriteAction() = false
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parents
|
|||||||
|
|
||||||
class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtPrimaryConstructor>(
|
class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtPrimaryConstructor>(
|
||||||
KtPrimaryConstructor::class.java,
|
KtPrimaryConstructor::class.java,
|
||||||
KotlinBundle.message("convert.to.secondary.constructor")
|
KotlinBundle.lazyMessage("convert.to.secondary.constructor")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
|
||||||
val containingClass = element.containingClassOrObject as? KtClass ?: return false
|
val containingClass = element.containingClassOrObject as? KtClass ?: return false
|
||||||
@@ -38,15 +38,15 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
return element.valueParameters.all { !it.hasValOrVar() || (it.name != null && it.annotationEntries.isEmpty()) }
|
return element.valueParameters.all { !it.hasValOrVar() || (it.name != null && it.annotationEntries.isEmpty()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtReferenceExpression.isIndependent(classDescriptor: ClassDescriptor, context: BindingContext): Boolean {
|
private fun KtReferenceExpression.isIndependent(classDescriptor: ClassDescriptor, context: BindingContext): Boolean =
|
||||||
val referencedDescriptor = context[BindingContext.REFERENCE_TARGET, this] ?: return false
|
when (val referencedDescriptor = context[BindingContext.REFERENCE_TARGET, this]) {
|
||||||
return when (referencedDescriptor) {
|
null ->
|
||||||
|
false
|
||||||
is ValueParameterDescriptor ->
|
is ValueParameterDescriptor ->
|
||||||
(referencedDescriptor.containingDeclaration as? ConstructorDescriptor)?.containingDeclaration != classDescriptor
|
(referencedDescriptor.containingDeclaration as? ConstructorDescriptor)?.containingDeclaration != classDescriptor
|
||||||
else ->
|
else ->
|
||||||
classDescriptor !in referencedDescriptor.parents
|
classDescriptor !in referencedDescriptor.parents
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun KtProperty.isIndependent(klass: KtClass, context: BindingContext): Boolean {
|
private fun KtProperty.isIndependent(klass: KtClass, context: BindingContext): Boolean {
|
||||||
val propertyInitializer = initializer ?: return true
|
val propertyInitializer = initializer ?: return true
|
||||||
|
|||||||
+5
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
|
||||||
class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention<KtPropertyAccessor>(
|
class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention<KtPropertyAccessor>(
|
||||||
KtPropertyAccessor::class.java, KotlinBundle.message("convert.property.getter.to.initializer")
|
KtPropertyAccessor::class.java, KotlinBundle.lazyMessage("convert.property.getter.to.initializer")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtPropertyAccessor, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtPropertyAccessor, caretOffset: Int): Boolean {
|
||||||
@@ -41,10 +41,7 @@ class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention<KtPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtPropertyAccessor.singleExpression(): KtExpression? {
|
private fun KtPropertyAccessor.singleExpression(): KtExpression? = when (val bodyExpression = bodyExpression) {
|
||||||
val bodyExpression = this.bodyExpression
|
is KtBlockExpression -> (bodyExpression.statements.singleOrNull() as? KtReturnExpression)?.returnedExpression
|
||||||
return if (bodyExpression is KtBlockExpression)
|
else -> bodyExpression
|
||||||
(bodyExpression.statements.singleOrNull() as? KtReturnExpression)?.returnedExpression
|
|
||||||
else
|
|
||||||
bodyExpression
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-16
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -50,9 +39,8 @@ import java.util.*
|
|||||||
|
|
||||||
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(
|
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java,
|
KtProperty::class.java,
|
||||||
KotlinBundle.message("convert.property.to.function")
|
KotlinBundle.lazyMessage("convert.property.to.function")
|
||||||
),
|
), LowPriorityAction {
|
||||||
LowPriorityAction {
|
|
||||||
private inner class Converter(
|
private inner class Converter(
|
||||||
project: Project,
|
project: Project,
|
||||||
descriptor: CallableDescriptor
|
descriptor: CallableDescriptor
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -33,7 +22,8 @@ import org.jetbrains.kotlin.types.typeUtil.isNothing
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
|
|
||||||
class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody>(
|
class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody>(
|
||||||
KtDeclarationWithBody::class.java, KotlinBundle.message("convert.to.block.body")
|
KtDeclarationWithBody::class.java,
|
||||||
|
KotlinBundle.lazyMessage("convert.to.block.body")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtDeclarationWithBody, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtDeclarationWithBody, caretOffset: Int): Boolean {
|
||||||
if (element is KtFunctionLiteral || element.hasBlockBody() || !element.hasBody()) return false
|
if (element is KtFunctionLiteral || element.hasBlockBody() || !element.hasBody()) return false
|
||||||
@@ -58,7 +48,6 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun convert(declaration: KtDeclarationWithBody): KtDeclarationWithBody {
|
fun convert(declaration: KtDeclarationWithBody): KtDeclarationWithBody {
|
||||||
val body = declaration.bodyExpression!!
|
val body = declaration.bodyExpression!!
|
||||||
|
|
||||||
|
|||||||
+9
-19
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -29,7 +18,7 @@ import java.util.*
|
|||||||
|
|
||||||
class ConvertToForEachFunctionCallIntention : SelfTargetingIntention<KtForExpression>(
|
class ConvertToForEachFunctionCallIntention : SelfTargetingIntention<KtForExpression>(
|
||||||
KtForExpression::class.java,
|
KtForExpression::class.java,
|
||||||
KotlinBundle.message("replace.with.a.foreach.function.call")
|
KotlinBundle.lazyMessage("replace.with.a.foreach.function.call")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtForExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtForExpression, caretOffset: Int): Boolean {
|
||||||
val rParen = element.rightParenthesis ?: return false
|
val rParen = element.rightParenthesis ?: return false
|
||||||
@@ -42,18 +31,19 @@ class ConvertToForEachFunctionCallIntention : SelfTargetingIntention<KtForExpres
|
|||||||
|
|
||||||
val labelName = element.getLabelName()
|
val labelName = element.getLabelName()
|
||||||
|
|
||||||
val body = element.body!!
|
val body = element.body ?: return
|
||||||
val loopParameter = element.loopParameter!!
|
val loopParameter = element.loopParameter ?: return
|
||||||
|
val loopRange = element.loopRange ?: return
|
||||||
|
|
||||||
val functionBodyArgument: Any = (body as? KtBlockExpression)?.contentRange() ?: body
|
val functionBodyArgument: Any = (body as? KtBlockExpression)?.contentRange() ?: body
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(element)
|
val psiFactory = KtPsiFactory(element)
|
||||||
val foreachExpression = psiFactory.createExpressionByPattern(
|
val foreachExpression = psiFactory.createExpressionByPattern(
|
||||||
"$0.forEach{$1->\n$2}", element.loopRange!!, loopParameter, functionBodyArgument
|
"$0.forEach{$1->\n$2}", loopRange, loopParameter, functionBodyArgument
|
||||||
)
|
)
|
||||||
val result = element.replace(foreachExpression) as KtElement
|
|
||||||
|
|
||||||
result.findDescendantOfType<KtFunctionLiteral>()!!.getContinuesWithLabel(labelName).forEach {
|
val result = element.replace(foreachExpression) as KtElement
|
||||||
|
result.findDescendantOfType<KtFunctionLiteral>()?.getContinuesWithLabel(labelName)?.forEach {
|
||||||
it.replace(psiFactory.createExpression("return@forEach"))
|
it.replace(psiFactory.createExpression("return@forEach"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||||
|
|
||||||
sealed class ConvertToScopeIntention(
|
sealed class ConvertToScopeIntention(private val scopeFunction: ScopeFunction) : SelfTargetingIntention<KtExpression>(
|
||||||
private val scopeFunction: ScopeFunction
|
KtExpression::class.java,
|
||||||
) : SelfTargetingIntention<KtExpression>(KtExpression::class.java, KotlinBundle.message("convert.to.0", scopeFunction.functionName)) {
|
KotlinBundle.lazyMessage("convert.to.0", scopeFunction.functionName)
|
||||||
|
) {
|
||||||
enum class ScopeFunction(val functionName: String, val isParameterScope: Boolean) {
|
enum class ScopeFunction(val functionName: String, val isParameterScope: Boolean) {
|
||||||
ALSO(functionName = "also", isParameterScope = true),
|
ALSO(functionName = "also", isParameterScope = true),
|
||||||
APPLY(functionName = "apply", isParameterScope = false),
|
APPLY(functionName = "apply", isParameterScope = false),
|
||||||
@@ -87,8 +87,10 @@ sealed class ConvertToScopeIntention(
|
|||||||
|
|
||||||
val psiFactory = KtPsiFactory(expressionToApply)
|
val psiFactory = KtPsiFactory(expressionToApply)
|
||||||
|
|
||||||
val (scopeFunctionCall, block) =
|
val (scopeFunctionCall, block) = createScopeFunctionCall(
|
||||||
createScopeFunctionCall(psiFactory, refactoringTarget.targetElement) ?: return false
|
psiFactory,
|
||||||
|
refactoringTarget.targetElement
|
||||||
|
) ?: return false
|
||||||
|
|
||||||
replaceReference(referenceElement, refactoringTarget.targetElementValue, lastTarget, psiFactory)
|
replaceReference(referenceElement, refactoringTarget.targetElementValue, lastTarget, psiFactory)
|
||||||
|
|
||||||
@@ -110,6 +112,7 @@ sealed class ConvertToScopeIntention(
|
|||||||
val thisDotSomethingExpressions = block.collectDescendantsOfType<KtDotQualifiedExpression> {
|
val thisDotSomethingExpressions = block.collectDescendantsOfType<KtDotQualifiedExpression> {
|
||||||
it.receiverExpression is KtThisExpression && it.selectorExpression !== null
|
it.receiverExpression is KtThisExpression && it.selectorExpression !== null
|
||||||
}
|
}
|
||||||
|
|
||||||
thisDotSomethingExpressions.forEach { thisDotSomethingExpression ->
|
thisDotSomethingExpressions.forEach { thisDotSomethingExpression ->
|
||||||
thisDotSomethingExpression.selectorExpression?.let { selector ->
|
thisDotSomethingExpression.selectorExpression?.let { selector ->
|
||||||
thisDotSomethingExpression.replace(selector)
|
thisDotSomethingExpression.replace(selector)
|
||||||
@@ -211,11 +214,10 @@ sealed class ConvertToScopeIntention(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression.collectTargetElements(referenceName: String, forward: Boolean): Sequence<PsiElement> {
|
private fun KtExpression.collectTargetElements(referenceName: String, forward: Boolean): Sequence<PsiElement> =
|
||||||
return siblings(forward, withItself = false)
|
siblings(forward, withItself = false)
|
||||||
.filter { it !is PsiWhiteSpace && it !is PsiComment && !(it is LeafPsiElement && it.elementType == KtTokens.SEMICOLON) }
|
.filter { it !is PsiWhiteSpace && it !is PsiComment && !(it is LeafPsiElement && it.elementType == KtTokens.SEMICOLON) }
|
||||||
.takeWhile { it.isTarget(referenceName) }
|
.takeWhile { it.isTarget(referenceName) }
|
||||||
}
|
|
||||||
|
|
||||||
private fun PsiElement.isTarget(referenceName: String): Boolean {
|
private fun PsiElement.isTarget(referenceName: String): Boolean {
|
||||||
when (this) {
|
when (this) {
|
||||||
@@ -246,18 +248,15 @@ sealed class ConvertToScopeIntention(
|
|||||||
}
|
}
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return !anyDescendantOfType<KtNameReferenceExpression> { it.text == scopeFunction.receiver }
|
return !anyDescendantOfType<KtNameReferenceExpression> { it.text == scopeFunction.receiver }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression.prevProperty(): KtProperty? {
|
private fun KtExpression.prevProperty(): KtProperty? = PsiTreeUtil.findFirstParent(this) {
|
||||||
val blockChildExpression = PsiTreeUtil.findFirstParent(this) {
|
it.parent is KtBlockExpression
|
||||||
it.parent is KtBlockExpression
|
|
||||||
} ?: return null
|
|
||||||
|
|
||||||
return blockChildExpression
|
|
||||||
.siblings(forward = false, withItself = true)
|
|
||||||
.firstOrNull { it is KtProperty && it.isLocal } as? KtProperty
|
|
||||||
}
|
}
|
||||||
|
?.siblings(forward = false, withItself = true)
|
||||||
|
?.firstOrNull { it is KtProperty && it.isLocal } as? KtProperty
|
||||||
|
|
||||||
private fun createScopeFunctionCall(factory: KtPsiFactory, element: PsiElement): ScopedFunctionCallAndBlock? {
|
private fun createScopeFunctionCall(factory: KtPsiFactory, element: PsiElement): ScopedFunctionCallAndBlock? {
|
||||||
val scopeFunctionName = scopeFunction.functionName
|
val scopeFunctionName = scopeFunction.functionName
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ import org.jetbrains.kotlin.psi.createExpressionByPattern
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||||
|
|
||||||
class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention<KtDotQualifiedExpression>(
|
class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention<KtDotQualifiedExpression>(
|
||||||
KtDotQualifiedExpression::class.java, KotlinBundle.message("convert.to.unsafe.cast")
|
KtDotQualifiedExpression::class.java,
|
||||||
|
KotlinBundle.lazyMessage("convert.to.unsafe.cast"),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean {
|
||||||
@@ -29,7 +30,7 @@ class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention<KtDotQ
|
|||||||
|
|
||||||
val type = element.callExpression?.typeArguments?.singleOrNull() ?: return false
|
val type = element.callExpression?.typeArguments?.singleOrNull() ?: return false
|
||||||
|
|
||||||
text = KotlinBundle.message("convert.to.0.as.1", element.receiverExpression.text, type.text)
|
setTextGetter(KotlinBundle.lazyMessage("convert.to.0.as.1", element.receiverExpression.text, type.text))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
|
||||||
class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention<KtBinaryExpressionWithTypeRHS>(
|
class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention<KtBinaryExpressionWithTypeRHS>(
|
||||||
KtBinaryExpressionWithTypeRHS::class.java, KotlinBundle.message("convert.to.unsafecast.call")
|
KtBinaryExpressionWithTypeRHS::class.java,
|
||||||
|
KotlinBundle.lazyMessage("convert.to.unsafecast.call"),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtBinaryExpressionWithTypeRHS, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtBinaryExpressionWithTypeRHS, caretOffset: Int): Boolean {
|
||||||
if (!element.platform.isJs()) return false
|
if (!element.platform.isJs()) return false
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention<KtBina
|
|||||||
val type = context[BindingContext.TYPE, right] ?: return false
|
val type = context[BindingContext.TYPE, right] ?: return false
|
||||||
if (TypeUtils.isNullableType(type)) return false
|
if (TypeUtils.isNullableType(type)) return false
|
||||||
|
|
||||||
text = KotlinBundle.message("convert.to.0.unsafecast.1", element.left.text, right.text)
|
setTextGetter(KotlinBundle.lazyMessage("convert.to.0.unsafecast.1", element.left.text, right.text))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ import org.jetbrains.kotlin.psi.KtTypeReference
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||||
|
|
||||||
class ConvertVarargParameterToArrayIntention : SelfTargetingIntention<KtParameter>(
|
class ConvertVarargParameterToArrayIntention : SelfTargetingIntention<KtParameter>(
|
||||||
KtParameter::class.java, KotlinBundle.message("convert.to.array.parameter")
|
KtParameter::class.java,
|
||||||
|
KotlinBundle.lazyMessage("convert.to.array.parameter"),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
||||||
if (element.getChildOfType<KtTypeReference>() == null) return false
|
if (element.getChildOfType<KtTypeReference>() == null) return false
|
||||||
return element.isVarArg
|
return element.isVarArg
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -24,8 +24,10 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
|
||||||
|
|
||||||
class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("import.members.with")),
|
class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(
|
||||||
HighPriorityAction {
|
KtElement::class.java,
|
||||||
|
KotlinBundle.lazyMessage("import.members.with")
|
||||||
|
), HighPriorityAction {
|
||||||
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
|
||||||
val receiverExpression = element.receiverExpression() ?: return false
|
val receiverExpression = element.receiverExpression() ?: return false
|
||||||
if (!receiverExpression.range.containsOffset(caretOffset)) return false
|
if (!receiverExpression.range.containsOffset(caretOffset)) return false
|
||||||
@@ -42,13 +44,11 @@ class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::c
|
|||||||
val helper = ImportInsertHelper.getInstance(project)
|
val helper = ImportInsertHelper.getInstance(project)
|
||||||
if (helper.importDescriptor(dummyFile, target, forceAllUnderImport = true) == ImportDescriptorResult.FAIL) return false
|
if (helper.importDescriptor(dummyFile, target, forceAllUnderImport = true) == ImportDescriptorResult.FAIL) return false
|
||||||
|
|
||||||
text = KotlinBundle.message("import.members.from.0", targetFqName.parent().asString())
|
setTextGetter(KotlinBundle.lazyMessage("import.members.from.0", targetFqName.parent().asString()))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtElement, editor: Editor?) {
|
override fun applyTo(element: KtElement, editor: Editor?) = element.importReceiverMembers()
|
||||||
element.importReceiverMembers()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun KtElement.importReceiverMembers() {
|
fun KtElement.importReceiverMembers() {
|
||||||
@@ -56,12 +56,12 @@ class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::c
|
|||||||
val classFqName = target.importableFqName!!.parent()
|
val classFqName = target.importableFqName!!.parent()
|
||||||
|
|
||||||
ImportInsertHelper.getInstance(project).importDescriptor(containingKtFile, target, forceAllUnderImport = true)
|
ImportInsertHelper.getInstance(project).importDescriptor(containingKtFile, target, forceAllUnderImport = true)
|
||||||
|
|
||||||
val qualifiedExpressions = containingKtFile.collectDescendantsOfType<KtDotQualifiedExpression> { qualifiedExpression ->
|
val qualifiedExpressions = containingKtFile.collectDescendantsOfType<KtDotQualifiedExpression> { qualifiedExpression ->
|
||||||
val qualifierName = qualifiedExpression.receiverExpression.getQualifiedElementSelector() as? KtNameReferenceExpression
|
val qualifierName = qualifiedExpression.receiverExpression.getQualifiedElementSelector() as? KtNameReferenceExpression
|
||||||
qualifierName?.getReferencedNameAsName() == classFqName.shortName() && target(qualifiedExpression)?.importableFqName
|
qualifierName?.getReferencedNameAsName() == classFqName.shortName() && target(qualifiedExpression)?.importableFqName
|
||||||
?.parent() == classFqName
|
?.parent() == classFqName
|
||||||
}
|
}
|
||||||
|
|
||||||
val userTypes = containingKtFile.collectDescendantsOfType<KtUserType> { userType ->
|
val userTypes = containingKtFile.collectDescendantsOfType<KtUserType> { userType ->
|
||||||
val receiver = userType.receiverExpression()?.getQualifiedElementSelector() as? KtNameReferenceExpression
|
val receiver = userType.receiverExpression()?.getQualifiedElementSelector() as? KtNameReferenceExpression
|
||||||
receiver?.getReferencedNameAsName() == classFqName.shortName() && target(userType)?.importableFqName
|
receiver?.getReferencedNameAsName() == classFqName.shortName() && target(userType)?.importableFqName
|
||||||
@@ -77,6 +77,7 @@ class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::c
|
|||||||
if (bindingContext[BindingContext.QUALIFIER, receiverExpression] !is ClassQualifier) {
|
if (bindingContext[BindingContext.QUALIFIER, receiverExpression] !is ClassQualifier) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val selector = qualifiedElement.getQualifiedElementSelector() as? KtNameReferenceExpression ?: return null
|
val selector = qualifiedElement.getQualifiedElementSelector() as? KtNameReferenceExpression ?: return null
|
||||||
return selector.mainReference.resolveToDescriptors(bindingContext).firstOrNull()
|
return selector.mainReference.resolveToDescriptors(bindingContext).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,11 +10,10 @@ import org.jetbrains.kotlin.idea.KotlinBundle
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
class InfixCallToOrdinaryIntention :
|
class InfixCallToOrdinaryIntention : SelfTargetingIntention<KtBinaryExpression>(
|
||||||
SelfTargetingIntention<KtBinaryExpression>(
|
KtBinaryExpression::class.java,
|
||||||
KtBinaryExpression::class.java,
|
KotlinBundle.lazyMessage("replace.infix.call.with.ordinary.call")
|
||||||
KotlinBundle.message("replace.infix.call.with.ordinary.call")
|
) {
|
||||||
) {
|
|
||||||
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||||
if (element.operationToken != KtTokens.IDENTIFIER || element.left == null || element.right == null) return false
|
if (element.operationToken != KtTokens.IDENTIFIER || element.left == null || element.right == null) return false
|
||||||
return element.operationReference.textRange.containsOffset(caretOffset)
|
return element.operationReference.textRange.containsOffset(caretOffset)
|
||||||
@@ -31,8 +30,14 @@ class InfixCallToOrdinaryIntention :
|
|||||||
is KtLambdaExpression -> " $2:'{}'"
|
is KtLambdaExpression -> " $2:'{}'"
|
||||||
else -> "($2)"
|
else -> "($2)"
|
||||||
}
|
}
|
||||||
val replacement =
|
|
||||||
KtPsiFactory(element).createExpressionByPattern(pattern, element.left!!, element.operationReference.text, argument)
|
val replacement = KtPsiFactory(element).createExpressionByPattern(
|
||||||
|
pattern,
|
||||||
|
element.left!!,
|
||||||
|
element.operationReference.text,
|
||||||
|
argument
|
||||||
|
)
|
||||||
|
|
||||||
return element.replace(replacement) as KtExpression
|
return element.replace(replacement) as KtExpression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -31,16 +20,14 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
|
|
||||||
class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(
|
class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java,
|
KtProperty::class.java,
|
||||||
KotlinBundle.message("introduce.backing.property")
|
KotlinBundle.lazyMessage("introduce.backing.property")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
||||||
if (!canIntroduceBackingProperty(element)) return false
|
if (!canIntroduceBackingProperty(element)) return false
|
||||||
return element.nameIdentifier?.textRange?.containsOffset(caretOffset) == true
|
return element.nameIdentifier?.textRange?.containsOffset(caretOffset) == true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtProperty, editor: Editor?) {
|
override fun applyTo(element: KtProperty, editor: Editor?) = introduceBackingProperty(element)
|
||||||
introduceBackingProperty(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun canIntroduceBackingProperty(property: KtProperty): Boolean {
|
fun canIntroduceBackingProperty(property: KtProperty): Boolean {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
|
|||||||
|
|
||||||
class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
||||||
KtIfExpression::class.java,
|
KtIfExpression::class.java,
|
||||||
KotlinBundle.message("invert.if.condition")
|
KotlinBundle.lazyMessage("invert.if.condition")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
||||||
if (!element.ifKeyword.textRange.containsOffset(caretOffset)) return false
|
if (!element.ifKeyword.textRange.containsOffset(caretOffset)) return false
|
||||||
@@ -39,10 +39,9 @@ class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
|||||||
PsiChildRange(element, rBrace)
|
PsiChildRange(element, rBrace)
|
||||||
else
|
else
|
||||||
PsiChildRange.singleElement(element)
|
PsiChildRange.singleElement(element)
|
||||||
|
|
||||||
val commentSaver = CommentSaver(commentSavingRange)
|
val commentSaver = CommentSaver(commentSavingRange)
|
||||||
if (rBrace != null) {
|
if (rBrace != null) element.nextEolCommentOnSameLine()?.delete()
|
||||||
element.nextEolCommentOnSameLine()?.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
val condition = element.condition!!
|
val condition = element.condition!!
|
||||||
val newCondition = (condition as? KtQualifiedExpression)?.invertSelectorFunction() ?: condition.negate()
|
val newCondition = (condition as? KtQualifiedExpression)?.invertSelectorFunction() ?: condition.negate()
|
||||||
@@ -53,6 +52,7 @@ class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
|||||||
PsiChildRange(newIf, rBrace)
|
PsiChildRange(newIf, rBrace)
|
||||||
else
|
else
|
||||||
PsiChildRange(newIf, parentBlockRBrace(newIf) ?: newIf)
|
PsiChildRange(newIf, parentBlockRBrace(newIf) ?: newIf)
|
||||||
|
|
||||||
commentSaver.restore(commentRestoreRange)
|
commentSaver.restore(commentRestoreRange)
|
||||||
|
|
||||||
val newIfCondition = newIf.condition
|
val newIfCondition = newIf.condition
|
||||||
@@ -207,12 +207,13 @@ class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
|||||||
val lastStatement = parent.statements.last()
|
val lastStatement = parent.statements.last()
|
||||||
return if (expression == lastStatement) {
|
return if (expression == lastStatement) {
|
||||||
exitStatementExecutedAfter(parent)
|
exitStatementExecutedAfter(parent)
|
||||||
} else if (lastStatement.isExitStatement() && expression.siblings(withItself = false)
|
} else if (lastStatement.isExitStatement() &&
|
||||||
.firstIsInstance<KtExpression>() == lastStatement
|
expression.siblings(withItself = false).firstIsInstance<KtExpression>() == lastStatement
|
||||||
) {
|
) {
|
||||||
lastStatement
|
lastStatement
|
||||||
} else
|
} else {
|
||||||
null
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when (parent) {
|
when (parent) {
|
||||||
@@ -225,18 +226,16 @@ class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is KtContainerNode -> {
|
is KtContainerNode -> when (val pparent = parent.parent) {
|
||||||
when (val pparent = parent.parent) {
|
is KtLoopExpression -> {
|
||||||
is KtLoopExpression -> {
|
if (expression == pparent.body) {
|
||||||
if (expression == pparent.body) {
|
return KtPsiFactory(expression).createExpression("continue")
|
||||||
return KtPsiFactory(expression).createExpression("continue")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
is KtIfExpression -> {
|
is KtIfExpression -> {
|
||||||
if (expression == pparent.then || expression == pparent.`else`) {
|
if (expression == pparent.then || expression == pparent.`else`) {
|
||||||
return exitStatementExecutedAfter(pparent)
|
return exitStatementExecutedAfter(pparent)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,13 +243,10 @@ class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parentBlockRBrace(element: KtIfExpression): PsiElement? {
|
private fun parentBlockRBrace(element: KtIfExpression): PsiElement? = (element.parent as? KtBlockExpression)?.rBrace
|
||||||
return (element.parent as? KtBlockExpression)?.rBrace
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun KtIfExpression.nextEolCommentOnSameLine(): PsiElement? {
|
private fun KtIfExpression.nextEolCommentOnSameLine(): PsiElement? = getLineNumber(false).let { lastLineNumber ->
|
||||||
val lastLineNumber = getLineNumber(false)
|
siblings(withItself = false)
|
||||||
return siblings(withItself = false)
|
|
||||||
.takeWhile { it.getLineNumber() == lastLineNumber }
|
.takeWhile { it.getLineNumber() == lastLineNumber }
|
||||||
.firstOrNull { it is PsiComment && it.node.elementType == KtTokens.EOL_COMMENT }
|
.firstOrNull { it is PsiComment && it.node.elementType == KtTokens.EOL_COMMENT }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
|
|
||||||
class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(
|
class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(
|
||||||
KtExpression::class.java,
|
KtExpression::class.java,
|
||||||
KotlinBundle.message("iterate.over.collection")
|
KotlinBundle.lazyMessage("iterate.over.collection")
|
||||||
),
|
),
|
||||||
HighPriorityAction {
|
HighPriorityAction {
|
||||||
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
||||||
@@ -36,10 +36,13 @@ class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(
|
|||||||
val range = element.textRange
|
val range = element.textRange
|
||||||
if (caretOffset != range.startOffset && caretOffset != range.endOffset) return false
|
if (caretOffset != range.startOffset && caretOffset != range.endOffset) return false
|
||||||
val data = data(element) ?: return false
|
val data = data(element) ?: return false
|
||||||
text = KotlinBundle.message(
|
setTextGetter(
|
||||||
"iterate.over.0",
|
KotlinBundle.lazyMessage(
|
||||||
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType)
|
"iterate.over.0",
|
||||||
|
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
|||||||
|
|
||||||
class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpression>(
|
class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpression>(
|
||||||
KtLambdaExpression::class.java,
|
KtLambdaExpression::class.java,
|
||||||
KotlinBundle.message("convert.to.anonymous.function"),
|
KotlinBundle.lazyMessage("convert.to.anonymous.function"),
|
||||||
KotlinBundle.message("convert.lambda.expression.to.anonymous.function")
|
KotlinBundle.lazyMessage("convert.lambda.expression.to.anonymous.function")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
||||||
if (element.getStrictParentOfType<KtValueArgument>() == null) return false
|
if (element.getStrictParentOfType<KtValueArgument>() == null) return false
|
||||||
@@ -75,6 +75,7 @@ class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpres
|
|||||||
functionDescriptor.extensionReceiverParameter?.type?.let {
|
functionDescriptor.extensionReceiverParameter?.type?.let {
|
||||||
receiver(typeSourceCode.renderType(it))
|
receiver(typeSourceCode.renderType(it))
|
||||||
}
|
}
|
||||||
|
|
||||||
name(functionName)
|
name(functionName)
|
||||||
for (parameter in functionDescriptor.valueParameters) {
|
for (parameter in functionDescriptor.valueParameters) {
|
||||||
val type = parameter.type.let { if (it.isFlexible()) it.makeNotNullable() else it }
|
val type = parameter.type.let { if (it.isFlexible()) it.makeNotNullable() else it }
|
||||||
@@ -85,6 +86,7 @@ class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpres
|
|||||||
param(parameter.name.asString(), renderType)
|
param(parameter.name.asString(), renderType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
functionDescriptor.returnType?.takeIf { !it.isUnit() }?.let {
|
functionDescriptor.returnType?.takeIf { !it.isUnit() }?.let {
|
||||||
val lastStatement = bodyExpression.statements.lastOrNull()
|
val lastStatement = bodyExpression.statements.lastOrNull()
|
||||||
if (lastStatement != null && lastStatement !is KtReturnExpression) {
|
if (lastStatement != null && lastStatement !is KtReturnExpression) {
|
||||||
@@ -103,6 +105,7 @@ class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpres
|
|||||||
blockBody(" " + bodyExpression.text)
|
blockBody(" " + bodyExpression.text)
|
||||||
}.asString()
|
}.asString()
|
||||||
)
|
)
|
||||||
|
|
||||||
return replaceElement(function).also { ShortenReferences.DEFAULT.process(it) }
|
return replaceElement(function).also { ShortenReferences.DEFAULT.process(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,7 +10,10 @@ import org.jetbrains.kotlin.idea.KotlinBundle
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
|
|
||||||
class MergeElseIfIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, KotlinBundle.message("merge.else.if")) {
|
class MergeElseIfIntention : SelfTargetingIntention<KtIfExpression>(
|
||||||
|
KtIfExpression::class.java,
|
||||||
|
KotlinBundle.lazyMessage("merge.else.if")
|
||||||
|
) {
|
||||||
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
||||||
val elseBody = element.`else` ?: return false
|
val elseBody = element.`else` ?: return false
|
||||||
val nestedIf = elseBody.nestedIf() ?: return false
|
val nestedIf = elseBody.nestedIf() ?: return false
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -20,8 +9,7 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
class MergeIfsIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, KotlinBundle.message("merge.if.s")) {
|
class MergeIfsIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, KotlinBundle.lazyMessage("merge.if.s")) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
|
||||||
if (element.`else` != null) return false
|
if (element.`else` != null) return false
|
||||||
val then = element.then ?: return false
|
val then = element.then ?: return false
|
||||||
|
|||||||
+3
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -25,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtLambdaArgument
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
||||||
|
|
||||||
class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtLambdaArgument>(
|
class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtLambdaArgument>(
|
||||||
KtLambdaArgument::class.java, KotlinBundle.message("move.lambda.argument.into.parentheses")
|
KtLambdaArgument::class.java, KotlinBundle.lazyMessage("move.lambda.argument.into.parentheses")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean {
|
||||||
val body = element.getLambdaExpression()?.bodyExpression ?: return true
|
val body = element.getLambdaExpression()?.bodyExpression ?: return true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -21,17 +21,15 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
|
|
||||||
class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
|
class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
|
||||||
KtParameter::class.java,
|
KtParameter::class.java,
|
||||||
KotlinBundle.message("move.to.class.body")
|
KotlinBundle.lazyMessage("move.to.class.body")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean =
|
||||||
return element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation()
|
element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation()
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: KtParameter, editor: Editor?) {
|
override fun applyTo(element: KtParameter, editor: Editor?) {
|
||||||
val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return
|
val parentClass = PsiTreeUtil.getParentOfType(element, KtClass::class.java) ?: return
|
||||||
|
|
||||||
val propertyDeclaration = KtPsiFactory(element)
|
val propertyDeclaration = KtPsiFactory(element).createProperty("${element.valOrVarKeyword?.text} ${element.name} = ${element.name}")
|
||||||
.createProperty("${element.valOrVarKeyword?.text} ${element.name} = ${element.name}")
|
|
||||||
|
|
||||||
val firstProperty = parentClass.getProperties().firstOrNull()
|
val firstProperty = parentClass.getProperties().firstOrNull()
|
||||||
parentClass.addDeclarationBefore(propertyDeclaration, firstProperty).apply {
|
parentClass.addDeclarationBefore(propertyDeclaration, firstProperty).apply {
|
||||||
@@ -59,6 +57,7 @@ class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
|
|||||||
} else {
|
} else {
|
||||||
element.modifierList?.delete()
|
element.modifierList?.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasVararg) element.addModifier(KtTokens.VARARG_KEYWORD)
|
if (hasVararg) element.addModifier(KtTokens.VARARG_KEYWORD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-16
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -47,7 +36,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
class MovePropertyToConstructorIntention :
|
class MovePropertyToConstructorIntention :
|
||||||
SelfTargetingIntention<KtProperty>(KtProperty::class.java, KotlinBundle.message("move.to.constructor")),
|
SelfTargetingIntention<KtProperty>(KtProperty::class.java, KotlinBundle.lazyMessage("move.to.constructor")),
|
||||||
LocalQuickFix {
|
LocalQuickFix {
|
||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
@@ -102,8 +91,10 @@ class MovePropertyToConstructorIntention :
|
|||||||
commentSaver.restore(this)
|
commentSaver.restore(this)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val typeText =
|
val typeText = element.typeReference?.text
|
||||||
element.typeReference?.text ?: (element.resolveToDescriptorIfAny() as? PropertyDescriptor)?.type?.render() ?: return
|
?: (element.resolveToDescriptorIfAny() as? PropertyDescriptor)?.type?.render()
|
||||||
|
?: return
|
||||||
|
|
||||||
val parameterText = buildString {
|
val parameterText = buildString {
|
||||||
element.modifierList?.getModifiersText()?.let(this::append)
|
element.modifierList?.getModifiersText()?.let(this::append)
|
||||||
propertyAnnotationsText?.takeIf(String::isNotBlank)?.let { appendWithSpaceBefore(it) }
|
propertyAnnotationsText?.takeIf(String::isNotBlank)?.let { appendWithSpaceBefore(it) }
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.types.TypeUtils
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
|
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
|
||||||
|
|
||||||
class NullableBooleanEqualityCheckToElvisIntention : SelfTargetingIntention<KtBinaryExpression>(
|
class NullableBooleanEqualityCheckToElvisIntention : SelfTargetingIntention<KtBinaryExpression>(
|
||||||
KtBinaryExpression::class.java, KotlinBundle.message("convert.boolean.const.to.elvis")
|
KtBinaryExpression::class.java, KotlinBundle.lazyMessage("convert.boolean.const.to.elvis")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||||
if (element.operationToken != KtTokens.EQEQ && element.operationToken != KtTokens.EXCLEQ) return false
|
if (element.operationToken != KtTokens.EQEQ && element.operationToken != KtTokens.EXCLEQ) return false
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -26,8 +15,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("remove.braces")) {
|
class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.lazyMessage("remove.braces")) {
|
||||||
|
|
||||||
private fun KtElement.findChildBlock() = when (this) {
|
private fun KtElement.findChildBlock() = when (this) {
|
||||||
is KtBlockExpression -> this
|
is KtBlockExpression -> this
|
||||||
is KtLoopExpression -> body as? KtBlockExpression
|
is KtLoopExpression -> body as? KtBlockExpression
|
||||||
@@ -47,11 +35,11 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class
|
|||||||
}
|
}
|
||||||
|
|
||||||
val description = container.description() ?: return false
|
val description = container.description() ?: return false
|
||||||
text = KotlinBundle.message("remove.braces.from.0.statement", description)
|
setTextGetter(KotlinBundle.lazyMessage("remove.braces.from.0.statement", description))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
is KtWhenEntry -> {
|
is KtWhenEntry -> {
|
||||||
text = KotlinBundle.message("remove.braces.from.when.entry")
|
setTextGetter(KotlinBundle.lazyMessage("remove.braces.from.when.entry"))
|
||||||
return singleStatement !is KtNamedDeclaration
|
return singleStatement !is KtNamedDeclaration
|
||||||
}
|
}
|
||||||
else -> return false
|
else -> return false
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
|||||||
|
|
||||||
class RemoveConstructorKeywordIntention : SelfTargetingIntention<KtPrimaryConstructor>(
|
class RemoveConstructorKeywordIntention : SelfTargetingIntention<KtPrimaryConstructor>(
|
||||||
KtPrimaryConstructor::class.java,
|
KtPrimaryConstructor::class.java,
|
||||||
KotlinBundle.message("remove.constructor.keyword")
|
KotlinBundle.lazyMessage("remove.constructor.keyword")
|
||||||
) {
|
) {
|
||||||
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
|
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
|
||||||
element.removeRedundantConstructorKeywordAndSpace()
|
element.removeRedundantConstructorKeywordAndSpace()
|
||||||
|
|||||||
+6
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,11 +11,10 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
|
||||||
class RemoveExplicitLambdaParameterTypesIntention :
|
class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtLambdaExpression>(
|
||||||
SelfTargetingIntention<KtLambdaExpression>(
|
KtLambdaExpression::class.java,
|
||||||
KtLambdaExpression::class.java,
|
KotlinBundle.lazyMessage("remove.explicit.lambda.parameter.types.may.break.code")
|
||||||
KotlinBundle.message("remove.explicit.lambda.parameter.types.may.break.code")
|
) {
|
||||||
) {
|
|
||||||
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
|
||||||
if (element.valueParameters.none { it.typeReference != null }) return false
|
if (element.valueParameters.none { it.typeReference != null }) return false
|
||||||
val arrow = element.functionLiteral.arrow ?: return false
|
val arrow = element.functionLiteral.arrow ?: return false
|
||||||
@@ -28,6 +27,7 @@ class RemoveExplicitLambdaParameterTypesIntention :
|
|||||||
val parameterString = oldParameterList.parameters.asSequence().map {
|
val parameterString = oldParameterList.parameters.asSequence().map {
|
||||||
it.destructuringDeclaration?.text ?: it.name
|
it.destructuringDeclaration?.text ?: it.name
|
||||||
}.joinToString(", ")
|
}.joinToString(", ")
|
||||||
|
|
||||||
val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString)
|
val newParameterList = KtPsiFactory(element).createLambdaParameterList(parameterString)
|
||||||
oldParameterList.replace(newParameterList)
|
oldParameterList.replace(newParameterList)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
|||||||
|
|
||||||
class RemoveLabeledReturnInLambdaIntention : SelfTargetingIntention<KtReturnExpression>(
|
class RemoveLabeledReturnInLambdaIntention : SelfTargetingIntention<KtReturnExpression>(
|
||||||
KtReturnExpression::class.java,
|
KtReturnExpression::class.java,
|
||||||
KotlinBundle.message("remove.labeled.return.from.last.expression.in.a.lambda")
|
KotlinBundle.lazyMessage("remove.labeled.return.from.last.expression.in.a.lambda")
|
||||||
), LowPriorityAction {
|
), LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtReturnExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtReturnExpression, caretOffset: Int): Boolean {
|
||||||
val labelName = element.getLabelName() ?: return false
|
val labelName = element.getLabelName() ?: return false
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -29,7 +18,7 @@ internal fun KtExpression.getArguments() = when (this) {
|
|||||||
|
|
||||||
class ReplaceUntilWithRangeToIntention : SelfTargetingIntention<KtExpression>(
|
class ReplaceUntilWithRangeToIntention : SelfTargetingIntention<KtExpression>(
|
||||||
KtExpression::class.java,
|
KtExpression::class.java,
|
||||||
KotlinBundle.message("replace.with.0.operator", "..")
|
KotlinBundle.lazyMessage("replace.with.0.operator", "..")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
||||||
if (element !is KtBinaryExpression && element !is KtDotQualifiedExpression) return false
|
if (element !is KtBinaryExpression && element !is KtDotQualifiedExpression) return false
|
||||||
|
|||||||
+5
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,9 +14,10 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||||
|
|
||||||
class ReplaceWithOrdinaryAssignmentIntention :
|
class ReplaceWithOrdinaryAssignmentIntention : SelfTargetingIntention<KtBinaryExpression>(
|
||||||
SelfTargetingIntention<KtBinaryExpression>(KtBinaryExpression::class.java, KotlinBundle.message("replace.with.ordinary.assignment")),
|
KtBinaryExpression::class.java,
|
||||||
LowPriorityAction {
|
KotlinBundle.lazyMessage("replace.with.ordinary.assignment")
|
||||||
|
), LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||||
if (element.operationToken !in KtTokens.AUGMENTED_ASSIGNMENTS) return false
|
if (element.operationToken !in KtTokens.AUGMENTED_ASSIGNMENTS) return false
|
||||||
if (element.left !is KtNameReferenceExpression) return false
|
if (element.left !is KtNameReferenceExpression) return false
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
|
import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class SplitIfIntention : SelfTargetingIntention<KtExpression>(KtExpression::class.java, KotlinBundle.message("split.if.into.two")) {
|
class SplitIfIntention : SelfTargetingIntention<KtExpression>(KtExpression::class.java, KotlinBundle.lazyMessage("split.if.into.two")) {
|
||||||
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
||||||
return when (element) {
|
return when (element) {
|
||||||
is KtOperationReferenceExpression -> isOperatorValid(element)
|
is KtOperationReferenceExpression -> isOperatorValid(element)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -20,9 +20,8 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
|||||||
|
|
||||||
class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>(
|
class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>(
|
||||||
KtBinaryExpression::class.java,
|
KtBinaryExpression::class.java,
|
||||||
KotlinBundle.message("flip.binary.expression")
|
KotlinBundle.lazyMessage("flip.binary.expression")
|
||||||
),
|
), LowPriorityAction {
|
||||||
LowPriorityAction {
|
|
||||||
companion object {
|
companion object {
|
||||||
private val SUPPORTED_OPERATIONS: Set<KtSingleValueToken> by lazy {
|
private val SUPPORTED_OPERATIONS: Set<KtSingleValueToken> by lazy {
|
||||||
setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ)
|
setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ)
|
||||||
@@ -47,7 +46,7 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
|
|||||||
if (operationToken in SUPPORTED_OPERATIONS
|
if (operationToken in SUPPORTED_OPERATIONS
|
||||||
|| operationToken == IDENTIFIER && operationTokenText in SUPPORTED_OPERATION_NAMES
|
|| operationToken == IDENTIFIER && operationTokenText in SUPPORTED_OPERATION_NAMES
|
||||||
) {
|
) {
|
||||||
text = KotlinBundle.message("flip.0", operationTokenText)
|
setTextGetter(KotlinBundle.lazyMessage("flip.0", operationTokenText))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -55,16 +54,16 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
|
|||||||
|
|
||||||
override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
|
override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
|
||||||
// Have to use text here to preserve names like "plus"
|
// Have to use text here to preserve names like "plus"
|
||||||
val operator = element.operationReference.text!!
|
val convertedOperator = when (val operator = element.operationReference.text!!) {
|
||||||
val convertedOperator = when (operator) {
|
|
||||||
">" -> "<"
|
">" -> "<"
|
||||||
"<" -> ">"
|
"<" -> ">"
|
||||||
"<=" -> ">="
|
"<=" -> ">="
|
||||||
">=" -> "<="
|
">=" -> "<="
|
||||||
else -> operator
|
else -> operator
|
||||||
}
|
}
|
||||||
val left = leftSubject(element)!!
|
|
||||||
val right = rightSubject(element)!!
|
val left = leftSubject(element) ?: return
|
||||||
|
val right = rightSubject(element) ?: return
|
||||||
val rightCopy = right.copied()
|
val rightCopy = right.copied()
|
||||||
val leftCopy = left.copied()
|
val leftCopy = left.copied()
|
||||||
left.replace(rightCopy)
|
left.replace(rightCopy)
|
||||||
@@ -72,13 +71,11 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
|
|||||||
element.replace(KtPsiFactory(element).createExpressionByPattern("$0 $convertedOperator $1", element.left!!, element.right!!))
|
element.replace(KtPsiFactory(element).createExpressionByPattern("$0 $convertedOperator $1", element.left!!, element.right!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun leftSubject(element: KtBinaryExpression): KtExpression? {
|
private fun leftSubject(element: KtBinaryExpression): KtExpression? =
|
||||||
return firstDescendantOfTighterPrecedence(element.left, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getRight)
|
firstDescendantOfTighterPrecedence(element.left, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getRight)
|
||||||
}
|
|
||||||
|
|
||||||
private fun rightSubject(element: KtBinaryExpression): KtExpression? {
|
private fun rightSubject(element: KtBinaryExpression): KtExpression? =
|
||||||
return firstDescendantOfTighterPrecedence(element.right, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getLeft)
|
firstDescendantOfTighterPrecedence(element.right, PsiPrecedences.getPrecedence(element), KtBinaryExpression::getLeft)
|
||||||
}
|
|
||||||
|
|
||||||
private fun firstDescendantOfTighterPrecedence(
|
private fun firstDescendantOfTighterPrecedence(
|
||||||
expression: KtExpression?,
|
expression: KtExpression?,
|
||||||
@@ -91,6 +88,7 @@ class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpression>
|
|||||||
return firstDescendantOfTighterPrecedence(expression.getChild(), precedence, getChild)
|
return firstDescendantOfTighterPrecedence(expression.getChild(), precedence, getChild)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression
|
return expression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -27,7 +16,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
|
|
||||||
class ToInfixCallIntention : SelfTargetingIntention<KtCallExpression>(
|
class ToInfixCallIntention : SelfTargetingIntention<KtCallExpression>(
|
||||||
KtCallExpression::class.java,
|
KtCallExpression::class.java,
|
||||||
KotlinBundle.message("replace.with.infix.function.call")
|
KotlinBundle.lazyMessage("replace.with.infix.function.call")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
|
||||||
val calleeExpr = element.calleeExpression as? KtNameReferenceExpression ?: return false
|
val calleeExpr = element.calleeExpression as? KtNameReferenceExpression ?: return false
|
||||||
|
|||||||
@@ -8,21 +8,22 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.application.options.CodeStyle
|
import com.intellij.application.options.CodeStyle
|
||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings
|
import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings
|
||||||
import org.jetbrains.kotlin.idea.util.addTrailingCommaIsAllowedForThis
|
import org.jetbrains.kotlin.idea.util.addTrailingCommaIsAllowedForThis
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
|
||||||
class TrailingCommaIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, "Enable/disable a trailing comma in the formatter"),
|
class TrailingCommaIntention : SelfTargetingIntention<KtElement>(
|
||||||
LowPriorityAction {
|
KtElement::class.java,
|
||||||
|
KotlinBundle.lazyMessage("intention.trailing.comma.text")
|
||||||
|
), LowPriorityAction {
|
||||||
override fun applyTo(element: KtElement, editor: Editor?) {
|
override fun applyTo(element: KtElement, editor: Editor?) {
|
||||||
val kotlinCustomSettings = CodeStyle.getSettings(element.project).kotlinCustomSettings
|
val kotlinCustomSettings = CodeStyle.getSettings(element.project).kotlinCustomSettings
|
||||||
kotlinCustomSettings.ALLOW_TRAILING_COMMA = !kotlinCustomSettings.ALLOW_TRAILING_COMMA
|
kotlinCustomSettings.ALLOW_TRAILING_COMMA = !kotlinCustomSettings.ALLOW_TRAILING_COMMA
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean = element.addTrailingCommaIsAllowedForThis().also {
|
||||||
return element.addTrailingCommaIsAllowedForThis().also {
|
val actionNumber = 1.takeIf { CodeStyle.getSettings(element.project).kotlinCustomSettings.ALLOW_TRAILING_COMMA } ?: 0
|
||||||
val action = if (CodeStyle.getSettings(element.project).kotlinCustomSettings.ALLOW_TRAILING_COMMA) "Disable" else "Enable"
|
setTextGetter(KotlinBundle.lazyMessage("intention.trailing.comma.custom.text", actionNumber))
|
||||||
text = "$action a trailing comma by default in the formatter"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.psi.stubs.ConstantValueKind
|
|||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
||||||
|
|
||||||
class AddUnderscoresToNumericLiteralIntention : SelfTargetingIntention<KtConstantExpression>(
|
class AddUnderscoresToNumericLiteralIntention : SelfTargetingIntention<KtConstantExpression>(
|
||||||
KtConstantExpression::class.java, KotlinBundle.message("add.underscores")
|
KtConstantExpression::class.java, KotlinBundle.lazyMessage("add.underscores")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean {
|
||||||
val text = element.text
|
val text = element.text
|
||||||
@@ -32,11 +32,10 @@ class AddUnderscoresToNumericLiteralIntention : SelfTargetingIntention<KtConstan
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RemoveUnderscoresFromNumericLiteralIntention : SelfTargetingIntention<KtConstantExpression>(
|
class RemoveUnderscoresFromNumericLiteralIntention : SelfTargetingIntention<KtConstantExpression>(
|
||||||
KtConstantExpression::class.java, KotlinBundle.message("remove.underscores")
|
KtConstantExpression::class.java, KotlinBundle.lazyMessage("remove.underscores")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtConstantExpression, caretOffset: Int): Boolean =
|
||||||
return element.isNumeric() && element.text.hasUnderscore()
|
element.isNumeric() && element.text.hasUnderscore()
|
||||||
}
|
|
||||||
|
|
||||||
override fun applyTo(element: KtConstantExpression, editor: Editor?) {
|
override fun applyTo(element: KtConstantExpression, editor: Editor?) {
|
||||||
element.replace(KtPsiFactory(element).createExpression(element.text.replace("_", "")))
|
element.replace(KtPsiFactory(element).createExpression(element.text.replace("_", "")))
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
@@ -26,9 +15,8 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
|||||||
|
|
||||||
class ValToObjectIntention : SelfTargetingIntention<KtProperty>(
|
class ValToObjectIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java,
|
KtProperty::class.java,
|
||||||
KotlinBundle.message("convert.to.object.declaration")
|
KotlinBundle.lazyMessage("convert.to.object.declaration")
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
||||||
if (element.isVar) return false
|
if (element.isVar) return false
|
||||||
if (!element.isTopLevel) return false
|
if (!element.isTopLevel) return false
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.psi.buildExpression
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class EliminateWhenSubjectIntention :
|
class EliminateWhenSubjectIntention :
|
||||||
SelfTargetingIntention<KtWhenExpression>(KtWhenExpression::class.java, KotlinBundle.message("eliminate.argument.of.when")),
|
SelfTargetingIntention<KtWhenExpression>(KtWhenExpression::class.java, KotlinBundle.lazyMessage("eliminate.argument.of.when")),
|
||||||
LowPriorityAction {
|
LowPriorityAction {
|
||||||
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
||||||
if (element.subjectExpression !is KtNameReferenceExpression) return false
|
if (element.subjectExpression !is KtNameReferenceExpression) return false
|
||||||
@@ -27,7 +27,7 @@ class EliminateWhenSubjectIntention :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyTo(element: KtWhenExpression, editor: Editor?) {
|
override fun applyTo(element: KtWhenExpression, editor: Editor?) {
|
||||||
val subject = element.subjectExpression!!
|
val subject = element.subjectExpression ?: return
|
||||||
|
|
||||||
val commentSaver = CommentSaver(element, saveLineBreaks = true)
|
val commentSaver = CommentSaver(element, saveLineBreaks = true)
|
||||||
|
|
||||||
|
|||||||
+3
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
|
||||||
@@ -28,7 +17,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
|||||||
|
|
||||||
class FlattenWhenIntention : SelfTargetingIntention<KtWhenExpression>(
|
class FlattenWhenIntention : SelfTargetingIntention<KtWhenExpression>(
|
||||||
KtWhenExpression::class.java,
|
KtWhenExpression::class.java,
|
||||||
KotlinBundle.message("flatten.when.expression")
|
KotlinBundle.lazyMessage("flatten.when.expression")
|
||||||
) {
|
) {
|
||||||
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
|
||||||
val subject = element.subjectExpression
|
val subject = element.subjectExpression
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
@@ -69,15 +58,12 @@ class AddConstModifierFix(property: KtProperty) : AddModifierFix(property, KtTok
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AddConstModifierIntention : SelfTargetingIntention<KtProperty>(
|
class AddConstModifierIntention : SelfTargetingIntention<KtProperty>(
|
||||||
KtProperty::class.java, KotlinBundle.message("fix.add.const.modifier")
|
KtProperty::class.java,
|
||||||
|
KotlinBundle.lazyMessage("fix.add.const.modifier"),
|
||||||
) {
|
) {
|
||||||
override fun applyTo(element: KtProperty, editor: Editor?) {
|
override fun applyTo(element: KtProperty, editor: Editor?) = AddConstModifierFix.addConstModifier(element)
|
||||||
AddConstModifierFix.addConstModifier(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean = isApplicableTo(element)
|
||||||
return isApplicableTo(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun isApplicableTo(element: KtProperty): Boolean {
|
fun isApplicableTo(element: KtProperty): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user