Skip to content

Commit

Permalink
Simplify 'isK2' check
Browse files Browse the repository at this point in the history
  • Loading branch information
leveretka committed Nov 26, 2024
1 parent 8222d77 commit 3615c20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,13 @@
package org.sonarsource.kotlin.checks

import org.jetbrains.kotlin.analysis.api.KaIdeApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.descriptors.accessors
import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtImportDirective
import org.jetbrains.kotlin.psi.KtImportList
import org.jetbrains.kotlin.psi.KtOperationReferenceExpression
import org.jetbrains.kotlin.psi.KtPackageDirective
import org.jetbrains.kotlin.psi.KtPrefixExpression
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPropertyDelegate
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
import org.jetbrains.kotlin.psi.KtUserType
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi2ir.deparenthesize
Expand All @@ -53,7 +40,6 @@ import org.sonar.check.Rule
import org.sonarsource.kotlin.api.checks.AbstractCheck
import org.sonarsource.kotlin.api.frontend.KotlinFileContext
import org.sonarsource.kotlin.api.visiting.analyze
import org.sonarsource.kotlin.checks.UnnecessaryImportsHelper.isK2

private const val MESSAGE_UNUSED = "Remove this unused import."
private const val MESSAGE_REDUNDANT = "Remove this redundant import."
Expand All @@ -68,7 +54,7 @@ class UnnecessaryImportsCheck : AbstractCheck() {
override fun visitKtFile(file: KtFile, context: KotlinFileContext) {

analyze {
if (isK2(this)) {
if (this.isK2()) {
val analyzeImportsToOptimize = analyzeImportsToOptimize(file)

file.importDirectives.mapNotNull { import -> import.importedFqName?.let { import to it } }
Expand Down Expand Up @@ -285,3 +271,6 @@ private fun KtReferenceExpression.importableSimpleName() =
is KtSimpleNameExpression -> getReferencedName()
else -> null
}

fun KaSession.isK2(): Boolean =
"org.jetbrains.kotlin.analysis.api.fir.KaFirSession" == javaClass.name

This file was deleted.

0 comments on commit 3615c20

Please sign in to comment.