i18n: add bundle for idea/intentions

This commit is contained in:
Dmitry Gridin
2020-03-10 12:39:43 +07:00
parent a3defb300a
commit c1dc72e677
149 changed files with 879 additions and 318 deletions
@@ -199,10 +199,10 @@ overridden.marker.implementations.choose.implementation.find.usages=Overriding p
overridden.marker.overrides.choose.implementation.title=Choose Super Implementation of {0}
overridden.marker.overrides.choose.implementation.find.usages=Super Implementations of {0}
remove.expression = Remove ''{0}''
unwrap.expression = Unwrap ''{0}''
remove.else = Remove else in ''{0}''
unwrap.else = Unwrap else in ''{0}''
remove.expression=Remove ''{0}''
unwrap.expression=Unwrap ''{0}''
remove.else=Remove else in ''{0}''
unwrap.else=Unwrap else in ''{0}''
override.declaration.x.in.y={0} in {1}
override.declaration.x.implements.y={0} in {1} implements {2} in {3}.
@@ -491,27 +491,27 @@ find.usages.checkbox.name.expected.properties=Expected properties
find.usages.action.text.find.usages.of=find usages of
find.usages.type.named.argument=Named argument
find.usages.type.type.alias=Type alias
find.usages.type.callable.reference = Callable reference
find.usages.type.type.constraint = Type constraint
find.usages.type.value.parameter.type = Parameter type
find.usages.type.nonLocal.property.type = Class/object property type
find.usages.type.function.return.type = Function return types
find.usages.type.superType = Supertype
find.usages.type.is = Target type of 'is' operation
find.usages.type.class.object = Nested class/object
find.usages.type.companion.object = Companion object
find.usages.type.function.call = Function call
find.usages.type.implicit.get = Implicit 'get'
find.usages.type.implicit.set = Implicit 'set'
find.usages.type.implicit.invoke = Implicit 'invoke'
find.usages.type.implicit.iteration = Implicit iteration
find.usages.type.property.delegation = Property delegation
find.usages.type.extension.receiver.type = Extension receiver type
find.usages.type.super.type.qualifier = Super type qualifier
find.usages.type.receiver = Receiver
find.usages.type.delegate = Delegate
find.usages.type.packageDirective = Package directive
find.usages.type.packageMemberAccess = Package member access
find.usages.type.callable.reference=Callable reference
find.usages.type.type.constraint=Type constraint
find.usages.type.value.parameter.type=Parameter type
find.usages.type.nonLocal.property.type=Class/object property type
find.usages.type.function.return.type=Function return types
find.usages.type.superType=Supertype
find.usages.type.is=Target type of 'is' operation
find.usages.type.class.object=Nested class/object
find.usages.type.companion.object=Companion object
find.usages.type.function.call=Function call
find.usages.type.implicit.get=Implicit 'get'
find.usages.type.implicit.set=Implicit 'set'
find.usages.type.implicit.invoke=Implicit 'invoke'
find.usages.type.implicit.iteration=Implicit iteration
find.usages.type.property.delegation=Property delegation
find.usages.type.extension.receiver.type=Extension receiver type
find.usages.type.super.type.qualifier=Super type qualifier
find.usages.type.receiver=Receiver
find.usages.type.delegate=Delegate
find.usages.type.packageDirective=Package directive
find.usages.type.packageMemberAccess=Package member access
formatter.button.text.use.import.with.when.at.least=Use import with '*' when at least
formatter.button.text.use.import.with=Use import with '*'
@@ -852,7 +852,7 @@ searching.usages.of.0.parameter=Searching usages of ''{0}''parameter
selected.code.fragment.has.multiple.exit.points=Selected code fragment has multiple exit points
selected.code.fragment.has.multiple.output.values=Selected code fragment has more than 3 output values:
selected.code.fragment.has.output.values.and.exit.points=Selected code fragment has output values as well as alternative exit points
setter.of.0.will.become.invisible.after.extraction = Setter of {0} will become invisible after extraction
setter.of.0.will.become.invisible.after.extraction=Setter of {0} will become invisible after extraction
text.0.1.must.be.moved.with.sealed.parent.class.and.all.its.subclasses={0} ''{1}'' must be moved with sealed parent class and all its subclasses
text.0.already.contains.1={0} already contains {1}
text.0.already.contains.nested.class.1={0} already contains nested class named {1}
@@ -1560,7 +1560,6 @@ constructor.has.non.null.self.reference.parameter=Constructor has non-null self
assign.backing.field.fix.text=Assign backing field
existing.backing.field.is.not.assigned.by.the.setter=Existing backing field is not assigned by the setter
replace.with.error=Replace with '?: error(...)'
replace.with.operator=Replace with '!!' operator
replace.assert.with.operator=Replace assert with operator
assert.should.be.replaced.with.operator=assert should be replaced with operator
simplify.negated.operation=Simplify negated operation
@@ -1599,4 +1598,224 @@ use.expression.body.instead.of.0=Use expression body instead of {0}
convert.to.expression.body.fix.text=Convert to expression body
when.has.only.else.branch.and.should.be.simplified='when' has only 'else' branch and should be simplified
wrap.unary.operator.quickfix.text=Wrap unary operator and value with ()
make.0.1=Make ''{0}'' {1}
make.0.1=Make ''{0}'' {1}
replace.with.0.operator=Replace with ''{0}'' operator
do.you.want.to.make.new.extension.an.expected.declaration=Do you want to make new extension an expected declaration?
loop.to.call.fix.family.name=Replace with stdlib operations
loop.to.call.fix.family.name2=Replace with stdlib operations with use of 'asSequence()'
loop.can.be.replaced.with.stdlib.operations=Loop can be replaced with stdlib operations
text.add.setter=Add setter
text.add.getter=Add getter
text.add.getter.and.setter=Add getter and setter
text.add.use.site.target.0=Add use-site target ''{0}''
choose.use.site.target=Choose use-site target
add.use.site.target=Add use-site target
add.braces.to.0.statement=Add braces to ''{0}'' statement
add.braces.to.when.entry=Add braces to 'when' entry
add.jvmoverloads.annotation.to.0=Add ''@JvmOverloads'' annotation to {0}
text.primary.constructor=primary constructor
function.0=function ''{0}''
looking.for.usages.in.java.files=Looking for usages in Java files...
add.return.at.0=Add return@{0}
add.0.to.argument=Add ''{0} ='' to argument
add.val.var.to.parameter.0=Add val/var to parameter ''{0}''
add.val.var.to.primary.constructor.parameter=Add val/var to primary constructor parameter
make.primary.constructor.0=Make primary constructor {0}
change.visibility.modifier=Change visibility modifier
0.may.break.code={0} (may break code)
convert.to.vararg.parameter=Convert to vararg parameter
replace.with=Replace '||' with '&&'
replace.with2=Replace '&&' with '||'
can.t.modify.0=Can''t modify {0}
0.already.exists={0} already exists
type.arguments.will.be.lost.after.conversion.0=Type arguments will be lost after conversion: {0}
call.with.arguments.will.be.skipped.0=Call with arguments will be skipped: {0}
looking.for.usages.and.conflicts=Looking for usages and conflicts...
following.expression.won.t.be.processed.since.refactoring.can.t.preserve.its.semantics.0=Following expression won''t be processed since refactoring can''t preserve its semantics: {0}
callable.reference.transformation.is.not.supported.0=Callable reference transformation is not supported: {0}
can.t.replace.non.kotlin.reference.with.call.expression.0=Can''t replace non-Kotlin reference with call expression: {0}
convert.0.to.1=Convert ''{0}'' to ''{1}''
convert.lambda.to.reference=Convert lambda to reference
select.target.code.block.file=Select target code block / file
select.target.file=Select target file
replace.expression.with.if.expression=Replace '!!' expression with 'if' expression
eliminate.argument.of.when=Eliminate argument of 'when'
replace.elvis.expression.with.if.expression=Replace elvis expression with 'if' expression
flatten.when.expression=Flatten 'when' expression
replace.if.expression.with.return=Replace 'if' expression with return
lift.return.out.of.if.expression=Lift return out of 'if' expression
replace.if.with.when=Replace 'if' with 'when'
replace.safe.access.expression.with.if.expression=Replace safe access expression with 'if' expression
replace.assignment.with.if.expression=Replace assignment with 'if' expression
replace.assignment.with.when.expression=Replace assignment with 'when' expression
replace.property.initializer.with.if.expression=Replace property initializer with 'if' expression
replace.property.initializer.with.when.expression=Replace property initializer with 'when' expression
replace.return.with.if.expression=Replace return with 'if' expression
replace.return.with.when.expression=Replace return with 'when' expression
replace.when.with.if=Replace 'when' with 'if'
replace.call.with.unary.operator=Replace call with unary operator
replace.contains.call.with.in.operator=Replace 'contains' call with 'in' operator
replace.invoke.with.direct.call=Replace 'invoke' with direct call
copy.concatenation.text.to.clipboard=Copy concatenation text to clipboard
split.property.declaration=Split property declaration
replace.with.stdlib.operations.with.use.of.assequence=Replace with stdlib operations with use of 'asSequence()'
replace.with.stdlib.operations=Replace with stdlib operations
use.withindex.instead.of.manual.index.increment=Use withIndex() instead of manual index increment
add.braces=Add braces
add.indices.to.for.loop=Add indices to 'for' loop
add.jvmoverloads.annotation=Add '@JvmOverloads' annotation
add.jvmstatic.annotation=Add '@JvmStatic' annotation
add.labeled.return.to.last.expression.in.a.lambda=Add labeled return to last expression in a lambda
add.missing.component=Add missing component
add.names.to.call.arguments=Add names to call arguments
add.names.to.this.argument.and.following.arguments=Add names to this argument and following arguments
add.name.to.argument=Add name to argument
make.open=Make open
add.throws.annotation=Add '@Throws' annotation
add.remaining.branches=Add remaining branches
convert.anonymous.function.to.lambda.expression=Convert anonymous function to lambda expression
convert.to.lambda.expression=Convert to lambda expression
put.arguments.on.separate.lines=Put arguments on separate lines
put.parameters.on.separate.lines=Put parameters on separate lines
demorgan.law=DeMorgan Law
replace.with.end.of.line.comment=Replace with end of line comment
convert.collection.constructor.to.function=Convert Collection constructor to function
convert.to.sealed.class=Convert to sealed class
replace.with.a.for.loop=Replace with a 'for' loop
convert.function.to.property=Convert function to property
convert.function.type.parameter.to.receiver=Convert function type parameter to receiver
convert.function.type.receiver.to.parameter=Convert function type receiver to parameter
convert.to.nullable.var=Convert to nullable var
convert.to.ordinary.property=Convert to ordinary property
replace.with.block.comment=Replace with block comment
convert.to.lateinit.var=Convert to lateinit var
convert.object.literal.to.class=Convert object literal to class
convert.to.lazy.property=Convert to lazy property
convert.parameter.to.receiver=Convert parameter to receiver
convert.to.secondary.constructor=Convert to secondary constructor
convert.property.getter.to.initializer=Convert property getter to initializer
convert.property.initializer.to.getter=Convert property initializer to getter
convert.property.to.function=Convert property to function
can.t.replace.foreign.reference.with.call.expression.0=Can''t replace foreign reference with call expression: {0}
unrecognized.reference.will.be.skipped.0=Unrecognized reference will be skipped: {0}
property.overloaded.in.child.class.constructor=Property overloaded in child class constructor
property.has.an.actual.declaration.in.the.class.constructor=Property has an actual declaration in the class constructor
convert.to.comparisons=Convert to comparisons
convert.receiver.to.parameter=Convert receiver to parameter
convert.reference.to.lambda=Convert reference to lambda
following.problems.are.found=Following problems are found:\n
all.expected.and.actual.classes.must.be.sealed.classes=All expected and actual classes must be sealed classes.\n
all.inheritors.must.be.nested.objects.of.the.class.itself.and.may.not.inherit.from.other.classes.or.interfaces=All inheritors must be nested objects of the class itself and may not inherit from other classes or interfaces.\n
searching.inheritors=Searching inheritors...
convert.to.enum.class=Convert to enum class
convert.to.primary.constructor=Convert to primary constructor
rename.to.01=Rename to {0}
replace.0.name.with.spaces=Replace {0} name with spaces
convert.to.block.body=Convert to block body
convert.template.to.concatenated.string=Convert template to concatenated string
replace.with.a.foreach.function.call=Replace with a 'forEach' function call
convert.concatenation.to.raw.string=Convert concatenation to raw string
convert.concatenation.to.template=Convert concatenation to template
convert.try.finally.to.use=Convert try-finally to .use()
convert.to.unsafe.cast=Convert to unsafe cast
convert.to.0.as.1=Convert to ''{0} as {1}''
convert.to.0.unsafecast.1=Convert to ''{0}.unsafeCast<{1}>()''
convert.to.unsafecast.call=Convert to unsafeCast() call
convert.to.array.parameter=Convert to array parameter
create.kotlin.subclass=Create Kotlin subclass
use.destructuring.declaration=Use destructuring declaration
implement.as.constructor.parameter=Implement as constructor parameter
implement.abstract.member=Implement abstract member
import.members.from.0=Import members from ''{0}''
import.members.with=Import members with '*'
add.import.for.0=Add import for ''{0}''
add.import.for.member=Add import for member
indent.raw.string=Indent raw string
replace.infix.call.with.ordinary.call=Replace infix call with ordinary call
insert.curly.braces.around.variable=Insert curly braces around variable
add.explicit.type.arguments=Add explicit type arguments
introduce.backing.property=Introduce backing property
introduce.import.alias=Introduce import alias
invert.if.condition=Invert 'if' condition
iterate.over.0=Iterate over ''{0}''
iterate.over.collection=Iterate over collection
join.declaration.and.assignment=Join declaration and assignment
can.be.joined.with.assignment=Can be joined with assignment
put.arguments.on.one.line=Put arguments on one line
put.parameters.on.one.line=Put parameters on one line
convert.lambda.expression.to.anonymous.function=Convert lambda expression to anonymous function
convert.to.anonymous.function=Convert to anonymous function
merge.else.if=Merge 'else if'
merge.if.s=Merge 'if's
move.lambda.argument.into.parentheses=Move lambda argument into parentheses
class.0.already.contains.1=Class ''{0}'' already contains {1}
0.in.1.will.require.class.instance=''{0}'' in {1} will require class instance
searching.for.0=Searching for {0}
move.out.of.companion.object=Move out of companion object
calls.with.explicit.extension.receiver.won.t.be.processed.0=Calls with explicit extension receiver won''t be processed: {0}
usages.of.outer.class.instance.inside.of.property.0.won.t.be.processed=Usages of outer class instance inside of property ''{0}'' won''t be processed
companion.object.already.contains.0=Companion object already contains {0}
0.references.type.parameters.of.the.containing.class={0} references type parameters of the containing class
0.is.overridden.by.declaration.s.in.a.subclass={0} is overridden by declaration(s) in a subclass
move.to.companion.object=Move to companion object
move.to.top.level=Move to top level
package.0.already.contains.1=Package ''{0}'' already contains {1}
move.to.class.body=Move to class body
move.to.constructor=Move to constructor
convert.boolean.const.to.elvis=Convert Boolean? == const to elvis
convert.object.literal.to.lambda=Convert object literal to lambda
convert.to.lambda=Convert to lambda
replace.by.0=Replace by ''{0}''
replace.by.reconstructed.type=Replace by reconstructed type
remove.argument.name=Remove argument name
remove.braces.from.when.entry=Remove braces from 'when' entry
remove.braces.from.0.statement=Remove braces from ''{0}'' statement
remove.braces=Remove braces
remove.constructor.keyword=Remove constructor keyword
redundant.empty.class.body=Redundant empty class body
remove.unnecessary.parentheses.from.function.call.with.lambda=Remove unnecessary parentheses from function call with lambda
remove.empty.primary.constructor=Remove empty primary constructor
remove.empty.constructor.body=Remove empty constructor body
remove.explicit.lambda.parameter.types.may.break.code=Remove explicit lambda parameter types (may break code)
remove.explicit.supertype.qualification=Remove explicit supertype qualification
remove.explicit.type.arguments=Remove explicit type arguments
remove.explicit.type.specification=Remove explicit type specification
remove.indices.in.for.loop=Remove indices in 'for' loop
index.is.not.used.in.the.loop.body=Index is not used in the loop body
remove.return.0=Remove return@{0}
remove.labeled.return.from.last.expression.in.a.lambda=Remove labeled return from last expression in a lambda
remove.redundant.calls.of.the.conversion.method=Remove redundant calls of the conversion method
remove.single.expression.string.template=Remove single-expression string template
redundant.string.template=Redundant string template
remove.unnecessary.parentheses=Remove unnecessary parentheses
rename.class.to.0=Rename class to {0}
rename.class.to.containing.file.name=Rename class to containing file name
rename.file.to.0.1=Rename file to {0}.{1}
rename.file.to.match.top.level.class.name=Rename file to match top-level class name
replace.0.with=Replace ''{0}()'' with ''+=''
replace.with1=Replace with '+='
replace.explicit.parameter.0.with.it=Replace explicit parameter ''{0}'' with ''it''
replace.it.with.explicit.parameter=Replace 'it' with explicit parameter
replace.with.0.1.2=Replace with {0}[{1}] ?: {2}
replace.with.indexing.and.elvis.operator=Replace with indexing and elvis operator
replace.size.check.with.isnotempty=Replace size check with 'isNotEmpty'
replace.size.zero.check.with.isempty=Replace size zero check with 'isEmpty'
replace.with.parameter.name=Replace '_' with parameter name
replace.with.ordinary.assignment=Replace with ordinary assignment
simplify.boolean.expression=Simplify boolean expression
specify.explicit.lambda.signature=Specify explicit lambda signature
specify.all.types.explicitly.in.destructuring.declaration=Specify all types explicitly in destructuring declaration
cannot.infer.type.for.this.declaration=Cannot infer type for this declaration
split.if.into.two=Split 'if' into two
flip.0=Flip ''{0}''
flip.binary.expression=Flip binary expression
flip.equals=Flip 'equals'
replace.with.infix.function.call=Replace with infix function call
to.ordinary.string.literal=To ordinary string literal
to.raw.string.literal=To raw string literal
remove.underscores=Remove underscores
add.underscores=Add underscores
excluded.methods=Excluded methods
use.of.0.method.instead.of.property.access.syntax=Use of {0} method instead of property access syntax
use.property.access.syntax=Use property access syntax
convert.to.object.declaration=Convert to object declaration
@@ -16,6 +16,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.psi.CREATE_BY_PATTERN_MAY_NOT_REFORMAT
import org.jetbrains.kotlin.psi.KtBlockExpression
@@ -26,13 +27,14 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
@Suppress("EqualsOrHashCode")
abstract class SelfTargetingIntention<TElement : PsiElement>(
val elementType: Class<TElement>,
private var text: String,
private val familyName: String = text
@Nls private var text: String,
@Nls private val familyName: String = text
) : IntentionAction {
@Nls
protected val defaultText: String = text
protected fun setText(text: String) {
protected fun setText(@Nls text: String) {
this.text = text
}
@@ -114,13 +116,13 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
elementType: Class<TElement>,
text: String,
familyName: String = text
@Nls text: String,
@Nls familyName: String = text
) : SelfTargetingIntention<TElement>(elementType, text, familyName) {
abstract fun applicabilityRange(element: TElement): TextRange?
override final fun isApplicableTo(element: TElement, caretOffset: Int): Boolean {
final override fun isApplicableTo(element: TElement, caretOffset: Int): Boolean {
val range = applicabilityRange(element) ?: return false
return range.containsOffset(caretOffset)
}
@@ -128,13 +130,13 @@ abstract class SelfTargetingRangeIntention<TElement : PsiElement>(
abstract class SelfTargetingOffsetIndependentIntention<TElement : KtElement>(
elementType: Class<TElement>,
text: String,
familyName: String = text
@Nls text: String,
@Nls familyName: String = text
) : SelfTargetingRangeIntention<TElement>(elementType, text, familyName) {
abstract fun isApplicableTo(element: TElement): Boolean
override final fun applicabilityRange(element: TElement): TextRange? {
final override fun applicabilityRange(element: TElement): TextRange? {
return if (isApplicableTo(element)) element.textRange else null
}
}
@@ -68,7 +68,7 @@ class SimplifyAssertNotNullInspection : AbstractApplicabilityBasedInspection<KtC
override fun fixText(element: KtCallExpression): String {
return if (element.valueArguments.size == 1) {
KotlinBundle.message("replace.with.operator")
KotlinBundle.message("replace.with.0.operator", "!!")
} else {
KotlinBundle.message("replace.with.error")
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.refactoring.isAbstract
@@ -103,9 +104,9 @@ abstract class AbstractAddAccessorsIntention(
}
private fun createFamilyName(addGetter: Boolean, addSetter: Boolean): String = when {
addGetter && addSetter -> "Add getter and setter"
addGetter -> "Add getter"
addSetter -> "Add setter"
addGetter && addSetter -> KotlinBundle.message("text.add.getter.and.setter")
addGetter -> KotlinBundle.message("text.add.getter")
addSetter -> KotlinBundle.message("text.add.setter")
else -> throw AssertionError("At least one from (addGetter, addSetter) should be true")
}
@@ -18,6 +18,7 @@ import com.intellij.util.PlatformIcons
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -25,14 +26,14 @@ import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
class AddAnnotationUseSiteTargetIntention : SelfTargetingIntention<KtAnnotationEntry>(
KtAnnotationEntry::class.java, "Add use-site target"
KtAnnotationEntry::class.java, KotlinBundle.message("add.use.site.target")
) {
override fun isApplicableTo(element: KtAnnotationEntry, caretOffset: Int): Boolean {
val useSiteTargets = element.applicableUseSiteTargets()
if (useSiteTargets.isEmpty()) return false
if (useSiteTargets.size == 1) {
text = "Add use-site target '${useSiteTargets.first().renderName}'"
text = KotlinBundle.message("text.add.use.site.target.0", useSiteTargets.first().renderName)
}
return true
}
@@ -56,7 +57,7 @@ class AddAnnotationUseSiteTargetIntention : SelfTargetingIntention<KtAnnotationE
useSiteTargets: List<AnnotationUseSiteTarget>,
project: Project
): ListPopupStep<*> {
return object : BaseListPopupStep<AnnotationUseSiteTarget>("Choose use-site target", useSiteTargets) {
return object : BaseListPopupStep<AnnotationUseSiteTarget>(KotlinBundle.message("choose.use.site.target"), useSiteTargets) {
override fun isAutoSelectionEnabled() = false
override fun onChosen(selectedValue: AnnotationUseSiteTarget, finalChoice: Boolean): PopupStep<*>? {
@@ -140,7 +141,7 @@ private fun KtAnnotationEntry.applicableUseSiteTargets(): List<AnnotationUseSite
}
fun KtAnnotationEntry.addUseSiteTarget(useSiteTarget: AnnotationUseSiteTarget, project: Project) {
project.executeWriteCommand("Add use-site target") {
project.executeWriteCommand(KotlinBundle.message("add.use.site.target")) {
replace(KtPsiFactory(this).createAnnotationEntry("@${useSiteTarget.renderName}:$shortName${valueArgumentList?.text ?: ""}"))
}
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.j2k.isInSingleLine
@@ -27,20 +28,19 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, "Add braces") {
class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("add.braces")) {
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
val expression = element.getTargetExpression(caretOffset) ?: return false
if (expression is KtBlockExpression) return false
val parent = expression.parent
return when (parent) {
return when (val parent = expression.parent) {
is KtContainerNode -> {
val description = parent.description() ?: return false
text = "Add braces to '$description' statement"
text = KotlinBundle.message("add.braces.to.0.statement", description)
true
}
is KtWhenEntry -> {
text = "Add braces to 'when' entry"
text = KotlinBundle.message("add.braces.to.when.entry")
true
}
else -> {
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
@@ -31,7 +32,10 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Add indices to 'for' loop"),
class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(
KtForExpression::class.java,
KotlinBundle.message("add.indices.to.for.loop")
),
LowPriorityAction {
private val WITH_INDEX_NAME = "withIndex"
private val WITH_INDEX_FQ_NAMES: Set<String> by lazy {
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.util.addAnnotation
import org.jetbrains.kotlin.idea.util.findAnnotation
@@ -19,7 +20,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
private val annotationFqName = FqName("kotlin.jvm.JvmOverloads")
class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
KtModifierListOwner::class.java, "Add '@JvmOverloads' annotation"
KtModifierListOwner::class.java, KotlinBundle.message("add.jvmoverloads.annotation")
), LowPriorityAction {
override fun isApplicableTo(element: KtModifierListOwner, caretOffset: Int): Boolean {
@@ -31,7 +32,7 @@ class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
return false
}
"function '${element.name}'" to valueParameterList.parameters
KotlinBundle.message("function.0", element.name.toString()) to valueParameterList.parameters
}
is KtSecondaryConstructor -> {
val constructorKeyword = element.getConstructorKeyword()
@@ -40,7 +41,7 @@ class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
return false
}
"secondary constructor" to valueParameterList.parameters
KotlinBundle.message("text.secondary.constructor") to valueParameterList.parameters
}
is KtPrimaryConstructor -> {
val parameters = (element.valueParameterList ?: return false).parameters
@@ -51,12 +52,12 @@ class AddJvmOverloadsIntention : SelfTargetingIntention<KtModifierListOwner>(
return false
}
"primary constructor" to parameters
KotlinBundle.message("text.primary.constructor") to parameters
}
else -> return false
}
text = "Add '@JvmOverloads' annotation to $targetName"
text = KotlinBundle.message("add.jvmoverloads.annotation.to.0", targetName)
return TargetPlatformDetector.getPlatform(element.containingKtFile).isJvm()
&& parameters.any { it.hasDefaultValue() }
@@ -14,6 +14,7 @@ import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.asJava.elements.KtLightField
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.search.restrictByFileType
import org.jetbrains.kotlin.idea.util.addAnnotation
@@ -31,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
class AddJvmStaticIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
KtNamedDeclaration::class.java,
"Add '@JvmStatic' annotation"
KotlinBundle.message("add.jvmstatic.annotation")
), LowPriorityAction {
private val JvmStaticFqName = FqName("kotlin.jvm.JvmStatic")
private val JvmFieldFqName = FqName("kotlin.jvm.JvmField")
@@ -63,7 +64,7 @@ class AddJvmStaticIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
val project = element.project
val expressionsToReplaceWithQualifier =
project.runSynchronouslyWithProgress("Looking for usages in Java files...", true) {
project.runSynchronouslyWithProgress(KotlinBundle.message("looking.for.usages.in.java.files"), true) {
runReadAction {
val searchScope = element.useScope.restrictByFileType(JavaFileType.INSTANCE)
ReferencesSearch
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtBlockExpression
@@ -18,13 +19,13 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention<KtBlockExpression>(
KtBlockExpression::class.java,
"Add labeled return to last expression in a lambda"
KotlinBundle.message("add.labeled.return.to.last.expression.in.a.lambda")
), LowPriorityAction {
override fun applicabilityRange(element: KtBlockExpression): TextRange? {
if (!isApplicableTo(element)) return null
val labelName = element.getParentLambdaLabelName() ?: return null
if (labelName == KtTokens.SUSPEND_KEYWORD.value) return null
text = "Add return@$labelName"
text = KotlinBundle.message("add.return.at.0", labelName)
return element.statements.lastOrNull()?.textRange
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -16,7 +17,10 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.createDestructuringDeclarationByPattern
class AddMissingDestructuringIntention :
SelfTargetingIntention<KtDestructuringDeclaration>(KtDestructuringDeclaration::class.java, "Add missing component") {
SelfTargetingIntention<KtDestructuringDeclaration>(
KtDestructuringDeclaration::class.java,
KotlinBundle.message("add.missing.component")
) {
override fun isApplicableTo(element: KtDestructuringDeclaration, caretOffset: Int): Boolean {
val entriesCount = element.entries.size
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.util.end
import org.jetbrains.kotlin.idea.core.util.start
@@ -37,7 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument
class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
KtValueArgument::class.java, "Add name to argument"
KtValueArgument::class.java, KotlinBundle.message("add.name.to.argument")
), LowPriorityAction {
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
@@ -47,7 +48,7 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
shouldBeLastUnnamed = !element.languageVersionSettings.supportsFeature(LanguageFeature.MixedNamedArgumentsInTheirOwnPosition)
) ?: return false
text = "Add '$name =' to argument"
text = KotlinBundle.message("add.0.to.argument", name)
if (expression is KtLambdaExpression) {
val range = expression.textRange
@@ -18,15 +18,19 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.KtCallElement
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.KtValueArgument
import org.jetbrains.kotlin.psi.LambdaArgument
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class AddNamesToCallArgumentsIntention : SelfTargetingRangeIntention<KtCallElement>(
KtCallElement::class.java,
"Add names to call arguments"
KotlinBundle.message("add.names.to.call.arguments")
) {
override fun applicabilityRange(element: KtCallElement): TextRange? {
val arguments = element.valueArguments
@@ -7,16 +7,17 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.util.start
import org.jetbrains.kotlin.idea.core.util.end
import org.jetbrains.kotlin.idea.core.util.start
import org.jetbrains.kotlin.psi.KtCallElement
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.KtValueArgument
import org.jetbrains.kotlin.psi.KtValueArgumentList
class AddNamesToFollowingArgumentsIntention : SelfTargetingIntention<KtValueArgument>(
KtValueArgument::class.java, "Add names to this argument and following arguments"
KtValueArgument::class.java, KotlinBundle.message("add.names.to.this.argument.and.following.arguments")
), LowPriorityAction {
override fun isApplicableTo(element: KtValueArgument, caretOffset: Int): Boolean {
val argumentList = element.parent as? KtValueArgumentList ?: return false
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.implicitModality
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtCallableDeclaration
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
class AddOpenModifierIntention : SelfTargetingIntention<KtCallableDeclaration>(
KtCallableDeclaration::class.java, "Make open"
KtCallableDeclaration::class.java, KotlinBundle.message("make.open")
), LowPriorityAction {
override fun isApplicableTo(element: KtCallableDeclaration, caretOffset: Int): Boolean {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.ShortenReferences
@@ -15,18 +16,18 @@ import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.addAnnotation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.getAbbreviatedType
class AddThrowsAnnotationIntention : SelfTargetingIntention<KtThrowExpression>(
KtThrowExpression::class.java, "Add '@Throws' annotation"
KtThrowExpression::class.java, KotlinBundle.message("add.throws.annotation")
) {
override fun isApplicableTo(element: KtThrowExpression, caretOffset: Int): Boolean {
@@ -13,6 +13,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.refactoring.ValVarExpression
@@ -25,10 +26,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
interface AddValVarToConstructorParameterAction {
companion object {
const val actionFamily = "Add val/var to primary constructor parameter"
val actionFamily: String get() = KotlinBundle.message("add.val.var.to.primary.constructor.parameter")
}
fun getActionText(element: KtParameter) = "Add val/var to parameter '${element.name ?: ""}'"
fun getActionText(element: KtParameter) = KotlinBundle.message("add.val.var.to.parameter.0", element.name ?: "")
fun canInvoke(element: KtParameter): Boolean {
return element.valOrVarKeyword == null && ((element.parent as? KtParameterList)?.parent as? KtPrimaryConstructor)
@@ -6,11 +6,12 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.quickfix.AddWhenRemainingBranchesFix
import org.jetbrains.kotlin.psi.KtWhenExpression
class AddWhenRemainingBranchesIntention : SelfTargetingIntention<KtWhenExpression>(
KtWhenExpression::class.java, "Add remaining branches"
KtWhenExpression::class.java, KotlinBundle.message("add.remaining.branches")
) {
override fun isApplicableTo(element: KtWhenExpression, caretOffset: Int): Boolean {
if (element.entries.none { it.isElse }) return false
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.getLastLambdaExpression
import org.jetbrains.kotlin.idea.core.moveFunctionLiteralOutsideParenthesesIfPossible
import org.jetbrains.kotlin.idea.core.replaced
@@ -22,8 +23,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
class AnonymousFunctionToLambdaIntention : SelfTargetingRangeIntention<KtNamedFunction>(
KtNamedFunction::class.java,
"Convert to lambda expression",
"Convert anonymous function to lambda expression"
KotlinBundle.message("convert.to.lambda.expression"),
KotlinBundle.message("convert.anonymous.function.to.lambda.expression")
) {
override fun applicabilityRange(element: KtNamedFunction): TextRange? {
if (element.name != null) return null
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.util.runCommandOnAllExpectAndActualDeclaration
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
@@ -34,7 +35,7 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
open class ChangeVisibilityModifierIntention protected constructor(
val modifier: KtModifierKeywordToken
) : SelfTargetingRangeIntention<KtDeclaration>(KtDeclaration::class.java, "Make ${modifier.value}") {
) : SelfTargetingRangeIntention<KtDeclaration>(KtDeclaration::class.java, KotlinBundle.message("make.0", modifier.value)) {
override fun startInWriteAction(): Boolean = false
override fun applicabilityRange(element: KtDeclaration): TextRange? {
@@ -62,7 +63,7 @@ open class ChangeVisibilityModifierIntention protected constructor(
if (element.isGetter) return null
if (targetVisibility == Visibilities.PUBLIC) {
val explicitVisibility = element.modifierList?.visibilityModifierType()?.value ?: return null
text = "Remove '$explicitVisibility' modifier"
text = KotlinBundle.message("remove.0.modifier", explicitVisibility)
} else {
val propVisibility = (element.property.toDescriptor() as? DeclarationDescriptorWithVisibility)?.visibility ?: return null
if (propVisibility == targetVisibility) return null
@@ -73,7 +74,7 @@ open class ChangeVisibilityModifierIntention protected constructor(
val defaultRange = noModifierYetApplicabilityRange(element) ?: return null
if (element is KtPrimaryConstructor && defaultRange.isEmpty && element.visibilityModifier() == null) {
text = "Make primary constructor ${modifier.value}" // otherwise it may be confusing
text = "${KotlinBundle.message("make.primary.constructor.0", modifier.value)}" // otherwise it may be confusing
}
return if (modifierList != null)
@@ -84,7 +85,7 @@ open class ChangeVisibilityModifierIntention protected constructor(
override fun applyTo(element: KtDeclaration, editor: Editor?) {
val factory = KtPsiFactory(element)
element.runCommandOnAllExpectAndActualDeclaration("Change visibility modifier", writeAction = true) {
element.runCommandOnAllExpectAndActualDeclaration(KotlinBundle.message("change.visibility.modifier"), writeAction = true) {
it.setVisibility(modifier)
if (it is KtPropertyAccessor) {
it.modifierList?.nextSibling?.replace(factory.createWhiteSpace())
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
@@ -98,7 +99,7 @@ abstract class AbstractChopListIntention<TList : KtElement, TElement : KtElement
class ChopParameterListIntention : AbstractChopListIntention<KtParameterList, KtParameter>(
KtParameterList::class.java,
KtParameter::class.java,
"Put parameters on separate lines"
KotlinBundle.message("put.parameters.on.separate.lines")
) {
override fun isApplicableTo(element: KtParameterList): Boolean {
if (element.parent is KtFunctionLiteral) return false
@@ -109,5 +110,5 @@ class ChopParameterListIntention : AbstractChopListIntention<KtParameterList, Kt
class ChopArgumentListIntention : AbstractChopListIntention<KtValueArgumentList, KtValueArgument>(
KtValueArgumentList::class.java,
KtValueArgument::class.java,
"Put arguments on separate lines"
KotlinBundle.message("put.arguments.on.separate.lines")
)
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.project.builtIns
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.lexer.KtTokens
@@ -60,9 +61,9 @@ class ConvertArrayParameterToVarargIntention : SelfTargetingIntention<KtParamete
}
companion object {
private const val DEFAULT_TEXT = "Convert to vararg parameter"
private val DEFAULT_TEXT: String get() = KotlinBundle.message("convert.to.vararg.parameter")
private const val BREAKING_TEXT = "$DEFAULT_TEXT (may break code)"
private val BREAKING_TEXT: String get() = KotlinBundle.message("0.may.break.code", DEFAULT_TEXT)
}
}
@@ -6,19 +6,20 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import java.util.*
class ConvertBinaryExpressionWithDemorgansLawIntention :
SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(KtBinaryExpression::class.java, "DeMorgan Law") {
SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(KtBinaryExpression::class.java, KotlinBundle.message("demorgan.law")) {
override fun isApplicableTo(element: KtBinaryExpression): Boolean {
val expr = element.parentsWithSelf.takeWhile { it is KtBinaryExpression }.last() as KtBinaryExpression
text = when (expr.operationToken) {
KtTokens.ANDAND -> "Replace '&&' with '||'"
KtTokens.OROR -> "Replace '||' with '&&'"
KtTokens.ANDAND -> KotlinBundle.message("replace.with2")
KtTokens.OROR -> KotlinBundle.message("replace.with")
else -> return false
}
@@ -9,11 +9,12 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtPsiFactory
class ConvertBlockCommentToLineCommentIntention : SelfTargetingIntention<PsiComment>(
PsiComment::class.java, "Replace with end of line comment"
PsiComment::class.java, KotlinBundle.message("replace.with.end.of.line.comment")
) {
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean {
return element.isBlockComment()
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -13,7 +14,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
class ConvertCollectionConstructorToFunction : SelfTargetingIntention<KtCallExpression>(
KtCallExpression::class.java, "Convert Collection constructor to function"
KtCallExpression::class.java, KotlinBundle.message("convert.collection.constructor.to.function")
) {
private val functionMap = hashMapOf(
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.refactoring.withExpectedActuals
import org.jetbrains.kotlin.lexer.KtTokens
@@ -18,7 +19,10 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class ConvertEnumToSealedClassIntention : SelfTargetingRangeIntention<KtClass>(KtClass::class.java, "Convert to sealed class") {
class ConvertEnumToSealedClassIntention : SelfTargetingRangeIntention<KtClass>(
KtClass::class.java,
KotlinBundle.message("convert.to.sealed.class")
) {
override fun applicabilityRange(element: KtClass): TextRange? {
if (element.getClassKeyword() == null) return null
val nameIdentifier = element.nameIdentifier ?: return null
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.psi.*
@@ -29,7 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIntention<KtSimpleNameExpression>(
KtSimpleNameExpression::class.java, "Replace with a 'for' loop"
KtSimpleNameExpression::class.java, KotlinBundle.message("replace.with.a.for.loop")
) {
companion object {
private const val FOR_EACH_NAME = "forEach"
@@ -31,6 +31,7 @@ import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
@@ -57,7 +58,8 @@ import org.jetbrains.kotlin.types.typeUtil.supertypes
import java.util.*
class ConvertFunctionToPropertyIntention :
SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, "Convert function to property"), LowPriorityAction {
SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, KotlinBundle.message("convert.function.to.property")),
LowPriorityAction {
private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD"))
private inner class Converter(
@@ -111,7 +113,7 @@ class ConvertFunctionToPropertyIntention :
if (callable !is PsiNamedElement) continue
if (!checkModifiable(callable)) {
reportDeclarationConflict(conflicts, callable) { "Can't modify $it" }
reportDeclarationConflict(conflicts, callable) { KotlinBundle.message("can.t.modify.0", it) }
}
if (callable is KtNamedFunction) {
@@ -129,7 +131,7 @@ class ConvertFunctionToPropertyIntention :
callableDescriptor.getContainingScope()
?.findVariable(callableDescriptor.name, NoLookupLocation.FROM_IDE)
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { s -> "$s already exists" } }
?.let { reportDeclarationConflict(conflicts, it) { s -> KotlinBundle.message("0.already.exists", s) } }
}
if (callable is PsiMethod) callable.checkDeclarationConflict(getterName, conflicts, callables)
@@ -143,14 +145,20 @@ class ConvertFunctionToPropertyIntention :
if (callElement.typeArguments.isNotEmpty()) {
conflicts.putValue(
callElement,
"Type arguments will be lost after conversion: ${StringUtil.htmlEmphasize(callElement.text)}"
KotlinBundle.message(
"type.arguments.will.be.lost.after.conversion.0",
StringUtil.htmlEmphasize(callElement.text)
)
)
}
if (callElement.valueArguments.isNotEmpty()) {
conflicts.putValue(
callElement,
"Call with arguments will be skipped: ${StringUtil.htmlEmphasize(callElement.text)}"
KotlinBundle.message(
"call.with.arguments.will.be.skipped.0",
StringUtil.htmlEmphasize(callElement.text)
)
)
continue
}
@@ -17,6 +17,7 @@ import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.core.*
@@ -45,7 +46,7 @@ import org.jetbrains.kotlin.types.KotlinType
class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntention<KtTypeReference>(
KtTypeReference::class.java,
"Convert function type parameter to receiver"
KotlinBundle.message("convert.function.type.parameter.to.receiver")
) {
class FunctionDefinitionInfo(element: KtFunction) : AbstractProcessableUsageInfo<KtFunction, ConversionData>(element) {
override fun process(data: ConversionData, elementsToShorten: MutableList<KtElement>) {
@@ -174,7 +175,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
val usages = ArrayList<AbstractProcessableUsageInfo<*, ConversionData>>()
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
project.runSynchronouslyWithProgress(KotlinBundle.message("looking.for.usages.and.conflicts"), true) {
runReadAction {
val progressStep = 1.0 / callables.size
for ((i, callable) in callables.withIndex()) {
@@ -184,7 +185,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
if (!checkModifiable(callable)) {
val renderedCallable = RefactoringUIUtil.getDescription(callable, true).capitalize()
conflicts.putValue(callable, "Can't modify $renderedCallable")
conflicts.putValue(callable, KotlinBundle.message("can.t.modify.0", renderedCallable))
}
usageLoop@ for (ref in callable.searchReferencesOrMethodReferences()) {
@@ -196,7 +197,10 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
if (data.isFirstParameter) continue@usageLoop
conflicts.putValue(
refElement,
"Can't replace non-Kotlin reference with call expression: " + StringUtil.htmlEmphasize(refElement.text)
KotlinBundle.message(
"can.t.replace.non.kotlin.reference.with.call.expression.0",
StringUtil.htmlEmphasize(refElement.text)
)
)
}
}
@@ -237,7 +241,10 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
) {
conflicts.putValue(
expressionToProcess,
"Following expression won't be processed since refactoring can't preserve its semantics: ${expressionToProcess.text}"
KotlinBundle.message(
"following.expression.won.t.be.processed.since.refactoring.can.t.preserve.its.semantics.0",
expressionToProcess.text
)
)
return
}
@@ -256,7 +263,10 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
if (callableReference != null) {
conflicts.putValue(
refElement,
"Callable reference transformation is not supported: " + StringUtil.htmlEmphasize(callableReference.text)
KotlinBundle.message(
"callable.reference.transformation.is.not.supported.0",
StringUtil.htmlEmphasize(callableReference.text)
)
)
return
}
@@ -281,7 +291,10 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
if (explicateReceiverOf(descriptor) == "this") {
conflicts.putValue(
thisExpr,
"Following expression won't be processed since refactoring can't preserve its semantics: ${thisExpr.text}"
KotlinBundle.message(
"following.expression.won.t.be.processed.since.refactoring.can.t.preserve.its.semantics.0",
thisExpr.text
)
)
return false
}
@@ -291,7 +304,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
private fun processInternalUsages(callable: KtFunction, usages: ArrayList<AbstractProcessableUsageInfo<*, ConversionData>>) {
val body = when (callable) {
is KtConstructor<*> -> callable.containingClassOrObject?.getBody()
is KtConstructor<*> -> callable.containingClassOrObject?.body
else -> callable.bodyExpression
}
if (body != null) {
@@ -341,7 +354,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
setReceiverTypeReference(element)
parameterList!!.removeParameter(data.typeParameterIndex)
}
text = "Convert '${elementBefore.text}' to '${elementAfter.text}'"
text = KotlinBundle.message("convert.0.to.1", elementBefore.text, elementAfter.text)
return element.textRange
}
@@ -27,6 +27,7 @@ import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
@@ -50,7 +51,7 @@ import org.jetbrains.kotlin.types.KotlinType
class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntention<KtTypeReference>(
KtTypeReference::class.java,
"Convert function type receiver to parameter"
KotlinBundle.message("convert.function.type.receiver.to.parameter")
) {
class ConversionData(
val functionParameterIndex: Int,
@@ -121,7 +122,7 @@ class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntent
val usages = ArrayList<AbstractProcessableUsageInfo<*, ConversionData>>()
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
project.runSynchronouslyWithProgress(KotlinBundle.message("looking.for.usages.and.conflicts"), true) {
runReadAction {
val progressStep = 1.0 / callables.size
for ((i, callable) in callables.withIndex()) {
@@ -131,7 +132,7 @@ class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntent
if (!checkModifiable(callable)) {
val renderedCallable = RefactoringUIUtil.getDescription(callable, true).capitalize()
conflicts.putValue(callable, "Can't modify $renderedCallable")
conflicts.putValue(callable, KotlinBundle.message("can.t.modify.0", renderedCallable))
}
for (ref in callable.searchReferencesOrMethodReferences()) {
@@ -177,7 +178,7 @@ class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntent
usages: java.util.ArrayList<AbstractProcessableUsageInfo<*, ConversionData>>
) {
val body = when (callable) {
is KtConstructor<*> -> callable.containingClassOrObject?.getBody()
is KtConstructor<*> -> callable.containingClassOrObject?.body
else -> callable.bodyExpression
}
if (body != null) {
@@ -217,7 +218,7 @@ class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntent
)
setReceiverTypeReference(null)
}
text = "Convert '${elementBefore.text}' to '${elementAfter.text}'"
text = KotlinBundle.message("convert.0.to.1", elementBefore.text, elementAfter.text)
return element.textRange
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.ShortenReferences
@@ -44,7 +45,7 @@ open class ConvertLambdaToReferenceIntention(text: String) :
SelfTargetingOffsetIndependentIntention<KtLambdaExpression>(KtLambdaExpression::class.java, text) {
@Suppress("unused")
constructor() : this("Convert lambda to reference")
constructor() : this(KotlinBundle.message("convert.lambda.to.reference"))
open fun buildReferenceText(element: KtLambdaExpression) = buildReferenceText(lambdaExpression = element, shortTypes = false)
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.setType
import org.jetbrains.kotlin.lexer.KtTokens
@@ -18,7 +19,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.typeUtil.makeNullable
class ConvertLateinitPropertyToNullableIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java, "Convert to nullable var"
KtProperty::class.java, KotlinBundle.message("convert.to.nullable.var")
) {
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
return element.hasModifier(KtTokens.LATEINIT_KEYWORD)
@@ -7,13 +7,14 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.collections.isCalling
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
class ConvertLazyPropertyToOrdinaryIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java, "Convert to ordinary property"
KtProperty::class.java, KotlinBundle.message("convert.to.ordinary.property")
) {
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
val delegateExpression = element.delegate?.expression as? KtCallExpression ?: return false
@@ -9,13 +9,14 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
class ConvertLineCommentToBlockCommentIntention : SelfTargetingIntention<PsiComment>(
PsiComment::class.java, "Replace with block comment"
PsiComment::class.java, KotlinBundle.message("replace.with.block.comment")
) {
override fun isApplicableTo(element: PsiComment, caretOffset: Int): Boolean {
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.setType
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression
@@ -25,7 +26,7 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
class ConvertNullablePropertyToLateinitIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java, "Convert to lateinit var"
KtProperty::class.java, KotlinBundle.message("convert.to.lateinit.var")
) {
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
if (element.hasModifier(KtTokens.LATEINIT_KEYWORD) || element.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return false
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.refactoring.chooseContainerElementIfNecessary
@@ -43,7 +44,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
class ConvertObjectLiteralToClassIntention : SelfTargetingRangeIntention<KtObjectLiteralExpression>(
KtObjectLiteralExpression::class.java,
"Convert object literal to class"
KotlinBundle.message("convert.object.literal.to.class")
) {
override fun applicabilityRange(element: KtObjectLiteralExpression) = element.objectDeclaration.getObjectKeyword()?.textRange
@@ -68,7 +69,7 @@ class ConvertObjectLiteralToClassIntention : SelfTargetingRangeIntention<KtObjec
val objectDeclaration = element.objectDeclaration
val containingClass = element.containingClass()
val hasMemberReference = containingClass?.getBody()?.allChildren?.any {
val hasMemberReference = containingClass?.body?.allChildren?.any {
(it is KtProperty || it is KtNamedFunction) &&
ReferencesSearch.search(it, element.useScope).findFirst() != null
} ?: false
@@ -78,7 +79,7 @@ class ConvertObjectLiteralToClassIntention : SelfTargetingRangeIntention<KtObjec
newClass.add(psiFactory.createColon())
newClass.add(it)
}
objectDeclaration.getBody()?.let {
objectDeclaration.body?.let {
newClass.add(it)
}
@@ -148,7 +149,7 @@ class ConvertObjectLiteralToClassIntention : SelfTargetingRangeIntention<KtObjec
chooseContainerElementIfNecessary(
containers,
editor,
if (containers.first() is KtFile) "Select target file" else "Select target code block / file",
if (containers.first() is KtFile) KotlinBundle.message("select.target.file") else KotlinBundle.message("select.target.code.block.file"),
true,
{ it },
{ doApply(editor, element, it) }
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.collections.isCalling
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtCallExpression
@@ -14,7 +15,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.createExpressionByPattern
class ConvertOrdinaryPropertyToLazyIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java, "Convert to lazy property"
KtProperty::class.java, KotlinBundle.message("convert.to.lazy.property")
) {
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
return !element.isVar && element.initializer != null && element.getter == null && !element.isLocal
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinChangeSignatureConfiguration
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor
import org.jetbrains.kotlin.idea.refactoring.changeSignature.modify
@@ -28,7 +29,10 @@ import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
class ConvertParameterToReceiverIntention : SelfTargetingIntention<KtParameter>(KtParameter::class.java, "Convert parameter to receiver") {
class ConvertParameterToReceiverIntention : SelfTargetingIntention<KtParameter>(
KtParameter::class.java,
KotlinBundle.message("convert.parameter.to.receiver")
) {
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
val identifier = element.nameIdentifier ?: return false
if (!identifier.textRange.containsOffset(caretOffset)) return false
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.lexer.KtTokens
@@ -27,7 +28,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parents
class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtPrimaryConstructor>(
KtPrimaryConstructor::class.java,
"Convert to secondary constructor"
KotlinBundle.message("convert.to.secondary.constructor")
) {
override fun isApplicableTo(element: KtPrimaryConstructor, caretOffset: Int): Boolean {
val containingClass = element.containingClassOrObject as? KtClass ?: return false
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.psi.*
@@ -14,7 +15,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClass
import org.jetbrains.kotlin.psi.psiUtil.endOffset
class ConvertPropertyGetterToInitializerIntention : SelfTargetingIntention<KtPropertyAccessor>(
KtPropertyAccessor::class.java, "Convert property getter to initializer"
KtPropertyAccessor::class.java, KotlinBundle.message("convert.property.getter.to.initializer")
) {
override fun isApplicableTo(element: KtPropertyAccessor, caretOffset: Int): Boolean {
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
import org.jetbrains.kotlin.psi.KtDeclaration
@@ -32,7 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.types.isError
class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention<KtProperty>(
KtProperty::class.java, "Convert property initializer to getter"
KtProperty::class.java, KotlinBundle.message("convert.property.initializer.to.getter")
) {
override fun applicabilityRange(element: KtProperty): TextRange? {
val initializer = element.initializer ?: return null
@@ -26,13 +26,14 @@ import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.refactoring.*
import org.jetbrains.kotlin.idea.references.KtReference
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
@@ -47,7 +48,10 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.utils.findFunction
import java.util.*
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(KtProperty::class.java, "Convert property to function"),
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java,
KotlinBundle.message("convert.property.to.function")
),
LowPriorityAction {
private inner class Converter(
project: Project,
@@ -102,7 +106,7 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
val refsToRename = ArrayList<PsiReference>()
val javaRefsToReplaceWithCall = ArrayList<PsiReferenceExpression>()
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
project.runSynchronouslyWithProgress(KotlinBundle.message("looking.for.usages.and.conflicts"), true) {
runReadAction {
val progressStep = 1.0 / callables.size
for ((i, callable) in callables.withIndex()) {
@@ -112,14 +116,14 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
if (!checkModifiable(callable)) {
val renderedCallable = RefactoringUIUtil.getDescription(callable, true).capitalize()
conflicts.putValue(callable, "Can't modify $renderedCallable")
conflicts.putValue(callable, KotlinBundle.message("can.t.modify.0", renderedCallable))
}
if (callable is KtParameter) {
conflicts.putValue(
callable,
if (callable.hasActualModifier()) "Property has an actual declaration in the class constructor"
else "Property overloaded in child class constructor"
if (callable.hasActualModifier()) KotlinBundle.message("property.has.an.actual.declaration.in.the.class.constructor")
else KotlinBundle.message("property.overloaded.in.child.class.constructor")
)
}
@@ -127,7 +131,7 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
callableDescriptor.getContainingScope()
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
?.let { reportDeclarationConflict(conflicts, it) { s -> "$s already exists" } }
?.let { reportDeclarationConflict(conflicts, it) { s -> KotlinBundle.message("0.already.exists", s) } }
} else if (callable is PsiMethod) callable.checkDeclarationConflict(propertyName, conflicts, callables)
val usages = ReferencesSearch.search(callable)
@@ -146,7 +150,10 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
val refElement = usage.element
conflicts.putValue(
refElement,
"Unrecognized reference will be skipped: " + StringUtil.htmlEmphasize(refElement.text)
KotlinBundle.message(
"unrecognized.reference.will.be.skipped.0",
StringUtil.htmlEmphasize(refElement.text)
)
)
}
continue
@@ -165,7 +172,10 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
conflicts.putValue(
refElement,
"Can't replace foreign reference with call expression: " + StringUtil.htmlEmphasize(refElement.text)
KotlinBundle.message(
"can.t.replace.foreign.reference.with.call.expression.0",
StringUtil.htmlEmphasize(refElement.text)
)
)
}
}
@@ -6,12 +6,13 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
class ConvertRangeCheckToTwoComparisonsIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(
KtBinaryExpression::class.java,
"Convert to comparisons"
KotlinBundle.message("convert.to.comparisons")
) {
private fun KtExpression?.isSimple() = this is KtConstantExpression || this is KtNameReferenceExpression
@@ -15,6 +15,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.getOrCreateValueParameterList
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
import org.jetbrains.kotlin.idea.refactoring.resolveToExpectedDescriptorIfPossible
@@ -27,7 +28,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
class ConvertReceiverToParameterIntention :
SelfTargetingOffsetIndependentIntention<KtTypeReference>(KtTypeReference::class.java, "Convert receiver to parameter"),
SelfTargetingOffsetIndependentIntention<KtTypeReference>(
KtTypeReference::class.java,
KotlinBundle.message("convert.receiver.to.parameter")
),
LowPriorityAction {
override fun isApplicableTo(element: KtTypeReference): Boolean {
return (element.parent as? KtNamedFunction)?.receiverTypeReference == element
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
@@ -30,7 +31,7 @@ import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
class ConvertReferenceToLambdaInspection : IntentionBasedInspection<KtCallableReferenceExpression>(ConvertReferenceToLambdaIntention::class)
class ConvertReferenceToLambdaIntention : SelfTargetingOffsetIndependentIntention<KtCallableReferenceExpression>(
KtCallableReferenceExpression::class.java, "Convert reference to lambda"
KtCallableReferenceExpression::class.java, KotlinBundle.message("convert.reference.to.lambda")
) {
override fun applyTo(element: KtCallableReferenceExpression, editor: Editor?) {
@@ -14,6 +14,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.refactoring.util.CommonRefactoringUtil
import com.intellij.refactoring.util.RefactoringDescriptionLocation
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest
@@ -29,7 +30,10 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(KtClass::class.java, "Convert to enum class") {
class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(
KtClass::class.java,
KotlinBundle.message("convert.to.enum.class")
) {
override fun applicabilityRange(element: KtClass): TextRange? {
val nameIdentifier = element.nameIdentifier ?: return null
val sealedKeyword = element.modifierList?.getModifier(KtTokens.SEALED_KEYWORD) ?: return null
@@ -45,7 +49,7 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
val klass = element.liftToExpected() as? KtClass ?: element
val subclasses = project.runSynchronouslyWithProgress("Searching inheritors...", true) {
val subclasses = project.runSynchronouslyWithProgress(KotlinBundle.message("searching.inheritors"), true) {
HierarchySearchRequest(klass, klass.useScope, false).searchInheritors().mapNotNull { it.unwrapped }
} ?: return
@@ -60,7 +64,7 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
val inconvertibleSubclasses = subclassesByContainer[null] ?: emptyList()
if (inconvertibleSubclasses.isNotEmpty()) {
return showError(
"All inheritors must be nested objects of the class itself and may not inherit from other classes or interfaces.\n",
KotlinBundle.message("all.inheritors.must.be.nested.objects.of.the.class.itself.and.may.not.inherit.from.other.classes.or.interfaces"),
inconvertibleSubclasses,
project,
editor
@@ -70,7 +74,12 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
@Suppress("UNCHECKED_CAST")
val nonSealedClasses = (subclassesByContainer.keys as Set<KtClass>).filter { !it.isSealed() }
if (nonSealedClasses.isNotEmpty()) {
return showError("All expected and actual classes must be sealed classes.\n", nonSealedClasses, project, editor)
return showError(
KotlinBundle.message("all.expected.and.actual.classes.must.be.sealed.classes"),
nonSealedClasses,
project,
editor
)
}
if (subclassesByContainer.isNotEmpty()) {
@@ -83,7 +92,7 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
private fun showError(message: String, elements: List<PsiElement>, project: Project, editor: Editor?) {
val errorText = buildString {
append(message)
append("Following problems are found:\n")
append(KotlinBundle.message("following.problems.are.found"))
elements.joinTo(this) { ElementDescriptionUtil.getElementDescription(it, RefactoringDescriptionLocation.WITHOUT_PARENT) }
}
return CommonRefactoringUtil.showErrorHint(project, editor, errorText, text, null)
@@ -109,7 +118,7 @@ class ConvertSealedClassToEnumIntention : SelfTargetingRangeIntention<KtClass>(K
}
val entry = psiFactory.createEnumEntry(entryText)
subclass.getBody()?.let { body -> entry.add(body) }
subclass.body?.let { body -> entry.add(body) }
if (i < subclasses.lastIndex) {
entry.add(comma)
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.util.CommentSaver
@@ -31,7 +32,7 @@ class ConvertSecondaryConstructorToPrimaryInspection : IntentionBasedInspection<
class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntention<KtSecondaryConstructor>(
KtSecondaryConstructor::class.java,
"Convert to primary constructor"
KotlinBundle.message("convert.to.primary.constructor")
) {
private tailrec fun ConstructorDescriptor.isReachableByDelegationFrom(
constructor: ConstructorDescriptor, context: BindingContext, visited: Set<ConstructorDescriptor> = emptySet()
@@ -28,17 +28,18 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import com.intellij.refactoring.rename.RenameProcessor
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart
import org.jetbrains.kotlin.utils.SmartList
sealed class ConvertTestFunctionToSpacedIntention(case: String) : SelfTargetingRangeIntention<KtNamedFunction>(
KtNamedFunction::class.java, "Replace $case name with spaces"
KtNamedFunction::class.java, KotlinBundle.message("replace.0.name.with.spaces", case)
) {
companion object {
private val SNAKE_CASE_REGEX = ".+_.+".toRegex()
@@ -65,7 +66,7 @@ sealed class ConvertTestFunctionToSpacedIntention(case: String) : SelfTargetingR
val lightMethod = element.toLightMethods().firstOrNull() ?: return null
if (!TestFrameworks.getInstance().isTestMethod(lightMethod)) return null
text = "Rename to $newName"
text = KotlinBundle.message("rename.to.01", newName)
return range
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.setType
@@ -29,7 +30,7 @@ import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.isUnit
class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody>(
KtDeclarationWithBody::class.java, "Convert to block body"
KtDeclarationWithBody::class.java, KotlinBundle.message("convert.to.block.body")
) {
override fun isApplicableTo(element: KtDeclarationWithBody, caretOffset: Int): Boolean {
if (element is KtFunctionLiteral || element.hasBlockBody() || !element.hasBody()) return false
@@ -8,13 +8,14 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
class ConvertToConcatenatedStringIntention : SelfTargetingOffsetIndependentIntention<KtStringTemplateExpression>(
KtStringTemplateExpression::class.java,
"Convert template to concatenated string"
KotlinBundle.message("convert.template.to.concatenated.string")
), LowPriorityAction {
override fun isApplicableTo(element: KtStringTemplateExpression): Boolean {
if (element.lastChild.node.elementType != KtTokens.CLOSING_QUOTE) return false // not available for unclosed literal
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.contentRange
@@ -28,7 +29,7 @@ import java.util.*
class ConvertToForEachFunctionCallIntention : SelfTargetingIntention<KtForExpression>(
KtForExpression::class.java,
"Replace with a 'forEach' function call"
KotlinBundle.message("replace.with.a.foreach.function.call")
) {
override fun isApplicableTo(element: KtForExpression, caretOffset: Int): Boolean {
val rParen = element.rightParenthesis ?: return false
@@ -6,12 +6,13 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.psi.KtBinaryExpression
class ConvertToRawStringTemplateIntention : ConvertToStringTemplateIntention() {
init {
text = "Convert concatenation to raw string"
text = KotlinBundle.message("convert.concatenation.to.raw.string")
}
override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
@@ -6,12 +6,16 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.*
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.RefactoringBundle
import com.intellij.refactoring.util.CommonRefactoringUtil
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.intentions.ConvertToScopeIntention.ScopeFunction.*
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters
@@ -23,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
sealed class ConvertToScopeIntention(
private val scopeFunction: ScopeFunction
) : SelfTargetingIntention<KtExpression>(KtExpression::class.java, "Convert to ${scopeFunction.functionName}") {
) : SelfTargetingIntention<KtExpression>(KtExpression::class.java, KotlinBundle.message("convert.to.0", scopeFunction.functionName)) {
enum class ScopeFunction(val functionName: String, val isParameterScope: Boolean) {
ALSO(functionName = "also", isParameterScope = true),
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.util.PsiUtilCore
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
@@ -36,7 +37,7 @@ class ConvertToStringTemplateInspection : IntentionBasedInspection<KtBinaryExpre
open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(
KtBinaryExpression::class.java,
"Convert concatenation to template"
KotlinBundle.message("convert.concatenation.to.template")
) {
override fun isApplicableTo(element: KtBinaryExpression): Boolean {
if (!isApplicableToNoParentCheck(element)) return false
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.psi.*
@@ -27,7 +28,7 @@ class ConvertTryFinallyToUseCallInspection : IntentionBasedInspection<KtTryExpre
}
class ConvertTryFinallyToUseCallIntention : SelfTargetingRangeIntention<KtTryExpression>(
KtTryExpression::class.java, "Convert try-finally to .use()"
KtTryExpression::class.java, KotlinBundle.message("convert.try.finally.to.use")
) {
override fun applyTo(element: KtTryExpression, editor: Editor?) {
val finallySection = element.finallyBlock!!
@@ -6,17 +6,18 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.createExpressionByPattern
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.platform.js.isJs
class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention<KtDotQualifiedExpression>(
KtDotQualifiedExpression::class.java, "Convert to unsafe cast"
KtDotQualifiedExpression::class.java, KotlinBundle.message("convert.to.unsafe.cast")
) {
override fun isApplicableTo(element: KtDotQualifiedExpression, caretOffset: Int): Boolean {
@@ -28,7 +29,7 @@ class ConvertUnsafeCastCallToUnsafeCastIntention : SelfTargetingIntention<KtDotQ
val type = element.callExpression?.typeArguments?.singleOrNull() ?: return false
text = "Convert to '${element.receiverExpression.text} as ${type.text}'"
text = KotlinBundle.message("convert.to.0.as.1", element.receiverExpression.text, type.text)
return true
}
@@ -6,19 +6,20 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.psi.KtBinaryExpressionWithTypeRHS
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.createExpressionByPattern
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.TypeUtils
class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention<KtBinaryExpressionWithTypeRHS>(
KtBinaryExpressionWithTypeRHS::class.java, "Convert to unsafeCast() call"
KtBinaryExpressionWithTypeRHS::class.java, KotlinBundle.message("convert.to.unsafecast.call")
) {
override fun isApplicableTo(element: KtBinaryExpressionWithTypeRHS, caretOffset: Int): Boolean {
@@ -31,7 +32,7 @@ class ConvertUnsafeCastToUnsafeCastCallIntention : SelfTargetingIntention<KtBina
val type = context[BindingContext.TYPE, right] ?: return false
if (TypeUtils.isNullableType(type)) return false
text = "Convert to '${element.left.text}.unsafeCast<${right.text}>()'"
text = KotlinBundle.message("convert.to.0.unsafecast.1", element.left.text, right.text)
return true
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtParameter
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
class ConvertVarargParameterToArrayIntention : SelfTargetingIntention<KtParameter>(
KtParameter::class.java, "Convert to array parameter"
KtParameter::class.java, KotlinBundle.message("convert.to.array.parameter")
) {
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
@@ -16,6 +16,7 @@ import com.intellij.psi.JavaDirectoryService
import com.intellij.refactoring.rename.PsiElementRenameHandler
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMembersHandler
@@ -30,7 +31,10 @@ import org.jetbrains.kotlin.resolve.ModifiersChecker
private const val IMPL_SUFFIX = "Impl"
class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtClass::class.java, "Create Kotlin subclass") {
class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(
KtClass::class.java,
KotlinBundle.message("create.kotlin.subclass")
) {
override fun applicabilityRange(element: KtClass): TextRange? {
if (element.name == null || element.getParentOfType<KtFunction>(true) != null) {
@@ -43,7 +47,7 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
val primaryConstructor = element.primaryConstructor
if (!element.isInterface() && primaryConstructor != null) {
val constructors = element.secondaryConstructors + primaryConstructor
if (constructors.none() {
if (constructors.none {
!it.isPrivate() &&
it.getValueParameters().all { it.hasDefaultValue() }
}) {
@@ -53,7 +57,7 @@ class CreateKotlinSubClassIntention : SelfTargetingRangeIntention<KtClass>(KtCla
}
}
text = getImplementTitle(element)
return TextRange(element.startOffset, element.getBody()?.lBrace?.startOffset ?: element.endOffset)
return TextRange(element.startOffset, element.body?.lBrace?.startOffset ?: element.endOffset)
}
private fun getImplementTitle(baseClass: KtClass) =
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -53,7 +54,7 @@ class DestructureInspection : IntentionBasedInspection<KtDeclaration>(
class DestructureIntention : SelfTargetingRangeIntention<KtDeclaration>(
KtDeclaration::class.java,
"Use destructuring declaration"
KotlinBundle.message("use.destructuring.declaration")
) {
override fun applyTo(element: KtDeclaration, editor: Editor?) {
val (usagesToRemove, removeSelectorInLoopRange) = collectUsagesToRemove(element)!!
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaClassDescriptor
import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideImplementMembersHandler
@@ -47,7 +48,7 @@ import java.util.*
import javax.swing.ListSelectionModel
abstract class ImplementAbstractMemberIntentionBase :
SelfTargetingRangeIntention<KtNamedDeclaration>(KtNamedDeclaration::class.java, "", "Implement abstract member") {
SelfTargetingRangeIntention<KtNamedDeclaration>(KtNamedDeclaration::class.java, "", KotlinBundle.message("implement.abstract.member")) {
companion object {
private val LOG = Logger.getInstance("#${ImplementAbstractMemberIntentionBase::class.java.canonicalName}")
}
@@ -237,7 +238,7 @@ class ImplementAbstractMemberIntention : ImplementAbstractMemberIntentionBase()
class ImplementAbstractMemberAsConstructorParameterIntention : ImplementAbstractMemberIntentionBase() {
override fun computeText(element: KtNamedDeclaration): String? {
if (element !is KtProperty) return null
return "Implement as constructor parameter"
return KotlinBundle.message("implement.as.constructor.parameter")
}
override fun acceptSubClass(subClassDescriptor: ClassDescriptor, memberDescriptor: CallableMemberDescriptor): Boolean {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.util.range
@@ -23,7 +24,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, "Import members with '*'"), HighPriorityAction {
class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("import.members.with")),
HighPriorityAction {
override fun isApplicableTo(element: KtElement, caretOffset: Int): Boolean {
val receiverExpression = element.receiverExpression() ?: return false
if (!receiverExpression.range.containsOffset(caretOffset)) return false
@@ -40,7 +42,7 @@ class ImportAllMembersIntention : SelfTargetingIntention<KtElement>(KtElement::c
val helper = ImportInsertHelper.getInstance(project)
if (helper.importDescriptor(dummyFile, target, forceAllUnderImport = true) == ImportDescriptorResult.FAIL) return false
text = "Import members from '${targetFqName.parent().asString()}'"
text = KotlinBundle.message("import.members.from.0", targetFqName.parent().asString())
return true
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.imports.canBeAddedToImport
@@ -34,7 +35,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class ImportMemberIntention : SelfTargetingOffsetIndependentIntention<KtNameReferenceExpression>(
KtNameReferenceExpression::class.java,
"Add import for member"
KotlinBundle.message("add.import.for.member")
), HighPriorityAction {
override fun isApplicableTo(element: KtNameReferenceExpression): Boolean {
if (element.getQualifiedElement() == element) return false //Ignore simple name expressions
@@ -45,7 +46,7 @@ class ImportMemberIntention : SelfTargetingOffsetIndependentIntention<KtNameRefe
val fqName = targetFqName(qualifiedExpression) ?: return false
text = "Add import for '${fqName.asString()}'"
text = KotlinBundle.message("add.import.for.0", fqName.asString())
return true
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.application.options.CodeStyle
import com.intellij.openapi.editor.Editor
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtProperty
@@ -18,7 +19,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class IndentRawStringIntention : SelfTargetingOffsetIndependentIntention<KtStringTemplateExpression>(
KtStringTemplateExpression::class.java, "Indent raw string"
KtStringTemplateExpression::class.java, KotlinBundle.message("indent.raw.string")
) {
override fun isApplicableTo(element: KtStringTemplateExpression): Boolean {
@@ -6,11 +6,15 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
class InfixCallToOrdinaryIntention :
SelfTargetingIntention<KtBinaryExpression>(KtBinaryExpression::class.java, "Replace infix call with ordinary call") {
SelfTargetingIntention<KtBinaryExpression>(
KtBinaryExpression::class.java,
KotlinBundle.message("replace.infix.call.with.ordinary.call")
) {
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
if (element.operationToken != KtTokens.IDENTIFIER || element.left == null || element.right == null) return false
return element.operationReference.textRange.containsOffset(caretOffset)
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.RestoreCaret
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtSimpleNameStringTemplateEntry
@@ -26,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
class InsertCurlyBracesToTemplateIntention :
SelfTargetingOffsetIndependentIntention<KtSimpleNameStringTemplateEntry>(
KtSimpleNameStringTemplateEntry::class.java, "Insert curly braces around variable"
KtSimpleNameStringTemplateEntry::class.java, KotlinBundle.message("insert.curly.braces.around.variable")
),
LowPriorityAction {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
@@ -24,7 +25,8 @@ import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.checker.NewCapturedType
class InsertExplicitTypeArgumentsIntention :
SelfTargetingRangeIntention<KtCallExpression>(KtCallExpression::class.java, "Add explicit type arguments"), LowPriorityAction {
SelfTargetingRangeIntention<KtCallExpression>(KtCallExpression::class.java, KotlinBundle.message("add.explicit.type.arguments")),
LowPriorityAction {
override fun applicabilityRange(element: KtCallExpression): TextRange? {
return if (isApplicableTo(element, element.analyze())) element.calleeExpression?.textRange else null
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
@@ -28,7 +29,10 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(KtProperty::class.java, "Introduce backing property") {
class IntroduceBackingPropertyIntention : SelfTargetingIntention<KtProperty>(
KtProperty::class.java,
KotlinBundle.message("introduce.backing.property")
) {
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
if (!canIntroduceBackingProperty(element)) return false
return element.nameIdentifier?.textRange?.containsOffset(caretOffset) == true
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.imports.canBeAddedToImport
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceImportAlias.KotlinIntroduceImportAliasHandler
import org.jetbrains.kotlin.idea.references.mainReference
@@ -16,7 +17,7 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression
class IntroduceImportAliasIntention : SelfTargetingRangeIntention<KtNameReferenceExpression>(
KtNameReferenceExpression::class.java,
"Introduce import alias"
KotlinBundle.message("introduce.import.alias")
) {
override fun applicabilityRange(element: KtNameReferenceExpression): TextRange? {
if (element.parent is KtInstanceExpressionWithLabel) return null
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.moveCaret
import org.jetbrains.kotlin.idea.core.replaced
@@ -23,7 +24,10 @@ import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, "Invert 'if' condition") {
class InvertIfConditionIntention : SelfTargetingIntention<KtIfExpression>(
KtIfExpression::class.java,
KotlinBundle.message("invert.if.condition")
) {
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
if (!element.ifKeyword.textRange.containsOffset(caretOffset)) return false
return element.condition != null && element.then != null
@@ -11,6 +11,7 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl
import com.intellij.codeInsight.template.impl.ConstantNode
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.*
@@ -25,14 +26,20 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.KotlinType
class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(KtExpression::class.java, "Iterate over collection"),
class IterateExpressionIntention : SelfTargetingIntention<KtExpression>(
KtExpression::class.java,
KotlinBundle.message("iterate.over.collection")
),
HighPriorityAction {
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
if (element.parent !is KtBlockExpression) return false
val range = element.textRange
if (caretOffset != range.startOffset && caretOffset != range.endOffset) return false
val data = data(element) ?: return false
text = "Iterate over '${IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType)}'"
text = KotlinBundle.message(
"iterate.over.0",
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(data.collectionType)
)
return true
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReferenceService
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.canOmitDeclaredType
import org.jetbrains.kotlin.idea.core.moveCaret
@@ -40,12 +41,12 @@ import org.jetbrains.kotlin.types.TypeUtils
@Suppress("DEPRECATION")
class JoinDeclarationAndAssignmentInspection : IntentionBasedInspection<KtProperty>(
JoinDeclarationAndAssignmentIntention::class,
"Can be joined with assignment"
KotlinBundle.message("can.be.joined.with.assignment")
)
class JoinDeclarationAndAssignmentIntention : SelfTargetingRangeIntention<KtProperty>(
KtProperty::class.java,
"Join declaration and assignment"
KotlinBundle.message("join.declaration.and.assignment")
) {
private fun equalNullableTypes(type1: KotlinType?, type2: KotlinType?): Boolean {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.codeStyle.CodeStyleManager
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
import org.jetbrains.kotlin.psi.psiUtil.endOffset
@@ -47,7 +48,7 @@ abstract class AbstractJoinListIntention<TList : KtElement, TElement : KtElement
class JoinParameterListIntention : AbstractJoinListIntention<KtParameterList, KtParameter>(
KtParameterList::class.java,
KtParameter::class.java,
"Put parameters on one line"
KotlinBundle.message("put.parameters.on.one.line")
) {
override fun isApplicableTo(element: KtParameterList): Boolean {
if (element.parent is KtFunctionLiteral) return false
@@ -58,5 +59,5 @@ class JoinParameterListIntention : AbstractJoinListIntention<KtParameterList, Kt
class JoinArgumentListIntention : AbstractJoinListIntention<KtValueArgumentList, KtValueArgument>(
KtValueArgumentList::class.java,
KtValueArgument::class.java,
"Put arguments on one line"
KotlinBundle.message("put.arguments.on.one.line")
)
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.moveInsideParentheses
@@ -30,8 +31,8 @@ import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
class LambdaToAnonymousFunctionIntention : SelfTargetingIntention<KtLambdaExpression>(
KtLambdaExpression::class.java,
"Convert to anonymous function",
"Convert lambda expression to anonymous function"
KotlinBundle.message("convert.to.anonymous.function"),
KotlinBundle.message("convert.lambda.expression.to.anonymous.function")
), LowPriorityAction {
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
if (element.getStrictParentOfType<KtValueArgument>() == null) return false
@@ -6,10 +6,11 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.*
class MergeElseIfIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, "Merge 'else if'") {
class MergeElseIfIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, KotlinBundle.message("merge.else.if")) {
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
val elseBody = element.`else` ?: return false
val nestedIf = elseBody.nestedIf() ?: return false
@@ -17,9 +17,10 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.*
class MergeIfsIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, "Merge 'if's") {
class MergeIfsIntention : SelfTargetingIntention<KtIfExpression>(KtIfExpression::class.java, KotlinBundle.message("merge.if.s")) {
override fun isApplicableTo(element: KtIfExpression, caretOffset: Int): Boolean {
if (element.`else` != null) return false
@@ -18,13 +18,14 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.moveInsideParentheses
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.psiUtil.containsInside
class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtLambdaArgument>(
KtLambdaArgument::class.java, "Move lambda argument into parentheses"
KtLambdaArgument::class.java, KotlinBundle.message("move.lambda.argument.into.parentheses")
), LowPriorityAction {
override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean {
val body = element.getLambdaExpression()?.bodyExpression ?: return true
@@ -23,13 +23,14 @@ import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.refactoring.getUsageContext
import org.jetbrains.kotlin.idea.refactoring.isInterfaceClass
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
import org.jetbrains.kotlin.psi.*
@@ -39,37 +40,42 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isSubclassOf
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
import org.jetbrains.kotlin.util.findCallableMemberBySignature
class MoveMemberOutOfCompanionObjectIntention : MoveMemberOutOfObjectIntention("Move out of companion object") {
class MoveMemberOutOfCompanionObjectIntention : MoveMemberOutOfObjectIntention(KotlinBundle.message("move.out.of.companion.object")) {
override fun addConflicts(element: KtNamedDeclaration, conflicts: MultiMap<PsiElement, String>) {
val targetClass = element.containingClassOrObject!!.containingClassOrObject!!
val targetClassDescriptor = runReadAction { targetClass.unsafeResolveToDescriptor() as ClassDescriptor }
val refsRequiringClassInstance = element.project.runSynchronouslyWithProgress("Searching for ${element.name}", true) {
runReadAction {
ReferencesSearch
.search(element)
.mapNotNull { it.element }
.filter {
if (it !is KtElement) return@filter true
val resolvedCall = it.resolveToCall() ?: return@filter false
val dispatchReceiver = resolvedCall.dispatchReceiver ?: return@filter false
if (dispatchReceiver !is ImplicitClassReceiver) return@filter true
it.parents
.filterIsInstance<KtClassOrObject>()
.none {
val classDescriptor = it.resolveToDescriptorIfAny()
if (classDescriptor != null && classDescriptor.isSubclassOf(targetClassDescriptor)) return@none true
if (it.isTopLevel() || it is KtObjectDeclaration || (it is KtClass && !it.isInner())) return@filter true
false
}
}
}
} ?: return
val refsRequiringClassInstance =
element.project.runSynchronouslyWithProgress(KotlinBundle.message("searching.for.0", element.name.toString()), true) {
runReadAction {
ReferencesSearch
.search(element)
.mapNotNull { it.element }
.filter {
if (it !is KtElement) return@filter true
val resolvedCall = it.resolveToCall() ?: return@filter false
val dispatchReceiver = resolvedCall.dispatchReceiver ?: return@filter false
if (dispatchReceiver !is ImplicitClassReceiver) return@filter true
it.parents
.filterIsInstance<KtClassOrObject>()
.none {
val classDescriptor = it.resolveToDescriptorIfAny()
if (classDescriptor != null && classDescriptor.isSubclassOf(targetClassDescriptor)) return@none true
if (it.isTopLevel() || it is KtObjectDeclaration || (it is KtClass && !it.isInner())) return@filter true
false
}
}
}
} ?: return
for (refElement in refsRequiringClassInstance) {
val context = refElement.getUsageContext()
val message = "'${refElement.text}' in ${RefactoringUIUtil.getDescription(context, false)} will require class instance"
val message = KotlinBundle.message(
"0.in.1.will.require.class.instance",
refElement.text,
RefactoringUIUtil.getDescription(context, false)
)
conflicts.putValue(refElement, message)
}
@@ -78,7 +84,14 @@ class MoveMemberOutOfCompanionObjectIntention : MoveMemberOutOfObjectIntention("
targetClassDescriptor.findCallableMemberBySignature(callableDescriptor)?.let {
DescriptorToSourceUtilsIde.getAnyDeclaration(element.project, it)
}?.let {
conflicts.putValue(it, "Class '${targetClass.name}' already contains ${RefactoringUIUtil.getDescription(it, false)}")
conflicts.putValue(
it,
KotlinBundle.message(
"class.0.already.contains.1",
targetClass.name.toString(),
RefactoringUIUtil.getDescription(it, false)
)
)
}
}
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
@@ -72,7 +73,7 @@ import org.jetbrains.kotlin.util.findCallableMemberBySignature
class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
KtNamedDeclaration::class.java,
"Move to companion object"
KotlinBundle.message("move.to.companion.object")
) {
override fun applicabilityRange(element: KtNamedDeclaration): TextRange? {
if (element !is KtNamedFunction && element !is KtProperty && element !is KtClassOrObject) return null
@@ -294,13 +295,13 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamed
if (HierarchySearchRequest(element, element.useScope, false).searchOverriders().any()) {
return CommonRefactoringUtil.showErrorHint(
project, editor, "$description is overridden by declaration(s) in a subclass", text, null
project, editor, KotlinBundle.message("0.is.overridden.by.declaration.s.in.a.subclass", description), text, null
)
}
if (hasTypeParameterReferences(containingClass, element)) {
return CommonRefactoringUtil.showErrorHint(
project, editor, "$description references type parameters of the containing class", text, null
project, editor, KotlinBundle.message("0.references.type.parameters.of.the.containing.class", description), text, null
)
}
@@ -314,20 +315,29 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamed
companionDescriptor.findCallableMemberBySignature(callableDescriptor)?.let {
DescriptorToSourceUtilsIde.getAnyDeclaration(project, it)
}?.let {
conflicts.putValue(it, "Companion object already contains ${RefactoringUIUtil.getDescription(it, false)}")
conflicts.putValue(
it,
KotlinBundle.message("companion.object.already.contains.0", RefactoringUIUtil.getDescription(it, false))
)
}
}
val outerInstanceReferences = collectOuterInstanceReferences(element)
if (outerInstanceReferences.isNotEmpty()) {
if (element is KtProperty) {
conflicts.putValue(element, "Usages of outer class instance inside of property '${element.name}' won't be processed")
conflicts.putValue(
element,
KotlinBundle.message(
"usages.of.outer.class.instance.inside.of.property.0.won.t.be.processed",
element.name.toString()
)
)
} else {
outerInstanceReferences.filterNotTo(outerInstanceUsages) { it.reportConflictIfAny(conflicts) }
}
}
project.runSynchronouslyWithProgress("Searching for ${element.name}", true) {
project.runSynchronouslyWithProgress(KotlinBundle.message("searching.for.0", element.name.toString()), true) {
runReadAction {
ReferencesSearch.search(element).mapNotNullTo(externalUsages) { ref ->
when (ref) {
@@ -343,7 +353,7 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamed
if (extensionReceiver != null && extensionReceiver !is ImplicitReceiver) {
conflicts.putValue(
callExpression,
"Calls with explicit extension receiver won't be processed: ${callExpression.text}"
KotlinBundle.message("calls.with.explicit.extension.receiver.won.t.be.processed.0", callExpression.text)
)
return@mapNotNullTo null
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -30,7 +31,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
class MoveMemberToTopLevelIntention : MoveMemberOutOfObjectIntention("Move to top level") {
class MoveMemberToTopLevelIntention : MoveMemberOutOfObjectIntention(KotlinBundle.message("move.to.top.level")) {
override fun addConflicts(element: KtNamedDeclaration, conflicts: MultiMap<PsiElement, String>) {
val packageViewDescriptor = element.findModuleDescriptor().getPackage(element.containingKtFile.packageFqName)
val packageDescriptor = packageViewDescriptor.fragments.firstIsInstance<LazyPackageDescriptor>()
@@ -52,7 +53,14 @@ class MoveMemberToTopLevelIntention : MoveMemberOutOfObjectIntention("Move to to
}
if (isRedeclaration) {
conflicts.putValue(element, "Package '$packageName' already contains ${RefactoringUIUtil.getDescription(element, false)}")
conflicts.putValue(
element,
KotlinBundle.message(
"package.0.already.contains.1",
packageName,
RefactoringUIUtil.getDescription(element, false)
)
)
}
}
@@ -9,6 +9,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -18,7 +19,10 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(KtParameter::class.java, "Move to class body") {
class MovePropertyToClassBodyIntention : SelfTargetingIntention<KtParameter>(
KtParameter::class.java,
KotlinBundle.message("move.to.class.body")
) {
override fun isApplicableTo(element: KtParameter, caretOffset: Int): Boolean {
return element.isPropertyParameter() && (element.ownerFunction as KtPrimaryConstructor).isNotContainedInAnnotation()
}
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.ParameterDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
@@ -46,7 +47,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.KotlinType
class MovePropertyToConstructorIntention :
SelfTargetingIntention<KtProperty>(KtProperty::class.java, "Move to constructor"),
SelfTargetingIntention<KtProperty>(KtProperty::class.java, KotlinBundle.message("move.to.constructor")),
LocalQuickFix {
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.lexer.KtTokens
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
class NullableBooleanEqualityCheckToElvisIntention : SelfTargetingIntention<KtBinaryExpression>(
KtBinaryExpression::class.java, "Convert Boolean? == const to elvis"
KtBinaryExpression::class.java, KotlinBundle.message("convert.boolean.const.to.elvis")
) {
override fun isApplicableTo(element: KtBinaryExpression, caretOffset: Int): Boolean {
if (element.operationToken != KtTokens.EQEQ && element.operationToken != KtTokens.EXCLEQ) return false
@@ -13,6 +13,7 @@ import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
@@ -59,8 +60,8 @@ class ObjectLiteralToLambdaInspection : IntentionBasedInspection<KtObjectLiteral
class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiteralExpression>(
KtObjectLiteralExpression::class.java,
"Convert to lambda",
"Convert object literal to lambda"
KotlinBundle.message("convert.to.lambda"),
KotlinBundle.message("convert.object.literal.to.lambda")
) {
override fun applicabilityRange(element: KtObjectLiteralExpression): TextRange? {
val (baseTypeRef, baseType, singleFunction) = extractData(element) ?: return null
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.replaced
@@ -18,7 +19,10 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isError
class ReconstructTypeInCastOrIsIntention :
SelfTargetingOffsetIndependentIntention<KtTypeReference>(KtTypeReference::class.java, "Replace by reconstructed type"),
SelfTargetingOffsetIndependentIntention<KtTypeReference>(
KtTypeReference::class.java,
KotlinBundle.message("replace.by.reconstructed.type")
),
LowPriorityAction {
override fun isApplicableTo(element: KtTypeReference): Boolean {
// Only user types (like Foo) are interesting
@@ -38,7 +42,7 @@ class ReconstructTypeInCastOrIsIntention :
if (type.constructor.parameters.isEmpty()) return false
val typePresentation = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(type)
text = "Replace by '$typePresentation'"
text = KotlinBundle.message("replace.by.0", typePresentation)
return true
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.completion.canBeUsedWithoutNameInCall
import org.jetbrains.kotlin.idea.completion.placedOnItsOwnPositionInCall
@@ -16,7 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.calls.callUtil.getParameterForArgument
import org.jetbrains.kotlin.resolve.calls.components.isVararg
class RemoveArgumentNameIntention : SelfTargetingRangeIntention<KtValueArgument>(KtValueArgument::class.java, "Remove argument name") {
class RemoveArgumentNameIntention : SelfTargetingRangeIntention<KtValueArgument>(
KtValueArgument::class.java,
KotlinBundle.message("remove.argument.name")
) {
override fun applicabilityRange(element: KtValueArgument): TextRange? {
if (!element.isNamed()) return null
val resolvedCall = element.getStrictParentOfType<KtCallElement>()?.resolveToCall() ?: return null
@@ -21,11 +21,12 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, "Remove braces") {
class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.java, KotlinBundle.message("remove.braces")) {
private fun KtElement.findChildBlock() = when (this) {
is KtBlockExpression -> this
@@ -45,11 +46,11 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class
}
val description = container.description() ?: return false
text = "Remove braces from '$description' statement"
text = KotlinBundle.message("remove.braces.from.0.statement", description)
return true
}
is KtWhenEntry -> {
text = "Remove braces from 'when' entry"
text = KotlinBundle.message("remove.braces.from.when.entry")
return singleStatement !is KtNamedDeclaration
&& !(singleStatement is KtLambdaExpression && singleStatement.functionLiteral.arrow == null)
}
@@ -6,13 +6,14 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
class RemoveConstructorKeywordIntention : SelfTargetingIntention<KtPrimaryConstructor>(
KtPrimaryConstructor::class.java,
"Remove constructor keyword"
KotlinBundle.message("remove.constructor.keyword")
) {
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) {
element.removeRedundantConstructorKeywordAndSpace()
@@ -9,6 +9,7 @@ import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -24,7 +25,7 @@ class RemoveEmptyClassBodyInspection :
}
class RemoveEmptyClassBodyIntention :
SelfTargetingOffsetIndependentIntention<KtClassBody>(KtClassBody::class.java, "Redundant empty class body") {
SelfTargetingOffsetIndependentIntention<KtClassBody>(KtClassBody::class.java, KotlinBundle.message("redundant.empty.class.body")) {
override fun applyTo(element: KtClassBody, editor: Editor?) {
val parent = element.parent
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.util.range
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.refactoring.getLineNumber
@@ -37,7 +38,7 @@ class RemoveEmptyParenthesesFromLambdaCallInspection : IntentionBasedInspection<
}
class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntention<KtValueArgumentList>(
KtValueArgumentList::class.java, "Remove unnecessary parentheses from function call with lambda"
KtValueArgumentList::class.java, KotlinBundle.message("remove.unnecessary.parentheses.from.function.call.with.lambda")
) {
override fun applicabilityRange(element: KtValueArgumentList): TextRange? {
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.util.isExpectDeclaration
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
@@ -32,7 +33,10 @@ class RemoveEmptyPrimaryConstructorInspection : IntentionBasedInspection<KtPrima
}
class RemoveEmptyPrimaryConstructorIntention :
SelfTargetingOffsetIndependentIntention<KtPrimaryConstructor>(KtPrimaryConstructor::class.java, "Remove empty primary constructor") {
SelfTargetingOffsetIndependentIntention<KtPrimaryConstructor>(
KtPrimaryConstructor::class.java,
KotlinBundle.message("remove.empty.primary.constructor")
) {
override fun applyTo(element: KtPrimaryConstructor, editor: Editor?) = element.delete()
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
@@ -21,7 +22,10 @@ class RemoveEmptySecondaryConstructorBodyInspection : IntentionBasedInspection<K
}
class RemoveEmptySecondaryConstructorBodyIntention :
SelfTargetingOffsetIndependentIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove empty constructor body") {
SelfTargetingOffsetIndependentIntention<KtBlockExpression>(
KtBlockExpression::class.java,
KotlinBundle.message("remove.empty.constructor.body")
) {
override fun applyTo(element: KtBlockExpression, editor: Editor?) = element.delete()
@@ -6,12 +6,16 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.endOffset
class RemoveExplicitLambdaParameterTypesIntention :
SelfTargetingIntention<KtLambdaExpression>(KtLambdaExpression::class.java, "Remove explicit lambda parameter types (may break code)") {
SelfTargetingIntention<KtLambdaExpression>(
KtLambdaExpression::class.java,
KotlinBundle.message("remove.explicit.lambda.parameter.types.may.break.code")
) {
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
if (element.valueParameters.none { it.typeReference != null }) return false
val arrow = element.functionLiteral.arrow ?: return false
@@ -9,6 +9,7 @@ import com.intellij.codeInspection.CleanupLocalInspectionTool
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
@@ -32,7 +33,10 @@ class RemoveExplicitSuperQualifierInspection : IntentionBasedInspection<KtSuperE
}
class RemoveExplicitSuperQualifierIntention :
SelfTargetingRangeIntention<KtSuperExpression>(KtSuperExpression::class.java, "Remove explicit supertype qualification") {
SelfTargetingRangeIntention<KtSuperExpression>(
KtSuperExpression::class.java,
KotlinBundle.message("remove.explicit.supertype.qualification")
) {
override fun applicabilityRange(element: KtSuperExpression): TextRange? {
if (element.superTypeQualifier == null) return null
@@ -10,6 +10,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.copied
@@ -38,7 +39,10 @@ class RemoveExplicitTypeArgumentsInspection : IntentionBasedInspection<KtTypeArg
}
class RemoveExplicitTypeArgumentsIntention :
SelfTargetingOffsetIndependentIntention<KtTypeArgumentList>(KtTypeArgumentList::class.java, "Remove explicit type arguments") {
SelfTargetingOffsetIndependentIntention<KtTypeArgumentList>(
KtTypeArgumentList::class.java,
KotlinBundle.message("remove.explicit.type.arguments")
) {
companion object {
fun isApplicableTo(element: KtTypeArgumentList, approximateFlexible: Boolean): Boolean {
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.refactoring.addTypeArgumentsIfNeeded
import org.jetbrains.kotlin.idea.refactoring.getQualifiedTypeArgumentList
import org.jetbrains.kotlin.idea.references.mainReference
@@ -31,7 +32,7 @@ import org.jetbrains.kotlin.types.typeUtil.isUnit
class RemoveExplicitTypeIntention : SelfTargetingRangeIntention<KtCallableDeclaration>(
KtCallableDeclaration::class.java,
"Remove explicit type specification"
KotlinBundle.message("remove.explicit.type.specification")
), HighPriorityAction {
override fun applicabilityRange(element: KtCallableDeclaration): TextRange? {
@@ -9,6 +9,7 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.editor.fixers.range
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
@@ -21,13 +22,13 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
@Suppress("DEPRECATION")
class RemoveForLoopIndicesInspection : IntentionBasedInspection<KtForExpression>(
RemoveForLoopIndicesIntention::class,
"Index is not used in the loop body"
KotlinBundle.message("index.is.not.used.in.the.loop.body")
) {
override fun problemHighlightType(element: KtForExpression): ProblemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
}
class RemoveForLoopIndicesIntention :
SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Remove indices in 'for' loop") {
SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, KotlinBundle.message("remove.indices.in.for.loop")) {
private val WITH_INDEX_NAME = "withIndex"
private val WITH_INDEX_FQ_NAMES: Set<String> by lazy {
sequenceOf("collections", "sequences", "text", "ranges").map { "kotlin.$it.$WITH_INDEX_NAME" }.toSet()
@@ -7,13 +7,14 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtReturnExpression
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
class RemoveLabeledReturnInLambdaIntention : SelfTargetingIntention<KtReturnExpression>(
KtReturnExpression::class.java,
"Remove labeled return from last expression in a lambda"
KotlinBundle.message("remove.labeled.return.from.last.expression.in.a.lambda")
), LowPriorityAction {
override fun isApplicableTo(element: KtReturnExpression, caretOffset: Int): Boolean {
val labelName = element.getLabelName() ?: return false
@@ -21,7 +22,7 @@ class RemoveLabeledReturnInLambdaIntention : SelfTargetingIntention<KtReturnExpr
if (block.statements.lastOrNull() != element) return false
val callName = block.getParentLambdaLabelName() ?: return false
if (labelName != callName) return false
text = "Remove return@$labelName"
text = KotlinBundle.message("remove.return.0", labelName)
return true
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.replaced
@@ -39,7 +40,7 @@ class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspecti
class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeIntention<KtQualifiedExpression>(
KtQualifiedExpression::class.java,
"Remove redundant calls of the conversion method"
KotlinBundle.message("remove.redundant.calls.of.the.conversion.method")
) {
private val targetClassMap: Map<String, String?> by lazy {
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.psi.KtExpression
@@ -26,12 +27,12 @@ class RemoveSingleExpressionStringTemplateInspection : IntentionBasedInspection<
} ?: false
}
) {
override val problemText = "Redundant string template"
override val problemText = KotlinBundle.message("redundant.string.template")
}
class RemoveSingleExpressionStringTemplateIntention : SelfTargetingOffsetIndependentIntention<KtStringTemplateExpression>(
KtStringTemplateExpression::class.java,
"Remove single-expression string template"
KotlinBundle.message("remove.single.expression.string.template")
) {
override fun isApplicableTo(element: KtStringTemplateExpression) =
element.singleExpressionOrNull() != null

Some files were not shown because too many files have changed in this diff Show More