Not searching for functions with conventional names.
Reasons: 1. They kind of implement interface. 2. They are too expensive to search.
This commit is contained in:
@@ -41,6 +41,8 @@ import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.FunctionUsagesSearchHelper
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.PsiSearchHelper.SearchCostResult.*
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.getOperationSymbolsToSearch
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.INVOKE_OPERATION_NAME
|
||||
|
||||
public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
private val javaInspection = UnusedDeclarationInspection()
|
||||
@@ -68,6 +70,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
|
||||
if (function.hasModifier(JetTokens.OVERRIDE_KEYWORD)) return
|
||||
if (isEntryPoint(function)) return
|
||||
if (isConventionalName(function)) return
|
||||
if (hasNonTrivialUsages(function)) return
|
||||
|
||||
holder.registerProblem(
|
||||
@@ -105,6 +108,11 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
return hasTextUsages
|
||||
}
|
||||
|
||||
private fun isConventionalName(namedDeclaration: JetNamedDeclaration): Boolean {
|
||||
val name = namedDeclaration.getNameAsName()
|
||||
return name.getOperationSymbolsToSearch().isNotEmpty() || name == INVOKE_OPERATION_NAME
|
||||
}
|
||||
|
||||
private fun hasNonTrivialUsages(declaration: JetNamedDeclaration): Boolean {
|
||||
val psiSearchHelper = PsiSearchHelper.SERVICE.getInstance(declaration.getProject())
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// all these are unused, but have conventional names, so they won't be marked as unused
|
||||
|
||||
fun inc() {
|
||||
}
|
||||
|
||||
fun dec() {
|
||||
}
|
||||
|
||||
fun component1() {
|
||||
}
|
||||
|
||||
fun component100() {
|
||||
}
|
||||
|
||||
fun equals() {
|
||||
}
|
||||
|
||||
fun invoke() {
|
||||
}
|
||||
|
||||
fun iterator() {
|
||||
}
|
||||
|
||||
fun compareTo() {
|
||||
}
|
||||
|
||||
fun get() {
|
||||
}
|
||||
|
||||
fun set() {
|
||||
}
|
||||
|
||||
fun plusAssign() {
|
||||
}
|
||||
Reference in New Issue
Block a user