From 0a886320ca6bce63562ee88c60bf8ebf70a80624 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 20 May 2015 14:18:52 +0300 Subject: [PATCH] JetWholeProjectForEachElementOfTypeFix - not too much duplicating string arguments --- .../kotlin/idea/JetBundle.properties | 9 ------- .../quickfix/DeprecatedAnnotationSyntaxFix.kt | 4 +-- .../DeprecatedEnumEntryDelimiterSyntaxFix.kt | 4 +-- ...catedEnumEntrySuperConstructorSyntaxFix.kt | 4 +-- .../quickfix/DeprecatedLambdaSyntaxFix.kt | 4 +-- .../idea/quickfix/DeprecatedTraitSyntaxFix.kt | 6 ++--- .../quickfix/JetWholeProjectModalAction.kt | 27 +++++++------------ .../quickfix/MissingConstructorKeywordFix.kt | 4 +-- .../RemoveNameFromFunctionExpressionFix.kt | 4 +-- .../quickfix/ReplaceObsoleteLabelSyntaxFix.kt | 6 ++--- ...ReplaceJavaClassAsAnnotationArgumentFix.kt | 4 +-- ...eplaceJavaClassAsAnnotationParameterFix.kt | 4 +-- .../traitToInterface/traitToInterface.kt | 2 +- .../traitToInterface.kt.after | 2 +- 14 files changed, 24 insertions(+), 60 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties index 2e5b286f705..ed6c88c72d2 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties @@ -166,9 +166,6 @@ migrate.class.object.to.companion.in.whole.project.modal.title=Replacing 'class' migrate.class.object.to.companion.in.whole.project.family=Replace 'class' Keyword with 'companion' Modifier in Whole Project migrate.lambda.syntax=Migrate lambda syntax migrate.lambda.syntax.family=Migrate lambda syntax -migrate.lambda.syntax.in.whole.project=Migrate lambda syntax in whole project -migrate.lambda.syntax.in.whole.project.modal.title=Migrating lambda syntax in whole project -migrate.lambda.syntax.in.whole.project.family=Migrate lambda syntax in whole project remove.val.var.from.parameter=Remove ''{0}'' from parameter add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project add.when.else.branch.action.family.name=Add Else Branch @@ -219,15 +216,9 @@ add.name.to.parameter.name.chooser.title=Choose parameter name replace.java.class.argument=Replace javaClass() with T::class replace.java.class.argument.family=Replace javaClass() with T::class -replace.java.class.argument.in.whole.project=Replace javaClass() with T::class in whole project -replace.java.class.argument.in.whole.project.family=Replace javaClass() with T::class in whole project -replace.java.class.argument.in.whole.project.modal.title=Replacing javaClass() with T::class in whole project replace.java.class.parameter=Replace Class with KClass in whole annotation replace.java.class.parameter.family=Replace Class with KClass in whole annotation -replace.java.class.parameter.in.whole.project=Replace Class with KClass for each annotation in project -replace.java.class.parameter.in.whole.project.family=Replace Class with KClass for each annotation in project -replace.java.class.parameter.in.whole.project.modal.title=Replacing Class with KClass for each annotation in project property.is.implemented.too.many=Has implementations property.is.overridden.too.many=Is overridden in subclasses diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt index f2de071e753..6e399138a59 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedAnnotationSyntaxFix.kt @@ -44,9 +44,7 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio JetWholeProjectForEachElementOfTypeFix.createByPredicate( predicate = { it.isDeprecated() }, taskProcessor = { replaceWithAtAnnotationEntries(it) }, - modalTitle = "Replacing deprecated annotations syntax", - name = "Replace with '@' annotations in whole project", - familyName = "Replace with '@' annotations in whole project" + name = "Replace with '@' annotations in whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntryDelimiterSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntryDelimiterSyntaxFix.kt index 1ab5085abf1..0e8d8fc63b1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntryDelimiterSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntryDelimiterSyntaxFix.kt @@ -51,9 +51,7 @@ class DeprecatedEnumEntryDelimiterSyntaxFix(element: JetEnumEntry): JetIntention JetWholeProjectForEachElementOfTypeFix.createByPredicate( predicate = { DeclarationsChecker.enumEntryUsesDeprecatedOrNoDelimiter(it) }, taskProcessor = { insertLackingCommaSemicolon(it) }, - modalTitle = "Replacing deprecated enum entry delimiter syntax", - name = "Insert lacking comma(s) / semicolon(s) in the whole project", - familyName = "Insert lacking comma(s) / semicolon(s) in the whole project" + name = "Insert lacking comma(s) / semicolon(s) in the whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt index 2bd1a8f3c5c..ed548cad2be 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt @@ -54,9 +54,7 @@ class DeprecatedEnumEntrySuperConstructorSyntaxFix(element: JetEnumEntry): JetIn JetWholeProjectForEachElementOfTypeFix.createByPredicate( predicate = { DeclarationsChecker.enumEntryUsesDeprecatedSuperConstructor(it) }, taskProcessor = { changeConstructorToShort(it) }, - modalTitle = "Replacing deprecated enum constructor syntax", - name = "Change to short enum entry super constructor in the whole project", - familyName = "Change to short enum entry super constructor in the whole project" + name = "Change to short enum entry super constructor in the whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt index 1c76dfd043c..c20c77ddeed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt @@ -51,9 +51,7 @@ public class DeprecatedLambdaSyntaxFix(element: JetFunctionLiteralExpression) : JetWholeProjectForEachElementOfTypeFix.createByTaskFactory( taskFactory = fun (it: JetFunctionLiteralExpression) = fixTaskFactory(it), taskProcessor = { it.runFix() }, - modalTitle = JetBundle.message("migrate.lambda.syntax.in.whole.project.modal.title"), - name = JetBundle.message("migrate.lambda.syntax.in.whole.project"), - familyName = JetBundle.message("migrate.lambda.syntax.in.whole.project.family") + name = "Migrate lambda syntax in whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedTraitSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedTraitSyntaxFix.kt index 7dd3eb1f256..8ae58d0594c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedTraitSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedTraitSyntaxFix.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetPsiFactory public class DeprecatedTraitSyntaxFix(element: PsiElement): JetIntentionAction(element), CleanupFix { - override fun getFamilyName() = "Replace with 'interface'" + override fun getFamilyName() = "Replace 'trait' with 'interface'" override fun getText() = getFamilyName() override fun invoke(project: Project, editor: Editor?, file: JetFile?) @@ -48,9 +48,7 @@ public class DeprecatedTraitSyntaxFix(element: PsiElement): JetIntentionAction

( predicate = { it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD) != null }, taskProcessor = { replaceWithInterfaceKeyword(it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD).getPsi())}, - modalTitle = "Replacing deprecated trait syntax", - name = "Replace with 'interface' in whole project", - familyName = "Replace with 'interface' in whole project" + name = "Replace 'trait' with 'interface' in whole project" ) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt index 13fc7a39090..1e1e33d32f9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/JetWholeProjectModalAction.kt @@ -115,14 +115,13 @@ public abstract class JetWholeProjectModalByCollectionAction(modalTitle } class JetWholeProjectForEachElementOfTypeFix private ( - val collectingVisitorFactory: (MutableCollection) -> JetVisitorVoid, - val tasksProcessor: (Collection) -> Unit, - modalTitle: String, - val name: String, - val familyNameText: String -) : JetWholeProjectModalByCollectionAction(modalTitle) { + private val collectingVisitorFactory: (MutableCollection) -> JetVisitorVoid, + private val tasksProcessor: (Collection) -> Unit, + private val name: String, + private val familyName: String = name +) : JetWholeProjectModalByCollectionAction("Applying '$name'") { - override fun getFamilyName() = familyNameText + override fun getFamilyName() = familyName override fun getText() = name override fun collectTasksForFile(project: Project, file: JetFile, accumulator: MutableCollection) { @@ -134,13 +133,11 @@ class JetWholeProjectForEachElementOfTypeFix private ( inline fun createByPredicate( noinline predicate: (E) -> Boolean, noinline taskProcessor: (E) -> Unit, - modalTitle: String, name: String, - familyName: String + familyName: String = name ) = createByTaskFactory( taskFactory = { if (predicate(it)) it else null }, taskProcessor = taskProcessor, - modalTitle = modalTitle, name = name, familyName = familyName ) @@ -148,13 +145,11 @@ class JetWholeProjectForEachElementOfTypeFix private ( inline fun createByTaskFactory( noinline taskFactory: (E) -> D?, noinline taskProcessor: (D) -> Unit, - modalTitle: String, name: String, - familyName: String + familyName: String = name ) = createForMultiTask( tasksFactory = { taskFactory(it).singletonOrEmptyList() }, tasksProcessor = { it.forEach(taskProcessor) }, - modalTitle = modalTitle, name = name, familyName = familyName ) @@ -162,15 +157,13 @@ class JetWholeProjectForEachElementOfTypeFix private ( inline fun createForMultiTask( noinline tasksFactory: (E) -> Collection, noinline tasksProcessor: (Collection) -> Unit, - modalTitle: String, name: String, - familyName: String + familyName: String = name ) = JetWholeProjectForEachElementOfTypeFix( collectingVisitorFactory = { accumulator -> flatMapDescendantsOfTypeVisitor(accumulator, tasksFactory) }, tasksProcessor = tasksProcessor, - modalTitle = modalTitle, name = name, - familyNameText = familyName + familyName = familyName ) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt index 81576bece2f..a9803eb9693 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt @@ -42,9 +42,7 @@ public class MissingConstructorKeywordFix(element: JetPrimaryConstructor) : JetI JetWholeProjectForEachElementOfTypeFix.createByPredicate( predicate = { it.getModifierList() != null && !it.hasConstructorKeyword() }, taskProcessor = { it.addConstructorKeyword() }, - modalTitle = "Adding missing 'constructor' keyword", - name = "Add missing 'constructor' keyword in whole project", - familyName = "Add missing 'constructor' keyword in whole project" + name = "Add missing 'constructor' keyword in whole project" ) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt index b8dd55a8093..df52e741b55 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt @@ -45,9 +45,7 @@ public class RemoveNameFromFunctionExpressionFix(element: JetNamedFunction) : Je JetWholeProjectForEachElementOfTypeFix.createByPredicate( predicate = { isFunctionExpression(it) }, taskProcessor = { removeNameFromFunction(it) }, - modalTitle = "Removing identifier from function expressions", - name = "Remove identifier from function expressions in the whole project", - familyName = "Remove identifier from function expressions in the whole project" + name = "Remove identifier from function expressions in the whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt index 879d5bb0c32..11b08c92be7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt @@ -50,12 +50,10 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn if (!(diagnostic.getPsiElement().getNonStrictParentOfType()?.looksLikeObsoleteLabelWithReferencesInCode() ?: false)) return@factory null - JetWholeProjectForEachElementOfTypeFix.createForMultiTask( + JetWholeProjectForEachElementOfTypeFix.createForMultiTaskOnElement( tasksFactory = { collectTasks(it) }, tasksProcessor ={ it.forEach { ann -> replaceWithLabel(ann) } }, - modalTitle = "Replacing labels with obsolete syntax", - name = "Update obsolete label syntax in whole project", - familyName = "Update obsolete label syntax in whole project" + name = "Update obsolete label syntax in whole project" ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationArgumentFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationArgumentFix.kt index 3b21f88168c..8ef2c62238e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationArgumentFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationArgumentFix.kt @@ -50,9 +50,7 @@ public class ReplaceJavaClassAsAnnotationArgumentFix( JetWholeProjectForEachElementOfTypeFix.createForMultiTask( tasksFactory = { createReplacementTasks(it) }, tasksProcessor = ::processTasks, - modalTitle = JetBundle.message("replace.java.class.argument.in.whole.project.modal.title"), - name = JetBundle.message("replace.java.class.argument.in.whole.project"), - familyName = JetBundle.message("replace.java.class.argument.in.whole.project.family") + name = "Replace javaClass() with T::class in whole project" ) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationParameterFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationParameterFix.kt index 720e8ad9ffa..d7f215341b9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationParameterFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceJavaClass/ReplaceJavaClassAsAnnotationParameterFix.kt @@ -48,9 +48,7 @@ public class ReplaceJavaClassAsAnnotationParameterFix( JetWholeProjectForEachElementOfTypeFix.createForMultiTask( tasksFactory = ::createReplacementTasksForAnnotationClass, tasksProcessor = ::processTasks, - modalTitle = JetBundle.message("replace.java.class.parameter.in.whole.project.modal.title"), - name = JetBundle.message("replace.java.class.parameter.in.whole.project"), - familyName = JetBundle.message("replace.java.class.parameter.in.whole.project.family") + name = "Replace Class with KClass for each annotation in project" ) } } diff --git a/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt b/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt index 3d701be7ddb..bea391b1e06 100644 --- a/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt +++ b/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt @@ -1,4 +1,4 @@ -// "Replace with 'interface'" "true" +// "Replace 'trait' with 'interface'" "true" trait Foo { diff --git a/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt.after b/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt.after index 7792b57fecd..95e00443c01 100644 --- a/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt.after +++ b/idea/testData/quickfix/migration/traitToInterface/traitToInterface.kt.after @@ -1,4 +1,4 @@ -// "Replace with 'interface'" "true" +// "Replace 'trait' with 'interface'" "true" interface Foo {