@@ -4,12 +4,9 @@ import com.intellij.codeInspection.InspectionSuppressor
4
4
import com.intellij.codeInspection.SuppressQuickFix
5
5
import com.intellij.psi.PsiElement
6
6
import com.intellij.psi.util.PsiTreeUtil
7
- import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
7
+ import org.jetbrains.kotlin.analysis.api.analyze
8
8
import org.jetbrains.kotlin.psi.KtClassOrObject
9
9
import org.jetbrains.kotlin.psi.KtTypeReference
10
- import org.jetbrains.kotlin.resolve.BindingContext
11
- import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
12
- import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
13
10
14
11
private const val INSPECTION = " unused"
15
12
@@ -34,34 +31,38 @@ class ExpansionUnusedSuppressor: InspectionSuppressor {
34
31
35
32
private fun checkIfClassImplementsOrExtends (element : PsiElement , className : String ): Boolean {
36
33
val ktClass = PsiTreeUtil .getParentOfType(element, KtClassOrObject ::class .java) ? : return false
37
- val context = ktClass.getResolutionFacade().analyze(ktClass, BodyResolveMode .FULL )
38
- return ktClass.implementsInterface(className, context) || ktClass.isSubclassOf(className, context)
34
+ return analyze(ktClass) {
35
+ ktClass.implementsInterface(className) || ktClass.isSubclassOf(className)
36
+ }
39
37
}
40
38
41
- private fun KtClassOrObject.isSubclassOf (className : String , context : BindingContext ): Boolean {
39
+ private fun KtClassOrObject.isSubclassOf (className : String ): Boolean {
42
40
if (fqName?.asString() == className) return true
43
41
44
42
val superTypes = this .superTypeListEntries
45
43
return superTypes.any { typeEntry ->
46
44
val typeReference = typeEntry.typeReference
47
- val typeFqName = typeReference?.getFqName(context )
45
+ val typeFqName = typeReference?.getFqName()
48
46
typeFqName == className
49
47
}
50
48
}
51
49
52
- private fun KtClassOrObject.implementsInterface (interfaceName : String , context : BindingContext ): Boolean {
53
- if (isSubclassOf(interfaceName, context )) return true
50
+ private fun KtClassOrObject.implementsInterface (interfaceName : String ): Boolean {
51
+ if (isSubclassOf(interfaceName)) return true
54
52
55
53
val superTypes = this .superTypeListEntries
56
54
return superTypes.any { typeEntry ->
57
55
val typeReference = typeEntry.typeReference
58
- val typeFqName = typeReference?.getFqName(context )
56
+ val typeFqName = typeReference?.getFqName()
59
57
typeFqName == interfaceName
60
58
}
61
59
}
62
60
63
- private fun KtTypeReference.getFqName (context : BindingContext ): String? {
64
- val type = context[BindingContext .TYPE , this ]
65
- return type?.constructor ?.declarationDescriptor?.fqNameSafe?.asString()
61
+ private fun KtTypeReference.getFqName (): String? {
62
+ return analyze(this ) {
63
+ val type = type
64
+ val symbol = type.expandedSymbol
65
+ symbol?.classId?.asSingleFqName()?.asString()
66
+ }
66
67
}
67
68
}
0 commit comments