JetWholeProjectForEachElementOfTypeFix - not too much duplicating string arguments

This commit is contained in:
Valentin Kipyatkov
2015-05-20 14:18:52 +03:00
parent 7d8a92aeb7
commit 0a886320ca
14 changed files with 24 additions and 60 deletions
@@ -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.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=Migrate lambda syntax
migrate.lambda.syntax.family=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 remove.val.var.from.parameter=Remove ''{0}'' from parameter
add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project
add.when.else.branch.action.family.name=Add Else Branch 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<T>() with T::class replace.java.class.argument=Replace javaClass<T>() with T::class
replace.java.class.argument.family=Replace javaClass<T>() with T::class replace.java.class.argument.family=Replace javaClass<T>() with T::class
replace.java.class.argument.in.whole.project=Replace javaClass<T>() with T::class in whole project
replace.java.class.argument.in.whole.project.family=Replace javaClass<T>() with T::class in whole project
replace.java.class.argument.in.whole.project.modal.title=Replacing javaClass<T>() with T::class in whole project
replace.java.class.parameter=Replace Class<T> with KClass<T> in whole annotation replace.java.class.parameter=Replace Class<T> with KClass<T> in whole annotation
replace.java.class.parameter.family=Replace Class<T> with KClass<T> in whole annotation replace.java.class.parameter.family=Replace Class<T> with KClass<T> in whole annotation
replace.java.class.parameter.in.whole.project=Replace Class<T> with KClass<T> for each annotation in project
replace.java.class.parameter.in.whole.project.family=Replace Class<T> with KClass<T> for each annotation in project
replace.java.class.parameter.in.whole.project.modal.title=Replacing Class<T> with KClass<T> for each annotation in project
property.is.implemented.too.many=Has implementations property.is.implemented.too.many=Has implementations
property.is.overridden.too.many=Is overridden in subclasses property.is.overridden.too.many=Is overridden in subclasses
@@ -44,9 +44,7 @@ public class DeprecatedAnnotationSyntaxFix(element: JetAnnotation) : JetIntentio
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetAnnotation>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetAnnotation>(
predicate = { it.isDeprecated() }, predicate = { it.isDeprecated() },
taskProcessor = { replaceWithAtAnnotationEntries(it) }, taskProcessor = { replaceWithAtAnnotationEntries(it) },
modalTitle = "Replacing deprecated annotations syntax", name = "Replace with '@' annotations in whole project"
name = "Replace with '@' annotations in whole project",
familyName = "Replace with '@' annotations in whole project"
) )
} }
@@ -51,9 +51,7 @@ class DeprecatedEnumEntryDelimiterSyntaxFix(element: JetEnumEntry): JetIntention
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetEnumEntry>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetEnumEntry>(
predicate = { DeclarationsChecker.enumEntryUsesDeprecatedOrNoDelimiter(it) }, predicate = { DeclarationsChecker.enumEntryUsesDeprecatedOrNoDelimiter(it) },
taskProcessor = { insertLackingCommaSemicolon(it) }, taskProcessor = { insertLackingCommaSemicolon(it) },
modalTitle = "Replacing deprecated enum entry delimiter syntax", name = "Insert lacking comma(s) / semicolon(s) in the whole project"
name = "Insert lacking comma(s) / semicolon(s) in the whole project",
familyName = "Insert lacking comma(s) / semicolon(s) in the whole project"
) )
} }
@@ -54,9 +54,7 @@ class DeprecatedEnumEntrySuperConstructorSyntaxFix(element: JetEnumEntry): JetIn
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetEnumEntry>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetEnumEntry>(
predicate = { DeclarationsChecker.enumEntryUsesDeprecatedSuperConstructor(it) }, predicate = { DeclarationsChecker.enumEntryUsesDeprecatedSuperConstructor(it) },
taskProcessor = { changeConstructorToShort(it) }, taskProcessor = { changeConstructorToShort(it) },
modalTitle = "Replacing deprecated enum constructor syntax", name = "Change to short enum entry super constructor in the whole project"
name = "Change to short enum entry super constructor in the whole project",
familyName = "Change to short enum entry super constructor in the whole project"
) )
} }
@@ -51,9 +51,7 @@ public class DeprecatedLambdaSyntaxFix(element: JetFunctionLiteralExpression) :
JetWholeProjectForEachElementOfTypeFix.createByTaskFactory( JetWholeProjectForEachElementOfTypeFix.createByTaskFactory(
taskFactory = fun (it: JetFunctionLiteralExpression) = fixTaskFactory(it), taskFactory = fun (it: JetFunctionLiteralExpression) = fixTaskFactory(it),
taskProcessor = { it.runFix() }, taskProcessor = { it.runFix() },
modalTitle = JetBundle.message("migrate.lambda.syntax.in.whole.project.modal.title"), name = "Migrate lambda syntax in whole project"
name = JetBundle.message("migrate.lambda.syntax.in.whole.project"),
familyName = JetBundle.message("migrate.lambda.syntax.in.whole.project.family")
) )
} }
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiFactory
public class DeprecatedTraitSyntaxFix(element: PsiElement): JetIntentionAction<PsiElement>(element), CleanupFix { public class DeprecatedTraitSyntaxFix(element: PsiElement): JetIntentionAction<PsiElement>(element), CleanupFix {
override fun getFamilyName() = "Replace with 'interface'" override fun getFamilyName() = "Replace 'trait' with 'interface'"
override fun getText() = getFamilyName() override fun getText() = getFamilyName()
override fun invoke(project: Project, editor: Editor?, file: JetFile?) override fun invoke(project: Project, editor: Editor?, file: JetFile?)
@@ -48,9 +48,7 @@ public class DeprecatedTraitSyntaxFix(element: PsiElement): JetIntentionAction<P
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetClass>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetClass>(
predicate = { it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD) != null }, predicate = { it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD) != null },
taskProcessor = { replaceWithInterfaceKeyword(it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD).getPsi())}, taskProcessor = { replaceWithInterfaceKeyword(it.getNode().findChildByType(JetTokens.TRAIT_KEYWORD).getPsi())},
modalTitle = "Replacing deprecated trait syntax", name = "Replace 'trait' with 'interface' in whole project"
name = "Replace with 'interface' in whole project",
familyName = "Replace with 'interface' in whole project"
) )
} }
} }
@@ -115,14 +115,13 @@ public abstract class JetWholeProjectModalByCollectionAction<T : Any>(modalTitle
} }
class JetWholeProjectForEachElementOfTypeFix<T> private ( class JetWholeProjectForEachElementOfTypeFix<T> private (
val collectingVisitorFactory: (MutableCollection<T>) -> JetVisitorVoid, private val collectingVisitorFactory: (MutableCollection<T>) -> JetVisitorVoid,
val tasksProcessor: (Collection<T>) -> Unit, private val tasksProcessor: (Collection<T>) -> Unit,
modalTitle: String, private val name: String,
val name: String, private val familyName: String = name
val familyNameText: String ) : JetWholeProjectModalByCollectionAction<T>("Applying '$name'") {
) : JetWholeProjectModalByCollectionAction<T>(modalTitle) {
override fun getFamilyName() = familyNameText override fun getFamilyName() = familyName
override fun getText() = name override fun getText() = name
override fun collectTasksForFile(project: Project, file: JetFile, accumulator: MutableCollection<T>) { override fun collectTasksForFile(project: Project, file: JetFile, accumulator: MutableCollection<T>) {
@@ -134,13 +133,11 @@ class JetWholeProjectForEachElementOfTypeFix<T> private (
inline fun <reified E : JetElement> createByPredicate( inline fun <reified E : JetElement> createByPredicate(
noinline predicate: (E) -> Boolean, noinline predicate: (E) -> Boolean,
noinline taskProcessor: (E) -> Unit, noinline taskProcessor: (E) -> Unit,
modalTitle: String,
name: String, name: String,
familyName: String familyName: String = name
) = createByTaskFactory<E, E>( ) = createByTaskFactory<E, E>(
taskFactory = { if (predicate(it)) it else null }, taskFactory = { if (predicate(it)) it else null },
taskProcessor = taskProcessor, taskProcessor = taskProcessor,
modalTitle = modalTitle,
name = name, name = name,
familyName = familyName familyName = familyName
) )
@@ -148,13 +145,11 @@ class JetWholeProjectForEachElementOfTypeFix<T> private (
inline fun <reified E : JetElement, D : Any> createByTaskFactory( inline fun <reified E : JetElement, D : Any> createByTaskFactory(
noinline taskFactory: (E) -> D?, noinline taskFactory: (E) -> D?,
noinline taskProcessor: (D) -> Unit, noinline taskProcessor: (D) -> Unit,
modalTitle: String,
name: String, name: String,
familyName: String familyName: String = name
) = createForMultiTask<E, D>( ) = createForMultiTask<E, D>(
tasksFactory = { taskFactory(it).singletonOrEmptyList() }, tasksFactory = { taskFactory(it).singletonOrEmptyList() },
tasksProcessor = { it.forEach(taskProcessor) }, tasksProcessor = { it.forEach(taskProcessor) },
modalTitle = modalTitle,
name = name, name = name,
familyName = familyName familyName = familyName
) )
@@ -162,15 +157,13 @@ class JetWholeProjectForEachElementOfTypeFix<T> private (
inline fun <reified E : JetElement, D> createForMultiTask( inline fun <reified E : JetElement, D> createForMultiTask(
noinline tasksFactory: (E) -> Collection<D>, noinline tasksFactory: (E) -> Collection<D>,
noinline tasksProcessor: (Collection<D>) -> Unit, noinline tasksProcessor: (Collection<D>) -> Unit,
modalTitle: String,
name: String, name: String,
familyName: String familyName: String = name
) = JetWholeProjectForEachElementOfTypeFix( ) = JetWholeProjectForEachElementOfTypeFix(
collectingVisitorFactory = { accumulator -> flatMapDescendantsOfTypeVisitor(accumulator, tasksFactory) }, collectingVisitorFactory = { accumulator -> flatMapDescendantsOfTypeVisitor(accumulator, tasksFactory) },
tasksProcessor = tasksProcessor, tasksProcessor = tasksProcessor,
modalTitle = modalTitle,
name = name, name = name,
familyNameText = familyName familyName = familyName
) )
} }
} }
@@ -42,9 +42,7 @@ public class MissingConstructorKeywordFix(element: JetPrimaryConstructor) : JetI
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetPrimaryConstructor>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetPrimaryConstructor>(
predicate = { it.getModifierList() != null && !it.hasConstructorKeyword() }, predicate = { it.getModifierList() != null && !it.hasConstructorKeyword() },
taskProcessor = { it.addConstructorKeyword() }, taskProcessor = { it.addConstructorKeyword() },
modalTitle = "Adding missing 'constructor' keyword", name = "Add missing 'constructor' keyword in whole project"
name = "Add missing 'constructor' keyword in whole project",
familyName = "Add missing 'constructor' keyword in whole project"
) )
} }
} }
@@ -45,9 +45,7 @@ public class RemoveNameFromFunctionExpressionFix(element: JetNamedFunction) : Je
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetNamedFunction>( JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetNamedFunction>(
predicate = { isFunctionExpression(it) }, predicate = { isFunctionExpression(it) },
taskProcessor = { removeNameFromFunction(it) }, taskProcessor = { removeNameFromFunction(it) },
modalTitle = "Removing identifier from function expressions", name = "Remove identifier from function expressions in the whole project"
name = "Remove identifier from function expressions in the whole project",
familyName = "Remove identifier from function expressions in the whole project"
) )
} }
@@ -50,12 +50,10 @@ public class ReplaceObsoleteLabelSyntaxFix(element: JetAnnotationEntry?) : JetIn
if (!(diagnostic.getPsiElement().getNonStrictParentOfType<JetAnnotationEntry>()?.looksLikeObsoleteLabelWithReferencesInCode() if (!(diagnostic.getPsiElement().getNonStrictParentOfType<JetAnnotationEntry>()?.looksLikeObsoleteLabelWithReferencesInCode()
?: false)) return@factory null ?: false)) return@factory null
JetWholeProjectForEachElementOfTypeFix.createForMultiTask<JetAnnotatedExpression, JetAnnotationEntry>( JetWholeProjectForEachElementOfTypeFix.createForMultiTaskOnElement<JetAnnotatedExpression, JetAnnotationEntry>(
tasksFactory = { collectTasks(it) }, tasksFactory = { collectTasks(it) },
tasksProcessor ={ it.forEach { ann -> replaceWithLabel(ann) } }, tasksProcessor ={ it.forEach { ann -> replaceWithLabel(ann) } },
modalTitle = "Replacing labels with obsolete syntax", name = "Update obsolete label syntax in whole project"
name = "Update obsolete label syntax in whole project",
familyName = "Update obsolete label syntax in whole project"
) )
} }
@@ -50,9 +50,7 @@ public class ReplaceJavaClassAsAnnotationArgumentFix(
JetWholeProjectForEachElementOfTypeFix.createForMultiTask<JetAnnotationEntry, ReplacementTask>( JetWholeProjectForEachElementOfTypeFix.createForMultiTask<JetAnnotationEntry, ReplacementTask>(
tasksFactory = { createReplacementTasks(it) }, tasksFactory = { createReplacementTasks(it) },
tasksProcessor = ::processTasks, tasksProcessor = ::processTasks,
modalTitle = JetBundle.message("replace.java.class.argument.in.whole.project.modal.title"), name = "Replace javaClass<T>() with T::class in whole project"
name = JetBundle.message("replace.java.class.argument.in.whole.project"),
familyName = JetBundle.message("replace.java.class.argument.in.whole.project.family")
) )
} }
} }
@@ -48,9 +48,7 @@ public class ReplaceJavaClassAsAnnotationParameterFix(
JetWholeProjectForEachElementOfTypeFix.createForMultiTask( JetWholeProjectForEachElementOfTypeFix.createForMultiTask(
tasksFactory = ::createReplacementTasksForAnnotationClass, tasksFactory = ::createReplacementTasksForAnnotationClass,
tasksProcessor = ::processTasks, tasksProcessor = ::processTasks,
modalTitle = JetBundle.message("replace.java.class.parameter.in.whole.project.modal.title"), name = "Replace Class<T> with KClass<T> for each annotation in project"
name = JetBundle.message("replace.java.class.parameter.in.whole.project"),
familyName = JetBundle.message("replace.java.class.parameter.in.whole.project.family")
) )
} }
} }
@@ -1,4 +1,4 @@
// "Replace with 'interface'" "true" // "Replace 'trait' with 'interface'" "true"
<caret>trait Foo { <caret>trait Foo {
@@ -1,4 +1,4 @@
// "Replace with 'interface'" "true" // "Replace 'trait' with 'interface'" "true"
<caret>interface Foo { <caret>interface Foo {