PackageDirectoryMismatchInspection: fix visibility in editor
#KT-31816 Fixed
This commit is contained in:
+6
-1
@@ -12,6 +12,7 @@ import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.JavaProjectRootsUtil
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.refactoring.PackageWrapper
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
import org.jetbrains.kotlin.psi.packageDirectiveVisitor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = packageDirectiveVisitor(fun(directive: KtPackageDirective) {
|
||||
@@ -51,9 +53,12 @@ class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
|
||||
fixes += ChangePackageFix("'${fqNameWithImplicitPrefix.asString()}'", fqNameWithImplicitPrefix)
|
||||
}
|
||||
|
||||
val textRange = if (directive.textLength != 0) directive.textRange else file.declarations.firstOrNull()?.let {
|
||||
TextRange.from(it.startOffset, 1)
|
||||
}
|
||||
holder.registerProblem(
|
||||
file,
|
||||
directive.textRange,
|
||||
textRange,
|
||||
"Package directive doesn't match file location",
|
||||
*fixes.toTypedArray()
|
||||
)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>rootPackageMatched.kt</file>
|
||||
<line>1</line>
|
||||
<line>2</line>
|
||||
<module>testMismatchedProjectAndDirectoryRoot_MismatchedProjectAndDirectoryRoot</module>
|
||||
<entry_point TYPE="file" FQNAME="rootPackageMatched.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Package name does not match containing directory</problem_class>
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// FIX: Move file to source root
|
||||
|
||||
package
|
||||
|
||||
class Foo
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// FIX: Move file to source root
|
||||
|
||||
<caret>package
|
||||
|
||||
class Foo
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIX: Move file to source root
|
||||
|
||||
class Foo
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
<caret>
|
||||
class Foo
|
||||
// FIX: Move file to source root
|
||||
|
||||
<caret>class Foo
|
||||
|
||||
fun foo() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user