Generalize FirInterfaceWithSuperclassChecker to FirSupertypesChecker

This commit is contained in:
Mikhail Glukhikh
2021-05-06 13:01:24 +03:00
parent 632a9d66d1
commit db828a6aad
3 changed files with 33 additions and 27 deletions
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.findNonInterfaceSupertype
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isInterface
object FirInterfaceWithSuperclassChecker : FirRegularClassChecker() {
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
if (!declaration.isInterface) {
return
}
declaration.findNonInterfaceSupertype(context)?.let {
reporter.reportOn(it.source, FirErrors.INTERFACE_WITH_SUPERCLASS, context)
}
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.descriptors.ClassKind
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.reportOn
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
object FirSupertypesChecker : FirClassChecker() {
override fun check(declaration: FirClass<*>, context: CheckerContext, reporter: DiagnosticReporter) {
val isInterface = declaration.classKind == ClassKind.INTERFACE
for (superTypeRef in declaration.superTypeRefs) {
val lookupTag = superTypeRef.coneType.safeAs<ConeClassLikeType>()?.lookupTag ?: continue
val superTypeFir = lookupTag.toSymbol(context.session)?.fir
if (isInterface && superTypeFir is FirClass<*> && superTypeFir.classKind != ClassKind.INTERFACE) {
reporter.reportOn(superTypeRef.source, FirErrors.INTERFACE_WITH_SUPERCLASS, context)
return
}
}
}
}
@@ -75,7 +75,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
FirDelegationSuperCallInEnumConstructorChecker,
FirDelegationInInterfaceSyntaxChecker,
FirEnumClassSimpleChecker,
FirInterfaceWithSuperclassChecker,
FirSupertypesChecker,
FirLocalEntityNotAllowedChecker,
FirManyCompanionObjectsChecker,
FirMethodOfAnyImplementedInInterfaceChecker,