Improve wording for "change package" fix for source root case

This commit is contained in:
Mikhail Glukhikh
2017-12-26 18:27:13 +03:00
parent 429c31c010
commit 72ec55769b
2 changed files with 8 additions and 5 deletions
@@ -53,8 +53,11 @@ class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
val dirName = if (qualifiedName.isEmpty()) "source root" else "'${qualifiedName.replace('.', '/')}'"
fixes += MoveFileToPackageFix(dirName)
val fqNameByDirectory = file.getFqNameByDirectory()
if (fqNameByDirectory.hasIdentifiersOnly()) {
fixes += ChangePackageFix(fqNameByDirectory)
when {
fqNameByDirectory.isRoot ->
fixes += ChangePackageFix("source root")
fqNameByDirectory.hasIdentifiersOnly() ->
fixes += ChangePackageFix("'${fqNameByDirectory.asString()}'")
}
holder.registerProblem(
@@ -105,10 +108,10 @@ class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
}
}
private class ChangePackageFix(val fqNameByDirectory: FqName) : LocalQuickFix {
private class ChangePackageFix(val packageName: String) : LocalQuickFix {
override fun getFamilyName() = "Change file's package to match directory"
override fun getName() = "Change file's package to '${fqNameByDirectory.asString()}'"
override fun getName() = "Change file's package to $packageName"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val directive = descriptor.psiElement as? KtPackageDirective ?: return
@@ -1,5 +1,5 @@
{
"mainFile": "test.kt",
"inspectionClass": "org.jetbrains.kotlin.idea.refactoring.move.changePackage.PackageDirectoryMismatchInspection",
"fix": "Change file's package to ''"
"fix": "Change file's package to source root"
}