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.project.Project
|
||||||
import com.intellij.openapi.roots.JavaProjectRootsUtil
|
import com.intellij.openapi.roots.JavaProjectRootsUtil
|
||||||
import com.intellij.openapi.ui.Messages
|
import com.intellij.openapi.ui.Messages
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
import com.intellij.refactoring.PackageWrapper
|
import com.intellij.refactoring.PackageWrapper
|
||||||
import com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination
|
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.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||||
import org.jetbrains.kotlin.psi.packageDirectiveVisitor
|
import org.jetbrains.kotlin.psi.packageDirectiveVisitor
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
|
class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = packageDirectiveVisitor(fun(directive: KtPackageDirective) {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = packageDirectiveVisitor(fun(directive: KtPackageDirective) {
|
||||||
@@ -51,9 +53,12 @@ class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
|
|||||||
fixes += ChangePackageFix("'${fqNameWithImplicitPrefix.asString()}'", fqNameWithImplicitPrefix)
|
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(
|
holder.registerProblem(
|
||||||
file,
|
file,
|
||||||
directive.textRange,
|
textRange,
|
||||||
"Package directive doesn't match file location",
|
"Package directive doesn't match file location",
|
||||||
*fixes.toTypedArray()
|
*fixes.toTypedArray()
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<problems>
|
<problems>
|
||||||
<problem>
|
<problem>
|
||||||
<file>rootPackageMatched.kt</file>
|
<file>rootPackageMatched.kt</file>
|
||||||
<line>1</line>
|
<line>2</line>
|
||||||
<module>testMismatchedProjectAndDirectoryRoot_MismatchedProjectAndDirectoryRoot</module>
|
<module>testMismatchedProjectAndDirectoryRoot_MismatchedProjectAndDirectoryRoot</module>
|
||||||
<entry_point TYPE="file" FQNAME="rootPackageMatched.kt" />
|
<entry_point TYPE="file" FQNAME="rootPackageMatched.kt" />
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Package name does not match containing directory</problem_class>
|
<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
|
package
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// FIX: Move file to source root
|
||||||
|
|
||||||
<caret>package
|
<caret>package
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIX: Move file to source root
|
||||||
|
|
||||||
class Foo
|
class Foo
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
<caret>
|
// FIX: Move file to source root
|
||||||
class Foo
|
|
||||||
|
<caret>class Foo
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user