FIR: introduce diagnostic NESTED_CLASS_NOT_ALLOWED

This commit is contained in:
Tianyu Geng
2021-02-19 15:52:43 -08:00
committed by Mikhail Glukhikh
parent c5cabce2d5
commit 724ca1d3ee
39 changed files with 125 additions and 103 deletions
@@ -173,7 +173,10 @@ internal class NonReanalyzableDeclarationStructureElement(
firFile,
onDeclarationEnter = { firDeclaration ->
when {
firDeclaration.isGeneratedDeclaration -> DiagnosticCollectorDeclarationAction.SKIP
// Some generated declaration contains structures that we need to check. For example the FIR representation of an
// enum entry initializer, when present, is a generated anonymous object of kind `ENUM_ENTRY`.
firDeclaration.isGeneratedDeclaration ->
DiagnosticCollectorDeclarationAction.SKIP_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration is FirFile -> DiagnosticCollectorDeclarationAction.CHECK_CURRENT_DECLARATION_AND_CHECK_NESTED
firDeclaration == fir -> {
inCurrentDeclaration = true
@@ -99,6 +99,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.NESTED_CLASS_NOT_ALLOWED) { firDiagnostic ->
NestedClassNotAllowedImpl(
firDiagnostic.a,
firDiagnostic as FirPsiDiagnostic<*>,
token,
)
}
add(FirErrors.HIDDEN) { firDiagnostic ->
HiddenImpl(
firSymbolBuilder.buildSymbol(firDiagnostic.a.fir as FirDeclaration),
@@ -83,6 +83,11 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = DelegationInInterface::class
}
abstract class NestedClassNotAllowed : KtFirDiagnostic<KtNamedDeclaration>() {
override val diagnosticClass get() = NestedClassNotAllowed::class
abstract val declaration: String
}
abstract class Hidden : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = Hidden::class
abstract val hidden: KtSymbol
@@ -114,6 +114,14 @@ internal class DelegationInInterfaceImpl(
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
}
internal class NestedClassNotAllowedImpl(
override val declaration: String,
firDiagnostic: FirPsiDiagnostic<*>,
override val token: ValidityToken,
) : KtFirDiagnostic.NestedClassNotAllowed(), KtAbstractFirDiagnostic<KtNamedDeclaration> {
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
}
internal class HiddenImpl(
override val hidden: KtSymbol,
firDiagnostic: FirPsiDiagnostic<*>,