Simplify FirMethodOfAnyImplementedInInterfaceChecker
* Override CallableId and operator tag parts only, not entire function representation * Even more lazyness for inspector creation
This commit is contained in:
committed by
Mikhail Glukhikh
parent
338595703c
commit
0e9474342d
+7
-3
@@ -149,6 +149,12 @@ interface FirDeclarationPresenter {
|
|||||||
appendRepresentation(it.symbol.callableId)
|
appendRepresentation(it.symbol.callableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendOperatorTag(it: FirSimpleFunction) {
|
||||||
|
if (it.isOperator) {
|
||||||
|
append("operator ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun represent(it: FirSimpleFunction) = buildString {
|
fun represent(it: FirSimpleFunction) = buildString {
|
||||||
append('<')
|
append('<')
|
||||||
it.typeParameters.forEach {
|
it.typeParameters.forEach {
|
||||||
@@ -161,9 +167,7 @@ interface FirDeclarationPresenter {
|
|||||||
appendRepresentation(it)
|
appendRepresentation(it)
|
||||||
}
|
}
|
||||||
append(']')
|
append(']')
|
||||||
if (it.isOperator) {
|
appendOperatorTag(it)
|
||||||
append("operator ")
|
|
||||||
}
|
|
||||||
appendRepresentation(it.symbol.callableId)
|
appendRepresentation(it.symbol.callableId)
|
||||||
append('(')
|
append('(')
|
||||||
it.valueParameters.forEach {
|
it.valueParameters.forEach {
|
||||||
|
|||||||
+12
-21
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.symbolProvider
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), FirDeclarationPresenter {
|
object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), FirDeclarationPresenter {
|
||||||
@@ -33,26 +34,14 @@ object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), F
|
|||||||
inspector = this
|
inspector = this
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DuplicatedCode")
|
// We need representations that look like JVM signatures. Thus, just function names, not fully qualified ones.
|
||||||
override fun represent(it: FirSimpleFunction) = buildString {
|
override fun StringBuilder.appendRepresentation(it: CallableId) {
|
||||||
append('<')
|
append(it.callableName)
|
||||||
it.typeParameters.forEach {
|
}
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
// We need representations that look like JVM signatures. Hence, no need to represent operator.
|
||||||
}
|
override fun StringBuilder.appendOperatorTag(it: FirSimpleFunction) {
|
||||||
append('>')
|
// Intentionally empty
|
||||||
append('[')
|
|
||||||
it.receiverTypeRef?.let {
|
|
||||||
appendRepresentation(it)
|
|
||||||
}
|
|
||||||
append(']')
|
|
||||||
append(it.name.asString())
|
|
||||||
append('(')
|
|
||||||
it.valueParameters.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append(')')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
@@ -61,9 +50,11 @@ object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), F
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (it in declaration.declarations) {
|
for (it in declaration.declarations) {
|
||||||
|
if (it !is FirSimpleFunction || !it.isOverride || !it.hasBody) continue
|
||||||
|
|
||||||
val inspector = getInspector(context)
|
val inspector = getInspector(context)
|
||||||
|
|
||||||
if (it is FirSimpleFunction && inspector.contains(it) && it.body != null && it.isOverride) {
|
if (inspector.contains(it)) {
|
||||||
reporter.reportOn(it.source, FirErrors.ANY_METHOD_IMPLEMENTED_IN_INTERFACE, context)
|
reporter.reportOn(it.source, FirErrors.ANY_METHOD_IMPLEMENTED_IN_INTERFACE, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user