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:
Evgeny Gerashchenko
2015-01-14 20:09:14 +03:00
parent c5351b0760
commit 4b20435ec9
2 changed files with 42 additions and 0 deletions
@@ -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() {
}