Simplify FirSupertypeInitializedInInterfaceChecker
This commit is contained in:
+1
-1
@@ -5,4 +5,4 @@ interface B : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>A
|
||||
interface C
|
||||
class D
|
||||
|
||||
interface E : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>A<!>(), C, D()
|
||||
interface E : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>A<!>(), C, <!SUPERTYPE_INITIALIZED_IN_INTERFACE!>D<!>()
|
||||
Vendored
+1
-1
@@ -8,6 +8,6 @@ interface D : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>C
|
||||
|
||||
interface E : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>Any<!>()
|
||||
|
||||
interface F : A, <!SUPERTYPE_INITIALIZED_IN_INTERFACE!>B<!>(), <!INTERFACE_WITH_SUPERCLASS!>C<!>, D(), Any() {
|
||||
interface F : A, <!SUPERTYPE_INITIALIZED_IN_INTERFACE!>B<!>(), <!INTERFACE_WITH_SUPERCLASS!>C<!>, <!SUPERTYPE_INITIALIZED_IN_INTERFACE!>D<!>(), <!SUPERTYPE_INITIALIZED_IN_INTERFACE!>Any<!>() {
|
||||
|
||||
}
|
||||
+5
-44
@@ -5,22 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getChildren
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
|
||||
|
||||
object FirSupertypeInitializedInInterfaceChecker : FirMemberDeclarationChecker() {
|
||||
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
@@ -28,42 +20,11 @@ object FirSupertypeInitializedInInterfaceChecker : FirMemberDeclarationChecker()
|
||||
return
|
||||
}
|
||||
|
||||
declaration.source?.findSuperTypeCall()?.let {
|
||||
reporter.report(declaration.superTypeRefs.getOrNull(it)?.source)
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirSourceElement.findSuperTypeCall(): Int {
|
||||
val localPsi = psi
|
||||
val localLightNode = lighterASTNode
|
||||
|
||||
if (localPsi != null && localPsi !is PsiErrorElement) {
|
||||
return localPsi.findSuperTypeCall()
|
||||
} else if (this is FirLightSourceElement) {
|
||||
return localLightNode.findSuperTypeCall(treeStructure)
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
private fun PsiElement.findSuperTypeCall(): Int {
|
||||
val children = this.children // this is a method call and it collects children
|
||||
return if (children.isNotEmpty() && children[0] !is PsiErrorElement) {
|
||||
children[0].children.indexOfFirst { it is KtSuperTypeCallEntry }
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
private fun LighterASTNode.findSuperTypeCall(tree: FlyweightCapableTreeStructure<LighterASTNode>): Int {
|
||||
val children = getChildren(tree)
|
||||
return if (children.isNotEmpty()) {
|
||||
children.find { it?.tokenType == KtNodeTypes.SUPER_TYPE_LIST }
|
||||
?.getChildren(tree)
|
||||
?.indexOfFirst { it?.tokenType == KtNodeTypes.SUPER_TYPE_CALL_ENTRY }
|
||||
?: -1
|
||||
} else {
|
||||
-1
|
||||
for (superTypeRef in declaration.superTypeRefs) {
|
||||
val source = superTypeRef.source ?: continue
|
||||
if (source.treeStructure.getParent(source.lighterASTNode)?.tokenType == KtNodeTypes.CONSTRUCTOR_CALLEE) {
|
||||
reporter.report(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
open class bar()
|
||||
|
||||
interface <!CONSTRUCTOR_IN_INTERFACE!>Foo()<!> : <!INTERFACE_WITH_SUPERCLASS!>bar<!>(), bar, bar {
|
||||
interface <!CONSTRUCTOR_IN_INTERFACE!>Foo()<!> : <!INTERFACE_WITH_SUPERCLASS, SUPERTYPE_INITIALIZED_IN_INTERFACE!>bar<!>(), bar, bar {
|
||||
}
|
||||
|
||||
interface Foo2 : <!INTERFACE_WITH_SUPERCLASS!>bar<!>, Foo {
|
||||
|
||||
Reference in New Issue
Block a user