[Wasm] Port external declaration checker to K2 (KT-56849)

Share common code with FirJsExternalChecker using
FirWebCommonExternalChecker
This commit is contained in:
Svyatoslav Kuzmich
2023-10-26 11:46:22 +02:00
committed by Space Team
parent 83aa014d81
commit 62ebb9932f
35 changed files with 948 additions and 547 deletions
@@ -11,6 +11,7 @@ import java.nio.file.Paths
import org.jetbrains.kotlin.analysis.api.fir.generator.DiagnosticClassGenerator.generate
import org.jetbrains.kotlin.fir.builder.SYNTAX_DIAGNOSTIC_LIST
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JS_DIAGNOSTICS_LIST
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.WEB_COMMON_DIAGNOSTICS_LIST
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
import org.jetbrains.kotlin.utils.SmartPrinter
import java.io.File
@@ -31,6 +32,7 @@ internal fun SmartPrinter.printGeneratedMessage() {
fun main() {
val rootPath = Paths.get("analysis/analysis-api-fir/src").toAbsolutePath()
val packageName = "org.jetbrains.kotlin.analysis.api.fir.diagnostics"
val diagnostics = DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST + JS_DIAGNOSTICS_LIST + SYNTAX_DIAGNOSTIC_LIST
val diagnostics = DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST + JS_DIAGNOSTICS_LIST + SYNTAX_DIAGNOSTIC_LIST +
WEB_COMMON_DIAGNOSTICS_LIST
generate(rootPath, diagnostics, packageName)
}
@@ -72,6 +72,7 @@ object FirDiagnosticToKtDiagnosticConverterRenderer : AbstractDiagnosticsDataCla
"org.jetbrains.kotlin.fir.builder.FirSyntaxErrors",
"org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors",
"org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors",
"org.jetbrains.kotlin.fir.analysis.diagnostics.web.common.FirWebCommonErrors",
"org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors",
)
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.diagnostics.KtPsiDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.web.common.FirWebCommonErrors
import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFunction
@@ -5500,85 +5501,18 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirJsErrors.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER) { firDiagnostic ->
ExternalClassConstructorPropertyParameterImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.EXTERNAL_ENUM_ENTRY_WITH_BODY) { firDiagnostic ->
ExternalEnumEntryWithBodyImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.EXTERNAL_ANONYMOUS_INITIALIZER) { firDiagnostic ->
ExternalAnonymousInitializerImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.EXTERNAL_DELEGATION) { firDiagnostic ->
ExternalDelegationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL) { firDiagnostic ->
ExternalDelegatedConstructorCallImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.WRONG_BODY_OF_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongBodyOfExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongInitializerOfExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER) { firDiagnostic ->
WrongDefaultValueForExternalFunParameterImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.NESTED_EXTERNAL_DECLARATION) { firDiagnostic ->
NestedExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.WRONG_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongExternalDeclarationImpl(
firDiagnostic.a,
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.NESTED_CLASS_IN_EXTERNAL_INTERFACE) { firDiagnostic ->
NestedClassInExternalInterfaceImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE) { firDiagnostic ->
ExternalTypeExtendsNonExternalTypeImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.INLINE_EXTERNAL_DECLARATION) { firDiagnostic ->
InlineExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.ENUM_CLASS_IN_EXTERNAL_DECLARATION_WARNING) { firDiagnostic ->
EnumClassInExternalDeclarationWarningImpl(
firDiagnostic as KtPsiDiagnostic,
@@ -5603,12 +5537,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirJsErrors.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE) { firDiagnostic ->
NonAbstractMemberOfExternalInterfaceImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJsErrors.NON_EXTERNAL_DECLARATION_IN_INAPPROPRIATE_FILE) { firDiagnostic ->
NonExternalDeclarationInInappropriateFileImpl(
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
@@ -5725,4 +5653,77 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirWebCommonErrors.NESTED_EXTERNAL_DECLARATION) { firDiagnostic ->
NestedExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.WRONG_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongExternalDeclarationImpl(
firDiagnostic.a,
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.NESTED_CLASS_IN_EXTERNAL_INTERFACE) { firDiagnostic ->
NestedClassInExternalInterfaceImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.INLINE_EXTERNAL_DECLARATION) { firDiagnostic ->
InlineExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE) { firDiagnostic ->
NonAbstractMemberOfExternalInterfaceImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER) { firDiagnostic ->
ExternalClassConstructorPropertyParameterImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.EXTERNAL_ANONYMOUS_INITIALIZER) { firDiagnostic ->
ExternalAnonymousInitializerImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.EXTERNAL_DELEGATION) { firDiagnostic ->
ExternalDelegationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL) { firDiagnostic ->
ExternalDelegatedConstructorCallImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.WRONG_BODY_OF_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongBodyOfExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION) { firDiagnostic ->
WrongInitializerOfExternalDeclarationImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirWebCommonErrors.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER) { firDiagnostic ->
WrongDefaultValueForExternalFunParameterImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
}
@@ -3826,59 +3826,14 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = CallToDefinedExternallyFromNonExternalDeclaration::class
}
interface ExternalClassConstructorPropertyParameter : KtFirDiagnostic<KtParameter> {
override val diagnosticClass get() = ExternalClassConstructorPropertyParameter::class
}
interface ExternalEnumEntryWithBody : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalEnumEntryWithBody::class
}
interface ExternalAnonymousInitializer : KtFirDiagnostic<KtAnonymousInitializer> {
override val diagnosticClass get() = ExternalAnonymousInitializer::class
}
interface ExternalDelegation : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalDelegation::class
}
interface ExternalDelegatedConstructorCall : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalDelegatedConstructorCall::class
}
interface WrongBodyOfExternalDeclaration : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongBodyOfExternalDeclaration::class
}
interface WrongInitializerOfExternalDeclaration : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongInitializerOfExternalDeclaration::class
}
interface WrongDefaultValueForExternalFunParameter : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongDefaultValueForExternalFunParameter::class
}
interface NestedExternalDeclaration : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NestedExternalDeclaration::class
}
interface WrongExternalDeclaration : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = WrongExternalDeclaration::class
val classKind: String
}
interface NestedClassInExternalInterface : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NestedClassInExternalInterface::class
}
interface ExternalTypeExtendsNonExternalType : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalTypeExtendsNonExternalType::class
}
interface InlineExternalDeclaration : KtFirDiagnostic<KtDeclaration> {
override val diagnosticClass get() = InlineExternalDeclaration::class
}
interface EnumClassInExternalDeclarationWarning : KtFirDiagnostic<KtDeclaration> {
override val diagnosticClass get() = EnumClassInExternalDeclarationWarning::class
}
@@ -3895,10 +3850,6 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = ExtensionFunctionInExternalDeclaration::class
}
interface NonAbstractMemberOfExternalInterface : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NonAbstractMemberOfExternalInterface::class
}
interface NonExternalDeclarationInInappropriateFile : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = NonExternalDeclarationInInappropriateFile::class
val type: KtType
@@ -3981,4 +3932,53 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
val message: String
}
interface NestedExternalDeclaration : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NestedExternalDeclaration::class
}
interface WrongExternalDeclaration : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = WrongExternalDeclaration::class
val classKind: String
}
interface NestedClassInExternalInterface : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NestedClassInExternalInterface::class
}
interface InlineExternalDeclaration : KtFirDiagnostic<KtDeclaration> {
override val diagnosticClass get() = InlineExternalDeclaration::class
}
interface NonAbstractMemberOfExternalInterface : KtFirDiagnostic<KtExpression> {
override val diagnosticClass get() = NonAbstractMemberOfExternalInterface::class
}
interface ExternalClassConstructorPropertyParameter : KtFirDiagnostic<KtParameter> {
override val diagnosticClass get() = ExternalClassConstructorPropertyParameter::class
}
interface ExternalAnonymousInitializer : KtFirDiagnostic<KtAnonymousInitializer> {
override val diagnosticClass get() = ExternalAnonymousInitializer::class
}
interface ExternalDelegation : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalDelegation::class
}
interface ExternalDelegatedConstructorCall : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = ExternalDelegatedConstructorCall::class
}
interface WrongBodyOfExternalDeclaration : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongBodyOfExternalDeclaration::class
}
interface WrongInitializerOfExternalDeclaration : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongInitializerOfExternalDeclaration::class
}
interface WrongDefaultValueForExternalFunParameter : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = WrongDefaultValueForExternalFunParameter::class
}
}
@@ -4620,72 +4620,16 @@ internal class CallToDefinedExternallyFromNonExternalDeclarationImpl(
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.CallToDefinedExternallyFromNonExternalDeclaration
internal class ExternalClassConstructorPropertyParameterImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtParameter>(firDiagnostic, token), KtFirDiagnostic.ExternalClassConstructorPropertyParameter
internal class ExternalEnumEntryWithBodyImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalEnumEntryWithBody
internal class ExternalAnonymousInitializerImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtAnonymousInitializer>(firDiagnostic, token), KtFirDiagnostic.ExternalAnonymousInitializer
internal class ExternalDelegationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalDelegation
internal class ExternalDelegatedConstructorCallImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalDelegatedConstructorCall
internal class WrongBodyOfExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongBodyOfExternalDeclaration
internal class WrongInitializerOfExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongInitializerOfExternalDeclaration
internal class WrongDefaultValueForExternalFunParameterImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongDefaultValueForExternalFunParameter
internal class NestedExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NestedExternalDeclaration
internal class WrongExternalDeclarationImpl(
override val classKind: String,
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.WrongExternalDeclaration
internal class NestedClassInExternalInterfaceImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NestedClassInExternalInterface
internal class ExternalTypeExtendsNonExternalTypeImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalTypeExtendsNonExternalType
internal class InlineExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtDeclaration>(firDiagnostic, token), KtFirDiagnostic.InlineExternalDeclaration
internal class EnumClassInExternalDeclarationWarningImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
@@ -4706,11 +4650,6 @@ internal class ExtensionFunctionInExternalDeclarationImpl(
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExtensionFunctionInExternalDeclaration
internal class NonAbstractMemberOfExternalInterfaceImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NonAbstractMemberOfExternalInterface
internal class NonExternalDeclarationInInappropriateFileImpl(
override val type: KtType,
firDiagnostic: KtPsiDiagnostic,
@@ -4810,3 +4749,64 @@ internal class SyntaxImpl(
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.Syntax
internal class NestedExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NestedExternalDeclaration
internal class WrongExternalDeclarationImpl(
override val classKind: String,
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.WrongExternalDeclaration
internal class NestedClassInExternalInterfaceImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NestedClassInExternalInterface
internal class InlineExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtDeclaration>(firDiagnostic, token), KtFirDiagnostic.InlineExternalDeclaration
internal class NonAbstractMemberOfExternalInterfaceImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtExpression>(firDiagnostic, token), KtFirDiagnostic.NonAbstractMemberOfExternalInterface
internal class ExternalClassConstructorPropertyParameterImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtParameter>(firDiagnostic, token), KtFirDiagnostic.ExternalClassConstructorPropertyParameter
internal class ExternalAnonymousInitializerImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtAnonymousInitializer>(firDiagnostic, token), KtFirDiagnostic.ExternalAnonymousInitializer
internal class ExternalDelegationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalDelegation
internal class ExternalDelegatedConstructorCallImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.ExternalDelegatedConstructorCall
internal class WrongBodyOfExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongBodyOfExternalDeclaration
internal class WrongInitializerOfExternalDeclarationImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongInitializerOfExternalDeclaration
internal class WrongDefaultValueForExternalFunParameterImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.WrongDefaultValueForExternalFunParameter