org.jetbrains.kotlin.diagnostics.DiagnosticFactoryForDeprecation.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2021 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.diagnostics
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
sealed class DiagnosticFactoryForDeprecation>(
val deprecatingFeature: LanguageFeature,
val warningFactory: F,
val errorFactory: F
) {
fun LanguageVersionSettings.chooseFactory(): F {
return if (supportsFeature(deprecatingFeature)) errorFactory else warningFactory
}
}
class DiagnosticFactoryForDeprecation0(
featureForError: LanguageFeature,
warningFactory: DiagnosticFactory0,
errorFactory: DiagnosticFactory0
) : DiagnosticFactoryForDeprecation, DiagnosticFactory0>(featureForError, warningFactory, errorFactory) {
companion object {
@JvmStatic
@JvmOverloads
fun create(
featureForError: LanguageFeature,
positioningStrategy: PositioningStrategy = PositioningStrategies.DEFAULT
): DiagnosticFactoryForDeprecation0 {
return DiagnosticFactoryForDeprecation0(
featureForError,
warningFactory = DiagnosticFactory0.create(Severity.WARNING, positioningStrategy),
errorFactory = DiagnosticFactory0.create(Severity.ERROR, positioningStrategy),
)
}
}
fun on(languageVersionSettings: LanguageVersionSettings, element: E): SimpleDiagnostic {
return languageVersionSettings.chooseFactory().on(element)
}
fun onError(element: E): SimpleDiagnostic = errorFactory.on(element)
}
class DiagnosticFactoryForDeprecation1(
featureForError: LanguageFeature,
warningFactory: DiagnosticFactory1,
errorFactory: DiagnosticFactory1
) : DiagnosticFactoryForDeprecation, DiagnosticFactory1>(featureForError, warningFactory, errorFactory) {
companion object {
@JvmStatic
@JvmOverloads
fun create(
featureForError: LanguageFeature,
positioningStrategy: PositioningStrategy = PositioningStrategies.DEFAULT
): DiagnosticFactoryForDeprecation1 {
return DiagnosticFactoryForDeprecation1(
featureForError,
warningFactory = DiagnosticFactory1.create(Severity.WARNING, positioningStrategy),
errorFactory = DiagnosticFactory1.create(Severity.ERROR, positioningStrategy),
)
}
}
fun on(languageVersionSettings: LanguageVersionSettings, element: E, a: A): ParametrizedDiagnostic {
return languageVersionSettings.chooseFactory().on(element, a)
}
}
class DiagnosticFactoryForDeprecation2(
featureForError: LanguageFeature,
warningFactory: DiagnosticFactory2,
errorFactory: DiagnosticFactory2
) : DiagnosticFactoryForDeprecation, DiagnosticFactory2>(featureForError, warningFactory, errorFactory) {
companion object {
@JvmStatic
@JvmOverloads
fun create(
featureForError: LanguageFeature,
positioningStrategy: PositioningStrategy = PositioningStrategies.DEFAULT
): DiagnosticFactoryForDeprecation2 {
return DiagnosticFactoryForDeprecation2(
featureForError,
warningFactory = DiagnosticFactory2.create(Severity.WARNING, positioningStrategy),
errorFactory = DiagnosticFactory2.create(Severity.ERROR, positioningStrategy),
)
}
}
fun on(languageVersionSettings: LanguageVersionSettings, element: E, a: A, b: B): ParametrizedDiagnostic {
return languageVersionSettings.chooseFactory().on(element, a, b)
}
}
class DiagnosticFactoryForDeprecation3(
featureForError: LanguageFeature,
warningFactory: DiagnosticFactory3,
errorFactory: DiagnosticFactory3
) : DiagnosticFactoryForDeprecation, DiagnosticFactory3>(featureForError, warningFactory, errorFactory) {
companion object {
@JvmStatic
@JvmOverloads
fun create(
featureForError: LanguageFeature,
positioningStrategy: PositioningStrategy = PositioningStrategies.DEFAULT
): DiagnosticFactoryForDeprecation3 {
return DiagnosticFactoryForDeprecation3(
featureForError,
warningFactory = DiagnosticFactory3.create(Severity.WARNING, positioningStrategy),
errorFactory = DiagnosticFactory3.create(Severity.ERROR, positioningStrategy),
)
}
}
fun on(languageVersionSettings: LanguageVersionSettings, element: E, a: A, b: B, c: C): ParametrizedDiagnostic {
return languageVersionSettings.chooseFactory().on(element, a, b, c)
}
}
class DiagnosticFactoryForDeprecation4(
featureForError: LanguageFeature,
warningFactory: DiagnosticFactory4,
errorFactory: DiagnosticFactory4
) : DiagnosticFactoryForDeprecation, DiagnosticFactory4>(featureForError, warningFactory, errorFactory) {
companion object {
@JvmStatic
@JvmOverloads
fun create(
featureForError: LanguageFeature,
positioningStrategy: PositioningStrategy = PositioningStrategies.DEFAULT
): DiagnosticFactoryForDeprecation4 {
return DiagnosticFactoryForDeprecation4(
featureForError,
warningFactory = DiagnosticFactory4.create(Severity.WARNING, positioningStrategy),
errorFactory = DiagnosticFactory4.create(Severity.ERROR, positioningStrategy),
)
}
}
fun on(languageVersionSettings: LanguageVersionSettings, element: E, a: A, b: B, c: C, d: D): ParametrizedDiagnostic {
return languageVersionSettings.chooseFactory().on(element, a, b, c, d)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy