Generalize FirInterfaceWithSuperclassChecker to FirSupertypesChecker
This commit is contained in:
-26
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+32
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -75,7 +75,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
|||||||
FirDelegationSuperCallInEnumConstructorChecker,
|
FirDelegationSuperCallInEnumConstructorChecker,
|
||||||
FirDelegationInInterfaceSyntaxChecker,
|
FirDelegationInInterfaceSyntaxChecker,
|
||||||
FirEnumClassSimpleChecker,
|
FirEnumClassSimpleChecker,
|
||||||
FirInterfaceWithSuperclassChecker,
|
FirSupertypesChecker,
|
||||||
FirLocalEntityNotAllowedChecker,
|
FirLocalEntityNotAllowedChecker,
|
||||||
FirManyCompanionObjectsChecker,
|
FirManyCompanionObjectsChecker,
|
||||||
FirMethodOfAnyImplementedInInterfaceChecker,
|
FirMethodOfAnyImplementedInInterfaceChecker,
|
||||||
|
|||||||
Reference in New Issue
Block a user