Searching for property accessors, too.
This commit is contained in:
@@ -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.JetEnumEntry
|
||||||
import org.jetbrains.kotlin.psi.JetProperty
|
import org.jetbrains.kotlin.psi.JetProperty
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.PropertyUsagesSearchHelper
|
import org.jetbrains.kotlin.idea.search.usagesSearch.PropertyUsagesSearchHelper
|
||||||
|
import org.jetbrains.kotlin.idea.search.usagesSearch.getAccessorNames
|
||||||
|
|
||||||
public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||||
private val javaInspection = UnusedDeclarationInspection()
|
private val javaInspection = UnusedDeclarationInspection()
|
||||||
@@ -137,12 +138,18 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
val useScope = declaration.getUseScope()
|
val useScope = declaration.getUseScope()
|
||||||
if (useScope is GlobalSearchScope) {
|
if (useScope is GlobalSearchScope) {
|
||||||
val searchCostResult = psiSearchHelper.isCheapEnoughToSearch(declaration.getName(), useScope, null, null)
|
var zeroOccurrences = true
|
||||||
|
|
||||||
when (searchCostResult) {
|
for (name in listOf(declaration.getName()) + declaration.getAccessorNames()) {
|
||||||
ZERO_OCCURRENCES -> return false // function is surely unused
|
when (psiSearchHelper.isCheapEnoughToSearch(name, useScope, null, null)) {
|
||||||
FEW_OCCURRENCES -> {} // do search (following code)
|
ZERO_OCCURRENCES -> {} // go on, check other names
|
||||||
TOO_MANY_OCCURRENCES -> return true // searching usages is too expensive; behave like it is used
|
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 = ":)"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user