mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[kotlin] Use throwable as a root class to check
IJ-CR-168258 #KTIJ-30892 #KTIJ-34837 (cherry picked from commit 41b3cee7b143c753142a2d85cfddbe52ecba2134) IJ-MR-169152 GitOrigin-RevId: fae8c3f0ffa37bcf16404730339d33c156810b20
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5f6f79cb8f
commit
792ffcf24a
@@ -16,14 +16,13 @@ import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassSymbol
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
@@ -36,8 +35,8 @@ internal class ObjectInheritsExceptionInspection : AbstractKotlinInspection(), C
|
||||
val isException = analyze(declaration) {
|
||||
val symbol = declaration.symbol as? KaNamedClassSymbol ?: return
|
||||
symbol.superTypes.any {
|
||||
it.isClassType(exceptionClassId) ||
|
||||
it.isSubtypeOf(exceptionClassId)
|
||||
it.isClassType(throwableClassId) ||
|
||||
it.isSubtypeOf(throwableClassId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,4 +99,4 @@ internal class ObjectInheritsExceptionInspection : AbstractKotlinInspection(), C
|
||||
}
|
||||
}
|
||||
|
||||
private val exceptionClassId = ClassId(BUILT_INS_PACKAGE_FQ_NAME , Name.identifier("Exception"))
|
||||
private val throwableClassId = ClassId.topLevel( StandardNames.FqNames.throwable)
|
||||
|
||||
@@ -4,7 +4,7 @@ package some
|
||||
|
||||
import some.MyException
|
||||
|
||||
<caret>object MyException : Exception()
|
||||
<caret>object MyException : Throwable()
|
||||
|
||||
fun foo() {
|
||||
throw MyException
|
||||
|
||||
@@ -4,7 +4,7 @@ package some
|
||||
|
||||
import some.MyException
|
||||
|
||||
<caret>class MyException : Exception()
|
||||
<caret>class MyException : Throwable()
|
||||
|
||||
fun foo() {
|
||||
throw MyException()
|
||||
|
||||
Reference in New Issue
Block a user