Do not report "property can be private" on JvmField properties
So #KT-18970 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5281602381
commit
9d06a80519
@@ -26,11 +26,13 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.util.Processor
|
||||
import org.jetbrains.kotlin.idea.core.toDescriptor
|
||||
import org.jetbrains.kotlin.idea.quickfix.AddModifierFix
|
||||
import org.jetbrains.kotlin.idea.refactoring.isConstructorDeclaredProperty
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmFieldAnnotation
|
||||
|
||||
class MemberVisibilityCanPrivateInspection : AbstractKotlinInspection() {
|
||||
|
||||
@@ -67,6 +69,7 @@ class MemberVisibilityCanPrivateInspection : AbstractKotlinInspection() {
|
||||
val inheritable = classOrObject is KtClass && classOrObject.isInheritable()
|
||||
if (!inheritable && declaration.hasModifier(KtTokens.PROTECTED_KEYWORD)) return false //reported by ProtectedInFinalInspection
|
||||
if (declaration.isOverridable()) return false
|
||||
if (declaration.toDescriptor()?.hasJvmFieldAnnotation() != false) return false
|
||||
|
||||
val psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(declaration.project)
|
||||
val useScope = declaration.useScope
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.MemberVisibilityCanPrivateInspection
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// PROBLEM: none
|
||||
|
||||
class J(@JvmField val <caret>a: String) {
|
||||
|
||||
fun foo() {
|
||||
println(a)
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// PROBLEM: none
|
||||
|
||||
class J {
|
||||
@JvmField
|
||||
val <caret>b = ""
|
||||
|
||||
fun foo() {
|
||||
println(b)
|
||||
}
|
||||
}
|
||||
@@ -939,6 +939,27 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/memberVisibilityCanBePrivate")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class MemberVisibilityCanBePrivate extends AbstractLocalInspectionTest {
|
||||
public void testAllFilesPresentInMemberVisibilityCanBePrivate() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/memberVisibilityCanBePrivate"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("JvmFieldOnParameter.kt")
|
||||
public void testJvmFieldOnParameter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/memberVisibilityCanBePrivate/JvmFieldOnParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("JvmFieldOnProperty.kt")
|
||||
public void testJvmFieldOnProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/memberVisibilityCanBePrivate/JvmFieldOnProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user