FIR: add 'withSuppressedDiagnostics' call to property checkers
This commit is contained in:
+64
-61
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
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.analysis.diagnostics.withSuppressedDiagnostics
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
@@ -150,76 +151,78 @@ object FirMemberPropertiesChecker : FirRegularClassChecker() {
|
|||||||
// So, our source of truth should be the full modifier list retrieved from the source.
|
// So, our source of truth should be the full modifier list retrieved from the source.
|
||||||
val modifierList = property.source.getModifierList()
|
val modifierList = property.source.getModifierList()
|
||||||
|
|
||||||
checkPropertyInitializer(
|
withSuppressedDiagnostics(property, context) {
|
||||||
containingDeclaration,
|
checkPropertyInitializer(
|
||||||
property,
|
containingDeclaration,
|
||||||
modifierList,
|
property,
|
||||||
isInitialized,
|
modifierList,
|
||||||
reporter,
|
isInitialized,
|
||||||
context
|
reporter,
|
||||||
)
|
context
|
||||||
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
)
|
||||||
|
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
||||||
|
|
||||||
val hasAbstractModifier = KtTokens.ABSTRACT_KEYWORD in modifierList
|
val hasAbstractModifier = KtTokens.ABSTRACT_KEYWORD in modifierList
|
||||||
val isAbstract = property.isAbstract || hasAbstractModifier
|
val isAbstract = property.isAbstract || hasAbstractModifier
|
||||||
if (containingDeclaration.isInterface &&
|
if (containingDeclaration.isInterface &&
|
||||||
Visibilities.isPrivate(property.visibility) &&
|
Visibilities.isPrivate(property.visibility) &&
|
||||||
!isAbstract &&
|
!isAbstract &&
|
||||||
(property.getter == null || property.getter is FirDefaultPropertyAccessor)
|
(property.getter == null || property.getter is FirDefaultPropertyAccessor)
|
||||||
) {
|
) {
|
||||||
property.source?.let {
|
|
||||||
reporter.reportOn(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAbstract) {
|
|
||||||
if (!containingDeclaration.canHaveAbstractDeclaration) {
|
|
||||||
property.source?.let {
|
property.source?.let {
|
||||||
reporter.reportOn(
|
reporter.reportOn(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE, context)
|
||||||
it,
|
|
||||||
FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS,
|
|
||||||
property,
|
|
||||||
containingDeclaration,
|
|
||||||
context
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property.initializer?.source?.let {
|
|
||||||
reporter.reportOn(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER, context)
|
|
||||||
}
|
|
||||||
property.delegate?.source?.let {
|
|
||||||
reporter.reportOn(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAccessor(property.getter, property.delegate) { src, _, hasBody ->
|
if (isAbstract) {
|
||||||
if (hasBody) reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER, context)
|
if (!containingDeclaration.canHaveAbstractDeclaration) {
|
||||||
}
|
property.source?.let {
|
||||||
checkAccessor(property.setter, property.delegate) { src, symbol, hasBody ->
|
reporter.reportOn(
|
||||||
when {
|
it,
|
||||||
symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private ->
|
FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS,
|
||||||
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, context)
|
property,
|
||||||
hasBody -> reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER, context)
|
containingDeclaration,
|
||||||
|
context
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
property.initializer?.source?.let {
|
||||||
|
reporter.reportOn(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER, context)
|
||||||
|
}
|
||||||
|
property.delegate?.source?.let {
|
||||||
|
reporter.reportOn(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAccessor(property.getter, property.delegate) { src, _, hasBody ->
|
||||||
|
if (hasBody) reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER, context)
|
||||||
|
}
|
||||||
|
checkAccessor(property.setter, property.delegate) { src, symbol, hasBody ->
|
||||||
|
when {
|
||||||
|
symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private ->
|
||||||
|
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, context)
|
||||||
|
hasBody -> reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val hasOpenModifier = KtTokens.OPEN_KEYWORD in modifierList
|
val hasOpenModifier = KtTokens.OPEN_KEYWORD in modifierList
|
||||||
if (hasOpenModifier &&
|
if (hasOpenModifier &&
|
||||||
containingDeclaration.isInterface &&
|
containingDeclaration.isInterface &&
|
||||||
!hasAbstractModifier &&
|
!hasAbstractModifier &&
|
||||||
property.isAbstract &&
|
property.isAbstract &&
|
||||||
!isInsideExpectClass(containingDeclaration, context)
|
!isInsideExpectClass(containingDeclaration, context)
|
||||||
) {
|
) {
|
||||||
property.source?.let {
|
property.source?.let {
|
||||||
reporter.reportOn(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
|
reporter.reportOn(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
val isOpen = property.isOpen || hasOpenModifier
|
||||||
val isOpen = property.isOpen || hasOpenModifier
|
if (isOpen) {
|
||||||
if (isOpen) {
|
checkAccessor(property.setter, property.delegate) { src, symbol, _ ->
|
||||||
checkAccessor(property.setter, property.delegate) { src, symbol, _ ->
|
if (symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private) {
|
||||||
if (symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private) {
|
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY, context)
|
||||||
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY, context)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-9
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
|||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
|
import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
|
|
||||||
@@ -29,14 +30,16 @@ object FirTopLevelPropertiesChecker : FirFileChecker() {
|
|||||||
// So, our source of truth should be the full modifier list retrieved from the source.
|
// So, our source of truth should be the full modifier list retrieved from the source.
|
||||||
val modifierList = source.getModifierList()
|
val modifierList = source.getModifierList()
|
||||||
|
|
||||||
checkPropertyInitializer(
|
withSuppressedDiagnostics(property, context) {
|
||||||
containingClass = null,
|
checkPropertyInitializer(
|
||||||
property,
|
containingClass = null,
|
||||||
modifierList,
|
property,
|
||||||
isInitialized = property.initializer != null,
|
modifierList,
|
||||||
reporter,
|
isInitialized = property.initializer != null,
|
||||||
context
|
reporter,
|
||||||
)
|
context
|
||||||
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
)
|
||||||
|
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user