mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-24 00:21:28 +00:00
Simplify FirSupertypeInitializedWithoutPrimaryConstructor checker
This commit is contained in:
@@ -5,15 +5,12 @@
|
||||
|
||||
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.diagnostics.DiagnosticReporter
|
||||
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.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
@@ -24,21 +21,16 @@ object FirSupertypeInitializedWithoutPrimaryConstructor : FirMemberDeclarationCh
|
||||
return
|
||||
}
|
||||
|
||||
val hasSupertypeWithConstructor = declaration.source?.anySupertypeHasConstructorParentheses() == true
|
||||
val hasPrimaryConstructor = declaration.declarations.any { it is FirConstructor && it.isPrimary }
|
||||
|
||||
if (hasSupertypeWithConstructor && !hasPrimaryConstructor) {
|
||||
reporter.report(declaration.source)
|
||||
if (declaration.declarations.any { it is FirConstructor && it.isPrimary }) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirSourceElement.anySupertypeHasConstructorParentheses(): Boolean {
|
||||
return lighterASTNode.anySupertypeHasConstructorParentheses(treeStructure)
|
||||
}
|
||||
|
||||
private fun LighterASTNode.anySupertypeHasConstructorParentheses(tree: FlyweightCapableTreeStructure<LighterASTNode>): Boolean {
|
||||
val superTypes = tree.findChildByType(this, KtNodeTypes.SUPER_TYPE_LIST) ?: return false
|
||||
return tree.findChildByType(superTypes, KtNodeTypes.SUPER_TYPE_CALL_ENTRY) != null
|
||||
for (superTypeRef in declaration.superTypeRefs) {
|
||||
val source = superTypeRef.source ?: continue
|
||||
if (source.treeStructure.getParent(source.lighterASTNode)?.tokenType == KtNodeTypes.CONSTRUCTOR_CALLEE) {
|
||||
reporter.report(declaration.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.report(source: FirSourceElement?) {
|
||||
|
||||
Reference in New Issue
Block a user