Inspections: Don't show "Package directive doesn't match file location" in injected code
#KT-12376 Fixed (cherry picked from commit a5a5fe5)
This commit is contained in:
@@ -206,6 +206,7 @@
|
||||
- [`KT-12284`](https://youtrack.jetbrains.com/issue/KT-12284) Too wide applicability range for "Add braces to else" intention
|
||||
- [`KT-11975`](https://youtrack.jetbrains.com/issue/KT-11975) "Invert if-condition" intention does not simplify `is` expression
|
||||
- [`KT-12437`](https://youtrack.jetbrains.com/issue/KT-12437) "Replace explicit parameter" intention is suggested for parameter of inner lambda in presence of `it` from outer lambda
|
||||
- [`KT-12376`](https://youtrack.jetbrains.com/issue/KT-12376) Don't show "Package directive doesn't match file location" in injected code
|
||||
|
||||
#### Language injection
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils
|
||||
import com.intellij.codeInsight.unwrap.RangeSplitter
|
||||
import com.intellij.codeInsight.unwrap.UnwrapHandler
|
||||
import com.intellij.ide.util.PsiElementListCellRenderer
|
||||
import com.intellij.lang.injection.InjectedLanguageManager
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.command.CommandAdapter
|
||||
@@ -787,3 +788,9 @@ internal fun DeclarationDescriptor.explicateAsTextForReceiver(): String {
|
||||
internal fun ImplicitReceiver.explicateAsText(): String {
|
||||
return declarationDescriptor.explicateAsTextForReceiver()
|
||||
}
|
||||
|
||||
val PsiFile.isInjectedFragment: Boolean
|
||||
get() = InjectedLanguageManager.getInstance(project).isInjectedFragment(this)
|
||||
|
||||
val PsiElement.isInsideInjectedFragment: Boolean
|
||||
get() = containingFile.isInjectedFragment
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ package org.jetbrains.kotlin.idea.refactoring.move.changePackage
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.core.getFqNameByDirectory
|
||||
import org.jetbrains.kotlin.idea.core.packageMatchesDirectory
|
||||
import org.jetbrains.kotlin.idea.refactoring.hasIdentifiersOnly
|
||||
import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention
|
||||
import org.jetbrains.kotlin.idea.refactoring.hasIdentifiersOnly
|
||||
import org.jetbrains.kotlin.idea.refactoring.isInjectedFragment
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
|
||||
class ChangePackageToMatchDirectoryIntention : SelfTargetingOffsetIndependentIntention<KtPackageDirective>(
|
||||
@@ -28,7 +29,7 @@ class ChangePackageToMatchDirectoryIntention : SelfTargetingOffsetIndependentInt
|
||||
) {
|
||||
override fun isApplicableTo(element: KtPackageDirective): Boolean {
|
||||
val file = element.getContainingKtFile()
|
||||
if (file.packageMatchesDirectory()) return false
|
||||
if (file.isInjectedFragment || file.packageMatchesDirectory()) return false
|
||||
|
||||
val fqNameByDirectory = file.getFqNameByDirectory()
|
||||
if (!fqNameByDirectory.toUnsafe().hasIdentifiersOnly()) {
|
||||
|
||||
+2
@@ -28,12 +28,14 @@ import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectori
|
||||
import com.intellij.refactoring.util.RefactoringMessageUtil
|
||||
import org.jetbrains.kotlin.idea.core.packageMatchesDirectory
|
||||
import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention
|
||||
import org.jetbrains.kotlin.idea.refactoring.isInsideInjectedFragment
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
|
||||
class MoveFileToPackageMatchingDirectoryIntention : SelfTargetingOffsetIndependentIntention<KtPackageDirective>(
|
||||
KtPackageDirective::class.java, "", "Move file to package-matching directory"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtPackageDirective): Boolean {
|
||||
if (element.isInsideInjectedFragment) return false
|
||||
if (element.getContainingKtFile().packageMatchesDirectory()) return false
|
||||
|
||||
val qualifiedName = element.qualifiedName
|
||||
|
||||
Reference in New Issue
Block a user