Searching for property accessors, too.

This commit is contained in:
Evgeny Gerashchenko
2015-01-19 16:25:05 +03:00
parent 8fd5e72632
commit b0e2afc8cb
3 changed files with 32 additions and 5 deletions
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.INVOKE_OPERATION_NAME
import org.jetbrains.kotlin.psi.JetEnumEntry
import org.jetbrains.kotlin.psi.JetProperty
import org.jetbrains.kotlin.idea.search.usagesSearch.PropertyUsagesSearchHelper
import org.jetbrains.kotlin.idea.search.usagesSearch.getAccessorNames
public class UnusedSymbolInspection : AbstractKotlinInspection() {
private val javaInspection = UnusedDeclarationInspection()
@@ -137,12 +138,18 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
val useScope = declaration.getUseScope()
if (useScope is GlobalSearchScope) {
val searchCostResult = psiSearchHelper.isCheapEnoughToSearch(declaration.getName(), useScope, null, null)
var zeroOccurrences = true
when (searchCostResult) {
ZERO_OCCURRENCES -> return false // function is surely unused
FEW_OCCURRENCES -> {} // do search (following code)
TOO_MANY_OCCURRENCES -> return true // searching usages is too expensive; behave like it is used
for (name in listOf(declaration.getName()) + declaration.getAccessorNames()) {
when (psiSearchHelper.isCheapEnoughToSearch(name, useScope, null, null)) {
ZERO_OCCURRENCES -> {} // go on, check other names
FEW_OCCURRENCES -> zeroOccurrences = false
TOO_MANY_OCCURRENCES -> return true // searching usages is too expensive; behave like it is used
}
}
if (zeroOccurrences) {
return false
}
}
@@ -0,0 +1,12 @@
package test;
import foo.FooPackage;
import foo.Obj;
class usedInJava {
public static void main(String[] args) {
FooPackage.getUsedByGetter();
FooPackage.setUsedBySetter(":|");
System.out.println(Obj.CONST);
}
}
@@ -0,0 +1,8 @@
package foo
val usedByGetter = ":)"
var usedBySetter = ":)"
object Obj {
val CONST = ":)"
}