Reduce allocations in KotlinTarget and modifier checkers
This commit is contained in:
committed by
TeamCityServer
parent
2c1c24c042
commit
f2ffead881
+8
-6
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.Companion.classActualTargets
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
@@ -53,9 +52,12 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
if (list.modifiers.isEmpty()) return
|
||||
|
||||
// general strategy: report no more than one error and any number of warnings
|
||||
// therefore, a track of nodes with already reported errors should be kept
|
||||
val reportedNodes = hashSetOf<FirModifier<*>>()
|
||||
|
||||
val actualTargets = getActualTargetList(owner).defaultTargets
|
||||
|
||||
val parent = context.findClosest<FirDeclaration> {
|
||||
@@ -65,17 +67,17 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
|
||||
}
|
||||
|
||||
val actualParents = when (parent) {
|
||||
is FirAnonymousObject -> listOf(LOCAL_CLASS, CLASS)
|
||||
is FirAnonymousObject -> KotlinTarget.LOCAL_CLASS_LIST
|
||||
is FirClass -> classActualTargets(
|
||||
parent.classKind,
|
||||
isInnerClass = (parent as? FirMemberDeclaration)?.isInner ?: false,
|
||||
isCompanionObject = (parent as? FirRegularClass)?.isCompanion ?: false,
|
||||
isLocalClass = parent.isLocal
|
||||
)
|
||||
is FirPropertyAccessor -> listOf(if (parent.isSetter) PROPERTY_SETTER else PROPERTY_GETTER)
|
||||
is FirFunction -> listOf(FUNCTION)
|
||||
is FirEnumEntry -> listOf(ENUM_ENTRY, PROPERTY, FIELD)
|
||||
else -> listOf(FILE)
|
||||
is FirPropertyAccessor -> if (parent.isSetter) KotlinTarget.PROPERTY_SETTER_LIST else KotlinTarget.PROPERTY_GETTER_LIST
|
||||
is FirFunction -> KotlinTarget.FUNCTION_LIST
|
||||
is FirEnumEntry -> KotlinTarget.ENUM_ENTRY_LIST
|
||||
else -> KotlinTarget.FILE_LIST
|
||||
}
|
||||
|
||||
val modifiers = list.modifiers
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
@@ -206,10 +205,10 @@ object ModifierCheckerCore {
|
||||
isCompanionObject = parentDescriptor.isCompanionObject,
|
||||
isLocalClass = DescriptorUtils.isLocal(parentDescriptor)
|
||||
)
|
||||
is PropertySetterDescriptor -> listOf(PROPERTY_SETTER)
|
||||
is PropertyGetterDescriptor -> listOf(PROPERTY_GETTER)
|
||||
is FunctionDescriptor -> listOf(FUNCTION)
|
||||
else -> listOf(FILE)
|
||||
is PropertySetterDescriptor -> KotlinTarget.PROPERTY_SETTER_LIST
|
||||
is PropertyGetterDescriptor -> KotlinTarget.PROPERTY_GETTER_LIST
|
||||
is FunctionDescriptor -> KotlinTarget.FUNCTION_LIST
|
||||
else -> KotlinTarget.FILE_LIST
|
||||
}
|
||||
val deprecatedParents = deprecatedParentTargetMap[modifierType]
|
||||
if (deprecatedParents != null && actualParents.any { it in deprecatedParents }) {
|
||||
|
||||
Reference in New Issue
Block a user