Skip to content

Commit

Permalink
(WIP) TODO IsInstanceMethodCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Oct 8, 2024
1 parent 9289636 commit 1be44a1
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
package org.sonarsource.kotlin.checks

import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaClassLikeSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
Expand Down Expand Up @@ -75,8 +79,12 @@ class IsInstanceMethodCheck : CallAbstractCheck() {
private fun isJavaClassKeyword(expr: KtExpression?): Boolean =
(expr is KtNameReferenceExpression) && (expr.getReferencedName() in JAVA_CLASS_KEYWORDS)

// TODO easy
private fun KtReferenceExpression.isClass(ctx: KotlinFileContext) =
ctx.bindingContext[BindingContext.REFERENCE_TARGET, this] is ClassDescriptor
// TODO fails in K2 mode
private fun KtReferenceExpression.isClass(ctx: KotlinFileContext): Boolean {
val expression = this
analyze(expression) {
return expression.mainReference.resolveToSymbol() is KaClassSymbol
}
}

}

0 comments on commit 1be44a1

Please sign in to comment.