Report WRONG_MODIFIER_TARGET on the modifier instead of the declaration

in ExternalFunChecker.

This allows RemoveModifierFix to provide a quickfix to remove it.
This commit is contained in:
Mark Punzalan
2021-02-19 22:10:26 +00:00
committed by Ilya Kirillov
parent c680ee8525
commit dd20dd9806
6 changed files with 29 additions and 7 deletions
@@ -23,8 +23,8 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
@@ -39,7 +39,9 @@ class ExternalFunChecker : DeclarationChecker {
is ClassDescriptor -> "class"
else -> "non-function declaration"
}
trace.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, target))
declaration.modifierList?.getModifier(KtTokens.EXTERNAL_KEYWORD)?.let {
trace.report(Errors.WRONG_MODIFIER_TARGET.on(it, KtTokens.EXTERNAL_KEYWORD, target))
}
return
}
@@ -1,9 +1,9 @@
<!WRONG_MODIFIER_TARGET!>external class A<!>
<!WRONG_MODIFIER_TARGET!>external<!> class A
<!WRONG_MODIFIER_TARGET!>external val foo: Int = 23<!>
<!WRONG_MODIFIER_TARGET!>external<!> val foo: Int = 23
class B {
<!WRONG_MODIFIER_TARGET!>external class A<!>
<!WRONG_MODIFIER_TARGET!>external<!> class A
<!WRONG_MODIFIER_TARGET!>external val foo: Int = 23<!>
}
<!WRONG_MODIFIER_TARGET!>external<!> val foo: Int = 23
}
@@ -650,6 +650,11 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
runTest("idea/testData/quickfix/modifiers/removeConst.kt");
}
@TestMetadata("removeExternalModifier.kt")
public void testRemoveExternalModifier() throws Exception {
runTest("idea/testData/quickfix/modifiers/removeExternalModifier.kt");
}
@TestMetadata("removeIncompatibleModifier.kt")
public void testRemoveIncompatibleModifier() throws Exception {
runTest("idea/testData/quickfix/modifiers/removeIncompatibleModifier.kt");
@@ -0,0 +1,5 @@
// "Remove 'external' modifier" "true"
class B {
<caret>external val foo: Int = 23
}
@@ -0,0 +1,5 @@
// "Remove 'external' modifier" "true"
class B {
val foo: Int = 23
}
@@ -9432,6 +9432,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/modifiers/removeConst.kt");
}
@TestMetadata("removeExternalModifier.kt")
public void testRemoveExternalModifier() throws Exception {
runTest("idea/testData/quickfix/modifiers/removeExternalModifier.kt");
}
@TestMetadata("removeIncompatibleModifier.kt")
public void testRemoveIncompatibleModifier() throws Exception {
runTest("idea/testData/quickfix/modifiers/removeIncompatibleModifier.kt");