FIR checkers: simplify FirSupertypeInitializedWithoutPrimaryConstructor
This commit is contained in:
+4
-25
@@ -6,22 +6,17 @@
|
|||||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||||
|
|
||||||
import com.intellij.lang.LighterASTNode
|
import com.intellij.lang.LighterASTNode
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.psi.PsiErrorElement
|
|
||||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
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.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.findChildByType
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.psi
|
|
||||||
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
|
|
||||||
|
|
||||||
object FirSupertypeInitializedWithoutPrimaryConstructor : FirMemberDeclarationChecker() {
|
object FirSupertypeInitializedWithoutPrimaryConstructor : FirMemberDeclarationChecker() {
|
||||||
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
@@ -38,28 +33,12 @@ object FirSupertypeInitializedWithoutPrimaryConstructor : FirMemberDeclarationCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FirSourceElement.anySupertypeHasConstructorParentheses(): Boolean {
|
private fun FirSourceElement.anySupertypeHasConstructorParentheses(): Boolean {
|
||||||
val localPsi = psi
|
return lighterASTNode.anySupertypeHasConstructorParentheses(treeStructure)
|
||||||
val localLightNode = lighterASTNode
|
|
||||||
|
|
||||||
if (localPsi != null && localPsi !is PsiErrorElement) {
|
|
||||||
return localPsi.anySupertypeHasConstructorParentheses()
|
|
||||||
} else if (this is FirLightSourceElement) {
|
|
||||||
return localLightNode.anySupertypeHasConstructorParentheses(treeStructure)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun PsiElement.anySupertypeHasConstructorParentheses(): Boolean {
|
|
||||||
val children = this.children // this is a method call and it collects children
|
|
||||||
return children.isNotEmpty() && children[0] !is PsiErrorElement && children[0].children.any { it is KtSuperTypeCallEntry }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun LighterASTNode.anySupertypeHasConstructorParentheses(tree: FlyweightCapableTreeStructure<LighterASTNode>): Boolean {
|
private fun LighterASTNode.anySupertypeHasConstructorParentheses(tree: FlyweightCapableTreeStructure<LighterASTNode>): Boolean {
|
||||||
val superTypes = getChildren(tree).find { it?.tokenType == KtNodeTypes.SUPER_TYPE_LIST }
|
val superTypes = tree.findChildByType(this, KtNodeTypes.SUPER_TYPE_LIST) ?: return false
|
||||||
?: return false
|
return tree.findChildByType(superTypes, KtNodeTypes.SUPER_TYPE_CALL_ENTRY) != null
|
||||||
|
|
||||||
return superTypes.getChildren(tree).any { it?.tokenType == KtNodeTypes.SUPER_TYPE_CALL_ENTRY }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DiagnosticReporter.report(source: FirSourceElement?) {
|
private fun DiagnosticReporter.report(source: FirSourceElement?) {
|
||||||
|
|||||||
+1
-1
@@ -198,7 +198,7 @@ private fun FlyweightCapableTreeStructure<LighterASTNode>.receiverTypeReference(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FlyweightCapableTreeStructure<LighterASTNode>.findChildByType(node: LighterASTNode, type: IElementType): LighterASTNode? {
|
fun FlyweightCapableTreeStructure<LighterASTNode>.findChildByType(node: LighterASTNode, type: IElementType): LighterASTNode? {
|
||||||
val childrenRef = Ref<Array<LighterASTNode?>>()
|
val childrenRef = Ref<Array<LighterASTNode?>>()
|
||||||
getChildren(node, childrenRef)
|
getChildren(node, childrenRef)
|
||||||
return childrenRef.get()?.firstOrNull { it?.tokenType == type }
|
return childrenRef.get()?.firstOrNull { it?.tokenType == type }
|
||||||
|
|||||||
Reference in New Issue
Block a user