Remove deprecated Flag usages in MetadataDeclarationsComparator.kt
#KT-59440
This commit is contained in:
committed by
Space Team
parent
2b6ca6d8e1
commit
06c471d413
+86
-115
@@ -3,8 +3,6 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("DEPRECATION") // TODO: kotlinx.metadata Flags API. Usage here is too big.
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.commonizer.metadata.utils
|
package org.jetbrains.kotlin.commonizer.metadata.utils
|
||||||
|
|
||||||
import com.intellij.util.containers.FactoryMap
|
import com.intellij.util.containers.FactoryMap
|
||||||
@@ -30,7 +28,7 @@ import kotlin.contracts.ExperimentalContracts
|
|||||||
import kotlin.error
|
import kotlin.error
|
||||||
import kotlin.let
|
import kotlin.let
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
import kotlin.reflect.KProperty0
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two metadata modules ([KlibModuleMetadata]). Returns [Result], which may hold a list
|
* Compares two metadata modules ([KlibModuleMetadata]). Returns [Result], which may hold a list
|
||||||
@@ -519,7 +517,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
classA: KmClass,
|
classA: KmClass,
|
||||||
classB: KmClass
|
classB: KmClass
|
||||||
) {
|
) {
|
||||||
compareFlags(classContext, classA.flags, classB.flags, CLASS_FLAGS)
|
compareFlags(classContext, classA, classB, CLASS_FLAGS)
|
||||||
compareAnnotationLists(classContext, classA.annotations, classB.annotations)
|
compareAnnotationLists(classContext, classA.annotations, classB.annotations)
|
||||||
|
|
||||||
compareTypeParameterLists(classContext, classA.typeParameters, classB.typeParameters)
|
compareTypeParameterLists(classContext, classA.typeParameters, classB.typeParameters)
|
||||||
@@ -553,7 +551,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
typeAliasA: KmTypeAlias,
|
typeAliasA: KmTypeAlias,
|
||||||
typeAliasB: KmTypeAlias
|
typeAliasB: KmTypeAlias
|
||||||
) {
|
) {
|
||||||
compareFlags(typeAliasContext, typeAliasA.flags, typeAliasB.flags, TYPE_ALIAS_FLAGS)
|
compareFlags(typeAliasContext, typeAliasA, typeAliasB, TYPE_ALIAS_FLAGS)
|
||||||
compareAnnotationLists(typeAliasContext, typeAliasA.annotations, typeAliasB.annotations)
|
compareAnnotationLists(typeAliasContext, typeAliasA.annotations, typeAliasB.annotations)
|
||||||
|
|
||||||
compareTypeParameterLists(typeAliasContext, typeAliasA.typeParameters, typeAliasB.typeParameters)
|
compareTypeParameterLists(typeAliasContext, typeAliasA.typeParameters, typeAliasB.typeParameters)
|
||||||
@@ -580,9 +578,11 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
propertyA: KmProperty,
|
propertyA: KmProperty,
|
||||||
propertyB: KmProperty
|
propertyB: KmProperty
|
||||||
) {
|
) {
|
||||||
compareFlags(propertyContext, propertyA.flags, propertyB.flags, PROPERTY_FLAGS)
|
compareFlags(propertyContext, propertyA, propertyB, PROPERTY_FLAGS)
|
||||||
compareFlags(propertyContext, propertyA.getterFlags, propertyB.getterFlags, PROPERTY_ACCESSOR_FLAGS, FlagKind.GETTER)
|
compareFlags(propertyContext, propertyA.getter, propertyB.getter, PROPERTY_ACCESSOR_FLAGS, FlagKind.GETTER)
|
||||||
compareFlags(propertyContext, propertyA.setterFlags, propertyB.setterFlags, PROPERTY_ACCESSOR_FLAGS, FlagKind.SETTER)
|
compareValues(propertyContext, propertyA.setter != null, propertyB.setter != null, FlagKind.REGULAR, "hasSetter")
|
||||||
|
if (propertyA.setter != null && propertyB.setter != null)
|
||||||
|
compareFlags(propertyContext, propertyA.setter!!, propertyB.setter!!, PROPERTY_ACCESSOR_FLAGS, FlagKind.SETTER)
|
||||||
|
|
||||||
compareAnnotationLists(propertyContext, propertyA.annotations, propertyB.annotations)
|
compareAnnotationLists(propertyContext, propertyA.annotations, propertyB.annotations)
|
||||||
compareAnnotationLists(propertyContext, propertyA.getterAnnotations, propertyB.getterAnnotations, AnnotationKind.GETTER)
|
compareAnnotationLists(propertyContext, propertyA.getterAnnotations, propertyB.getterAnnotations, AnnotationKind.GETTER)
|
||||||
@@ -623,7 +623,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
functionA: KmFunction,
|
functionA: KmFunction,
|
||||||
functionB: KmFunction
|
functionB: KmFunction
|
||||||
) {
|
) {
|
||||||
compareFlags(functionContext, functionA.flags, functionB.flags, FUNCTION_FLAGS)
|
compareFlags(functionContext, functionA, functionB, FUNCTION_FLAGS)
|
||||||
compareAnnotationLists(functionContext, functionA.annotations, functionB.annotations)
|
compareAnnotationLists(functionContext, functionA.annotations, functionB.annotations)
|
||||||
|
|
||||||
compareTypeParameterLists(functionContext, functionA.typeParameters, functionB.typeParameters)
|
compareTypeParameterLists(functionContext, functionA.typeParameters, functionB.typeParameters)
|
||||||
@@ -683,7 +683,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
constructorA: KmConstructor,
|
constructorA: KmConstructor,
|
||||||
constructorB: KmConstructor
|
constructorB: KmConstructor
|
||||||
) {
|
) {
|
||||||
compareFlags(constructorContext, constructorA.flags, constructorB.flags, CONSTRUCTOR_FLAGS)
|
compareFlags(constructorContext, constructorA, constructorB, CONSTRUCTOR_FLAGS)
|
||||||
compareAnnotationLists(constructorContext, constructorA.annotations, constructorB.annotations)
|
compareAnnotationLists(constructorContext, constructorA.annotations, constructorB.annotations)
|
||||||
|
|
||||||
compareValueParameterLists(constructorContext, constructorA.valueParameters, constructorB.valueParameters)
|
compareValueParameterLists(constructorContext, constructorA.valueParameters, constructorB.valueParameters)
|
||||||
@@ -694,7 +694,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
valueParameterA: KmValueParameter,
|
valueParameterA: KmValueParameter,
|
||||||
valueParameterB: KmValueParameter
|
valueParameterB: KmValueParameter
|
||||||
) {
|
) {
|
||||||
compareFlags(valueParameterContext, valueParameterA.flags, valueParameterB.flags, VALUE_PARAMETER_FLAGS)
|
compareFlags(valueParameterContext, valueParameterA, valueParameterB, VALUE_PARAMETER_FLAGS)
|
||||||
compareAnnotationLists(valueParameterContext, valueParameterA.annotations, valueParameterB.annotations)
|
compareAnnotationLists(valueParameterContext, valueParameterA.annotations, valueParameterB.annotations)
|
||||||
|
|
||||||
compareNullableEntities(
|
compareNullableEntities(
|
||||||
@@ -718,7 +718,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
typeA: KmType,
|
typeA: KmType,
|
||||||
typeB: KmType
|
typeB: KmType
|
||||||
) {
|
) {
|
||||||
compareFlags(typeContext, typeA.flags, typeB.flags, TYPE_FLAGS)
|
compareFlags(typeContext, typeA, typeB, TYPE_FLAGS)
|
||||||
compareAnnotationLists(typeContext, typeA.annotations, typeB.annotations)
|
compareAnnotationLists(typeContext, typeA.annotations, typeB.annotations)
|
||||||
|
|
||||||
compareValues(typeContext, typeA.classifier, typeB.classifier, EntityKind.Classifier)
|
compareValues(typeContext, typeA.classifier, typeB.classifier, EntityKind.Classifier)
|
||||||
@@ -787,7 +787,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
typeParameterA: KmTypeParameter,
|
typeParameterA: KmTypeParameter,
|
||||||
typeParameterB: KmTypeParameter
|
typeParameterB: KmTypeParameter
|
||||||
) {
|
) {
|
||||||
compareFlags(typeParameterContext, typeParameterA.flags, typeParameterB.flags, TYPE_PARAMETER_FLAGS)
|
compareFlags(typeParameterContext, typeParameterA, typeParameterB, TYPE_PARAMETER_FLAGS)
|
||||||
compareAnnotationLists(typeParameterContext, typeParameterA.annotations, typeParameterB.annotations)
|
compareAnnotationLists(typeParameterContext, typeParameterA.annotations, typeParameterB.annotations)
|
||||||
|
|
||||||
compareValues(typeParameterContext, typeParameterA.id, typeParameterB.id, EntityKind.TypeParameterId)
|
compareValues(typeParameterContext, typeParameterA.id, typeParameterB.id, EntityKind.TypeParameterId)
|
||||||
@@ -803,7 +803,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
effectExpressionA: KmEffectExpression,
|
effectExpressionA: KmEffectExpression,
|
||||||
effectExpressionB: KmEffectExpression
|
effectExpressionB: KmEffectExpression
|
||||||
) {
|
) {
|
||||||
compareFlags(effectExpressionContext, effectExpressionA.flags, effectExpressionB.flags, EFFECT_EXPRESSION_FLAGS)
|
compareFlags(effectExpressionContext, effectExpressionA, effectExpressionB, EFFECT_EXPRESSION_FLAGS)
|
||||||
compareNullableValues(
|
compareNullableValues(
|
||||||
containerContext = effectExpressionContext,
|
containerContext = effectExpressionContext,
|
||||||
valueA = effectExpressionA.parameterIndex,
|
valueA = effectExpressionA.parameterIndex,
|
||||||
@@ -972,16 +972,16 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compareFlags(
|
private fun <T> compareFlags(
|
||||||
containerContext: Context,
|
containerContext: Context,
|
||||||
flagsA: Int,
|
flagsA: T,
|
||||||
flagsB: Int,
|
flagsB: T,
|
||||||
flagsToCompare: Array<KProperty0<Flag>>,
|
flagsToCompare: Array<out KProperty1<T, Any>>,
|
||||||
flagKind: FlagKind = FlagKind.REGULAR
|
flagKind: FlagKind = FlagKind.REGULAR
|
||||||
) {
|
) {
|
||||||
for (flag in flagsToCompare) {
|
for (flag in flagsToCompare) {
|
||||||
val valueA = flag.get()(flagsA)
|
val valueA = flag.get(flagsA)
|
||||||
val valueB = flag.get()(flagsB)
|
val valueB = flag.get(flagsB)
|
||||||
|
|
||||||
compareValues(containerContext, valueA, valueB, flagKind, flag.name)
|
compareValues(containerContext, valueA, valueB, flagKind, flag.name)
|
||||||
}
|
}
|
||||||
@@ -994,119 +994,90 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
|
|||||||
config: Config = Config.Default
|
config: Config = Config.Default
|
||||||
): Result = MetadataDeclarationsComparator(config).compareModules(metadataA, metadataB)
|
): Result = MetadataDeclarationsComparator(config).compareModules(metadataA, metadataB)
|
||||||
|
|
||||||
private val VISIBILITY_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val CLASS_FLAGS: Array<KProperty1<KmClass, Any>> = arrayOf(
|
||||||
Flag.Common::IS_INTERNAL,
|
KmClass::hasAnnotations,
|
||||||
Flag.Common::IS_PRIVATE,
|
KmClass::visibility,
|
||||||
Flag.Common::IS_PROTECTED,
|
KmClass::modality,
|
||||||
Flag.Common::IS_PUBLIC,
|
KmClass::kind,
|
||||||
Flag.Common::IS_PRIVATE_TO_THIS,
|
KmClass::isInner,
|
||||||
Flag.Common::IS_LOCAL
|
KmClass::isData,
|
||||||
|
KmClass::isExternal,
|
||||||
|
KmClass::isExpect,
|
||||||
|
KmClass::isValue,
|
||||||
|
KmClass::isFunInterface,
|
||||||
|
KmClass::hasEnumEntries
|
||||||
)
|
)
|
||||||
|
|
||||||
private val MODALITY_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val TYPE_ALIAS_FLAGS: Array<KProperty1<KmTypeAlias, Any>> = arrayOf(
|
||||||
Flag.Common::IS_FINAL,
|
KmTypeAlias::hasAnnotations,
|
||||||
Flag.Common::IS_OPEN,
|
KmTypeAlias::visibility
|
||||||
Flag.Common::IS_ABSTRACT,
|
|
||||||
Flag.Common::IS_SEALED
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val CLASS_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val CONSTRUCTOR_FLAGS: Array<KProperty1<KmConstructor, Any>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmConstructor::hasAnnotations,
|
||||||
*VISIBILITY_FLAGS,
|
KmConstructor::visibility,
|
||||||
*MODALITY_FLAGS,
|
KmConstructor::isSecondary,
|
||||||
Flag.Class::IS_CLASS,
|
KmConstructor::hasNonStableParameterNames
|
||||||
Flag.Class::IS_INTERFACE,
|
|
||||||
Flag.Class::IS_ENUM_CLASS,
|
|
||||||
Flag.Class::IS_ENUM_ENTRY,
|
|
||||||
Flag.Class::IS_ANNOTATION_CLASS,
|
|
||||||
Flag.Class::IS_OBJECT,
|
|
||||||
Flag.Class::IS_COMPANION_OBJECT,
|
|
||||||
Flag.Class::IS_INNER,
|
|
||||||
Flag.Class::IS_DATA,
|
|
||||||
Flag.Class::IS_EXTERNAL,
|
|
||||||
Flag.Class::IS_EXPECT,
|
|
||||||
Flag.Class::IS_VALUE,
|
|
||||||
Flag.Class::IS_FUN,
|
|
||||||
Flag.Class::HAS_ENUM_ENTRIES,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val TYPE_ALIAS_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val FUNCTION_FLAGS: Array<KProperty1<KmFunction, Any>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmFunction::hasAnnotations,
|
||||||
*VISIBILITY_FLAGS
|
KmFunction::visibility,
|
||||||
|
KmFunction::modality,
|
||||||
|
KmFunction::kind,
|
||||||
|
KmFunction::isOperator,
|
||||||
|
KmFunction::isInfix,
|
||||||
|
KmFunction::isInline,
|
||||||
|
KmFunction::isTailrec,
|
||||||
|
KmFunction::isExternal,
|
||||||
|
KmFunction::isSuspend,
|
||||||
|
KmFunction::isExpect,
|
||||||
|
KmFunction::hasNonStableParameterNames
|
||||||
)
|
)
|
||||||
|
|
||||||
private val CONSTRUCTOR_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val PROPERTY_FLAGS: Array<KProperty1<KmProperty, Any>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmProperty::hasAnnotations,
|
||||||
*VISIBILITY_FLAGS,
|
KmProperty::visibility,
|
||||||
Flag.Constructor::IS_SECONDARY,
|
KmProperty::modality,
|
||||||
Flag.Constructor::HAS_NON_STABLE_PARAMETER_NAMES
|
KmProperty::kind,
|
||||||
|
KmProperty::isVar,
|
||||||
|
KmProperty::isConst,
|
||||||
|
KmProperty::isLateinit,
|
||||||
|
KmProperty::hasConstant,
|
||||||
|
KmProperty::isExternal,
|
||||||
|
KmProperty::isDelegated,
|
||||||
|
KmProperty::isExpect
|
||||||
)
|
)
|
||||||
|
|
||||||
private val FUNCTION_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val PROPERTY_ACCESSOR_FLAGS: Array<KProperty1<KmPropertyAccessorAttributes, Any>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmPropertyAccessorAttributes::hasAnnotations,
|
||||||
*VISIBILITY_FLAGS,
|
KmPropertyAccessorAttributes::visibility,
|
||||||
*MODALITY_FLAGS,
|
KmPropertyAccessorAttributes::modality,
|
||||||
Flag.Function::IS_DECLARATION,
|
KmPropertyAccessorAttributes::isNotDefault,
|
||||||
Flag.Function::IS_FAKE_OVERRIDE,
|
KmPropertyAccessorAttributes::isExternal,
|
||||||
Flag.Function::IS_DELEGATION,
|
KmPropertyAccessorAttributes::isInline
|
||||||
Flag.Function::IS_SYNTHESIZED,
|
|
||||||
Flag.Function::IS_OPERATOR,
|
|
||||||
Flag.Function::IS_INFIX,
|
|
||||||
Flag.Function::IS_INLINE,
|
|
||||||
Flag.Function::IS_TAILREC,
|
|
||||||
Flag.Function::IS_EXTERNAL,
|
|
||||||
Flag.Function::IS_SUSPEND,
|
|
||||||
Flag.Function::IS_EXPECT,
|
|
||||||
Flag.Function::HAS_NON_STABLE_PARAMETER_NAMES
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val PROPERTY_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val TYPE_FLAGS: Array<KProperty1<KmType, Boolean>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmType::isNullable,
|
||||||
*VISIBILITY_FLAGS,
|
KmType::isSuspend,
|
||||||
*MODALITY_FLAGS,
|
|
||||||
Flag.Property::IS_DECLARATION,
|
|
||||||
Flag.Property::IS_FAKE_OVERRIDE,
|
|
||||||
Flag.Property::IS_DELEGATION,
|
|
||||||
Flag.Property::IS_SYNTHESIZED,
|
|
||||||
Flag.Property::IS_VAR,
|
|
||||||
Flag.Property::HAS_GETTER,
|
|
||||||
Flag.Property::HAS_SETTER,
|
|
||||||
Flag.Property::IS_CONST,
|
|
||||||
Flag.Property::IS_LATEINIT,
|
|
||||||
Flag.Property::HAS_CONSTANT,
|
|
||||||
Flag.Property::IS_EXTERNAL,
|
|
||||||
Flag.Property::IS_DELEGATED,
|
|
||||||
Flag.Property::IS_EXPECT
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val PROPERTY_ACCESSOR_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val TYPE_PARAMETER_FLAGS: Array<KProperty1<KmTypeParameter, Boolean>> = arrayOf(
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
KmTypeParameter::isReified
|
||||||
*VISIBILITY_FLAGS,
|
|
||||||
*MODALITY_FLAGS,
|
|
||||||
Flag.PropertyAccessor::IS_NOT_DEFAULT,
|
|
||||||
Flag.PropertyAccessor::IS_EXTERNAL,
|
|
||||||
Flag.PropertyAccessor::IS_INLINE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val TYPE_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
private val VALUE_PARAMETER_FLAGS: Array<KProperty1<KmValueParameter, Boolean>> = arrayOf(
|
||||||
Flag.Type::IS_NULLABLE,
|
KmValueParameter::hasAnnotations,
|
||||||
Flag.Type::IS_SUSPEND
|
KmValueParameter::declaresDefaultValue,
|
||||||
|
KmValueParameter::isCrossinline,
|
||||||
|
KmValueParameter::isNoinline
|
||||||
)
|
)
|
||||||
|
|
||||||
private val TYPE_PARAMETER_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
@ExperimentalContracts
|
||||||
Flag.TypeParameter::IS_REIFIED
|
private val EFFECT_EXPRESSION_FLAGS: Array<KProperty1<KmEffectExpression, Boolean>> = arrayOf(
|
||||||
)
|
KmEffectExpression::isNegated,
|
||||||
|
KmEffectExpression::isNullCheckPredicate
|
||||||
private val VALUE_PARAMETER_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
|
||||||
Flag.Common::HAS_ANNOTATIONS,
|
|
||||||
Flag.ValueParameter::DECLARES_DEFAULT_VALUE,
|
|
||||||
Flag.ValueParameter::IS_CROSSINLINE,
|
|
||||||
Flag.ValueParameter::IS_NOINLINE
|
|
||||||
)
|
|
||||||
|
|
||||||
private val EFFECT_EXPRESSION_FLAGS: Array<KProperty0<Flag>> = arrayOf(
|
|
||||||
Flag.EffectExpression::IS_NEGATED,
|
|
||||||
Flag.EffectExpression::IS_NULL_CHECK_PREDICATE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user