Simplify FirDelegationInInterfaceChecker
This commit is contained in:
+5
-20
@@ -5,13 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
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
|
||||
@@ -23,23 +20,11 @@ object FirDelegationInInterfaceChecker : FirMemberDeclarationChecker() {
|
||||
return
|
||||
}
|
||||
|
||||
declaration.source?.findSuperTypeDelegation()?.let {
|
||||
reporter.report(declaration.superTypeRefs.getOrNull(it)?.source)
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirSourceElement.findSuperTypeDelegation(): Int =
|
||||
lighterASTNode.findSuperTypeDelegation(treeStructure)
|
||||
|
||||
private fun LighterASTNode.findSuperTypeDelegation(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.DELEGATED_SUPER_TYPE_ENTRY }
|
||||
?: -1
|
||||
} else {
|
||||
-1
|
||||
for (superTypeRef in declaration.superTypeRefs) {
|
||||
val source = superTypeRef.source ?: continue
|
||||
if (source.treeStructure.getParent(source.lighterASTNode)?.tokenType == KtNodeTypes.DELEGATED_SUPER_TYPE_ENTRY) {
|
||||
reporter.report(source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user