Do not suggest "can be private" for elements with given annotations

So #KT-19272 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-07-31 14:42:56 +03:00
parent c5a81691fb
commit 87cdc7635a
4 changed files with 15 additions and 1 deletions
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.inspections
import com.intellij.codeInspection.IntentionWrapper
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.codeInspection.ex.EntryPointsManager
import com.intellij.codeInspection.ex.EntryPointsManagerBase
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.psi.PsiReference
@@ -84,6 +86,11 @@ class MemberVisibilityCanPrivateInspection : AbstractKotlinInspection() {
if (declaration.isOverridable()) return false
if (descriptor.hasJvmFieldAnnotation()) return false
val entryPointsManager = EntryPointsManager.getInstance(declaration.project) as EntryPointsManagerBase
if (UnusedSymbolInspection.checkAnnotatedUsingPatterns(descriptor,
with (entryPointsManager) {
additionalAnnotations + ADDITIONAL_ANNOTATIONS
})) return false
val psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(declaration.project)
val useScope = declaration.useScope
@@ -113,7 +113,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
}
// variation of IDEA's AnnotationUtil.checkAnnotatedUsingPatterns()
private fun checkAnnotatedUsingPatterns(annotated: Annotated, annotationPatterns: Collection<String>): Boolean {
fun checkAnnotatedUsingPatterns(annotated: Annotated, annotationPatterns: Collection<String>): Boolean {
val annotationsPresent = annotated.annotations.mapNotNull { it.fqName?.asString() }
if (annotationsPresent.isEmpty()) return false
@@ -0,0 +1,3 @@
package test.anno
public annotation class EntryPoint
@@ -205,3 +205,7 @@ fun withLocal(): Int {
val local = Local(42)
return local.res()
}
class Math {
@test.anno.EntryPoint fun fact(n: Int) = if (n < 2) 1 else n * fact(n - 1)
}