Skip to content

Commit

Permalink
Simplify FirDelegationInInterfaceChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
mglukhikh committed Nov 26, 2020
1 parent b673996 commit d5f17ea
Showing 1 changed file with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit d5f17ea

Please sign in to comment.