private fun convertPrimaryConstructor ( classNode : LighterASTNode , primaryConstructor : LighterASTNode ? , selfTypeSource : KtSourceElement ? , classWrapper : ClassWrapper , delegatedConstructorSource : KtLightSourceElement ? , isEnumEntry : Boolean = false , containingClassIsExpectClass : Boolean , isImplicitlyActual : Boolean = false , isKotlinAny : Boolean = false , ) : PrimaryConstructor ?

{ <EOL> val shouldGenerateImplicitConstructor = <EOL> ( classWrapper . isEnumEntry ( ) || ! classWrapper . hasSecondaryConstructor ) && <EOL> ! classWrapper . isInterface ( ) && <EOL> ( ! containingClassIsExpectClass || classWrapper . classBuilder . classKind == ClassKind . ENUM_ENTRY ) <EOL> val isErrorConstructor = primaryConstructor == null && ! shouldGenerateImplicitConstructor <EOL> if ( isErrorConstructor && classWrapper . delegatedSuperCalls . isEmpty ( ) ) { <EOL> return null <EOL> } <EOL> val constructorSymbol = FirConstructorSymbol ( callableIdForClassConstructor ( ) ) <EOL> withContainerSymbol ( constructorSymbol ) { <EOL> var modifiersIfPresent : Modifier ? = null <EOL> val constructorAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> val valueParameters = mutableListOf < ValueParameter > ( ) <EOL> var hasConstructorKeyword = false <EOL> primaryConstructor ? . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> { <EOL> modifiersIfPresent = convertModifierList ( it ) <EOL> constructorAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> CONSTRUCTOR_KEYWORD -> hasConstructorKeyword = true <EOL> VALUE_PARAMETER_LIST -> valueParameters += convertValueParameters ( it , constructorSymbol , ValueParameterDeclaration . PRIMARY_CONSTRUCTOR ) <EOL> } <EOL> } <EOL> val modifiers = modifiersIfPresent ? : Modifier ( ) <EOL> val defaultVisibility = classWrapper . defaultConstructorVisibility ( ) <EOL> val firDelegatedCall = runUnless ( containingClassIsExpectClass || isKotlinAny ) { <EOL> fun createDelegatedConstructorCall ( delegatedConstructorSource : KtLightSourceElement ? , delegatedSuperTypeRef : FirTypeRef , arguments : List < FirExpression > , ) : FirDelegatedConstructorCall { <EOL> return buildDelegatedConstructorCall { <EOL> source = delegatedConstructorSource <EOL> ? : primaryConstructor ? . toFirSourceElement ( KtFakeSourceElementKind . DelegatingConstructorCall ) <EOL> ? : selfTypeSource ? . fakeElement ( KtFakeSourceElementKind . DelegatingConstructorCall ) <EOL> constructedTypeRef = delegatedSuperTypeRef . copyWithNewSourceKind ( KtFakeSourceElementKind . ImplicitTypeRef ) <EOL> isThis = false <EOL> calleeReference = buildExplicitSuperReference { <EOL> source = if ( ! isEnumEntry ) { <EOL> classWrapper . delegatedSuperTypeRef . source ? . fakeElement ( KtFakeSourceElementKind . DelegatingConstructorCall ) <EOL> ? : this@buildDelegatedConstructorCall . source ? . fakeElement ( KtFakeSourceElementKind . DelegatingConstructorCall ) <EOL> } else { <EOL> delegatedConstructorSource <EOL> ? . lighterASTNode <EOL> ? . getChildNodeByType ( CONSTRUCTOR_CALLEE ) <EOL> ? . toFirSourceElement ( KtFakeSourceElementKind . DelegatingConstructorCall ) <EOL> ? : this@buildDelegatedConstructorCall . source <EOL> } <EOL> superTypeRef = this@buildDelegatedConstructorCall . constructedTypeRef <EOL> } <EOL> extractArgumentsFrom ( arguments ) <EOL> } <EOL> } <EOL> if ( classWrapper . delegatedSuperCalls . size <= <NUM_LIT:1> ) { <EOL> createDelegatedConstructorCall ( delegatedConstructorSource , classWrapper . delegatedSuperTypeRef , classWrapper . delegatedSuperCalls . lastOrNull ( ) ? . arguments ? : emptyList ( ) , ) <EOL> } else { <EOL> buildMultiDelegatedConstructorCall { <EOL> classWrapper . delegatedSuperCalls . mapTo ( delegatedConstructorCalls ) { ( delegatedSuperTypeRef , arguments , source ) -> <EOL> createDelegatedConstructorCall ( source , delegatedSuperTypeRef , arguments ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> val explicitVisibility = runIf ( primaryConstructor != null ) { <EOL> modifiers . getVisibility ( ) . takeUnless { it == Visibilities . Unknown } <EOL> } <EOL> val status = FirDeclarationStatusImpl ( explicitVisibility ? : defaultVisibility , Modality . FINAL ) . apply { <EOL> isExpect = modifiers . hasExpect ( ) || context . containerIsExpect <EOL> isActual = modifiers . hasActual ( ) || isImplicitlyActual <EOL> isInner = classWrapper . isInner ( ) <EOL> isFromSealedClass = classWrapper . isSealed ( ) && explicitVisibility !== Visibilities . Private <EOL> isFromEnumClass = classWrapper . isEnum ( ) <EOL> } <EOL> val builder = when { <EOL> modifiersIfPresent != null && ! hasConstructorKeyword -> createErrorConstructorBuilder ( ConeMissingConstructorKeyword ) <EOL> isErrorConstructor -> createErrorConstructorBuilder ( ConeNoConstructorError ) <EOL> else -> FirPrimaryConstructorBuilder ( ) <EOL> } <EOL> builder . apply { <EOL> source = primaryConstructor ? . toFirSourceElement ( ) <EOL> ? : selfTypeSource ? . fakeElement ( KtFakeSourceElementKind . ImplicitConstructor ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = classWrapper . delegatedSelfTypeRef <EOL> dispatchReceiverType = classWrapper . obtainDispatchReceiverForConstructor ( ) <EOL> this . status = status <EOL> symbol = constructorSymbol <EOL> annotations += constructorAnnotations <EOL> typeParameters += constructorTypeParametersFromConstructedClass ( classWrapper . classBuilder . typeParameters ) <EOL> this . valueParameters += valueParameters . map { it . firValueParameter } <EOL> delegatedConstructor = firDelegatedCall <EOL> this . body = null <EOL> this . contextReceivers . addAll ( convertContextReceivers ( classNode ) ) <EOL> } <EOL> return PrimaryConstructor ( builder . build ( ) . apply { <EOL> containingClassForStaticMemberAttr = currentDispatchReceiverType ( ) ! ! . lookupTag <EOL> } , valueParameters , ) <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseClassOrObject
 * primaryConstructor branch
 */


private fun convertAnonymousInitializer ( anonymousInitializer : LighterASTNode , classWrapper : ClassWrapper ) : FirDeclaration

{ <EOL> val initializerSymbol = FirAnonymousInitializerSymbol ( ) <EOL> withContainerSymbol ( initializerSymbol ) { <EOL> var firBlock : FirBlock ? = null <EOL> val initializerAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> anonymousInitializer . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> initializerAnnotations += convertAnnotationList ( it ) <EOL> BLOCK -> withForcedLocalContext { <EOL> firBlock = convertBlock ( it ) <EOL> } <EOL> } <EOL> } <EOL> return buildAnonymousInitializer { <EOL> symbol = initializerSymbol <EOL> source = anonymousInitializer . toFirSourceElement ( ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> body = firBlock ? : buildEmptyExpressionBlock ( ) <EOL> containingDeclarationSymbol = classWrapper . classBuilder . ownerRegularOrAnonymousObjectSymbol <EOL> annotations += initializerAnnotations <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseMemberDeclarationRest
 * at INIT keyword
 */


private fun convertSecondaryConstructor ( secondaryConstructor : LighterASTNode , classWrapper : ClassWrapper ) : FirConstructor

{ <EOL> var modifiers : Modifier ? = null <EOL> val constructorAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> val firValueParameters = mutableListOf < ValueParameter > ( ) <EOL> var constructorDelegationCall : FirDelegatedConstructorCall ? = null <EOL> var block : LighterASTNode ? = null <EOL> val constructorSymbol = FirConstructorSymbol ( callableIdForClassConstructor ( ) ) <EOL> withContainerSymbol ( constructorSymbol ) { <EOL> secondaryConstructor . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> { <EOL> modifiers = convertModifierList ( it ) <EOL> constructorAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> VALUE_PARAMETER_LIST -> firValueParameters += convertValueParameters ( it , constructorSymbol , ValueParameterDeclaration . FUNCTION ) <EOL> CONSTRUCTOR_DELEGATION_CALL -> constructorDelegationCall = convertConstructorDelegationCall ( it , classWrapper ) <EOL> BLOCK -> block = it <EOL> } <EOL> } <EOL> val delegatedSelfTypeRef = classWrapper . delegatedSelfTypeRef <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> val explicitVisibility = calculatedModifiers . getVisibility ( ) <EOL> val status = FirDeclarationStatusImpl ( explicitVisibility , Modality . FINAL ) . apply { <EOL> isExpect = calculatedModifiers . hasExpect ( ) || context . containerIsExpect <EOL> isActual = calculatedModifiers . hasActual ( ) <EOL> isInner = classWrapper . isInner ( ) <EOL> isFromSealedClass = classWrapper . isSealed ( ) && explicitVisibility !== Visibilities . Private <EOL> isFromEnumClass = classWrapper . isEnum ( ) <EOL> } <EOL> val target = FirFunctionTarget ( labelName = null , isLambda = false ) <EOL> return buildConstructor { <EOL> source = secondaryConstructor . toFirSourceElement ( ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = delegatedSelfTypeRef <EOL> dispatchReceiverType = classWrapper . obtainDispatchReceiverForConstructor ( ) <EOL> this . status = status <EOL> symbol = constructorSymbol <EOL> delegatedConstructor = constructorDelegationCall <EOL> context . firFunctionTargets += target <EOL> annotations += constructorAnnotations <EOL> typeParameters += constructorTypeParametersFromConstructedClass ( classWrapper . classBuilder . typeParameters ) <EOL> valueParameters += firValueParameters . map { it . firValueParameter } <EOL> val ( body , contractDescription ) = withForcedLocalContext { <EOL> convertFunctionBody ( block , null , allowLegacyContractDescription = true ) <EOL> } <EOL> this . body = body <EOL> contractDescription ? . let { this . contractDescription = it } <EOL> context . firFunctionTargets . removeLast ( ) <EOL> this . contextReceivers . addAll ( convertContextReceivers ( secondaryConstructor . getParent ( ) ! ! . getParent ( ) ! ! ) ) <EOL> } . also { <EOL> it . containingClassForStaticMemberAttr = currentDispatchReceiverType ( ) ! ! . lookupTag <EOL> target . bind ( it ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseSecondaryConstructor
 */


private fun convertConstructorDelegationCall ( constructorDelegationCall : LighterASTNode , classWrapper : ClassWrapper ) : FirDelegatedConstructorCall ?

{ <EOL> var thisKeywordPresent = false <EOL> val firValueArguments = mutableListOf < FirExpression > ( ) <EOL> constructorDelegationCall . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> CONSTRUCTOR_DELEGATION_REFERENCE -> if ( it . asText == "<STR_LIT:this>" ) thisKeywordPresent = true <EOL> VALUE_ARGUMENT_LIST -> firValueArguments += expressionConverter . convertValueArguments ( it ) <EOL> } <EOL> } <EOL> val isImplicit = constructorDelegationCall . textLength == <NUM_LIT:0> <EOL> if ( isImplicit && classWrapper . modifiers . hasExternal ( ) ) { <EOL> return null <EOL> } <EOL> val isThis = thisKeywordPresent <EOL> val delegatedType = <EOL> when { <EOL> isThis -> classWrapper . delegatedSelfTypeRef <EOL> else -> classWrapper . delegatedSuperTypeRef <EOL> } <EOL> return buildDelegatedConstructorCall { <EOL> source = if ( isImplicit ) { <EOL> constructorDelegationCall . toFirSourceElement ( ) . fakeElement ( KtFakeSourceElementKind . ImplicitConstructor ) <EOL> } else { <EOL> constructorDelegationCall . toFirSourceElement ( ) <EOL> } <EOL> constructedTypeRef = delegatedType . copyWithNewSourceKind ( KtFakeSourceElementKind . ImplicitTypeRef ) <EOL> this . isThis = isThis <EOL> val calleeKind = <EOL> if ( isImplicit ) KtFakeSourceElementKind . ImplicitConstructor else KtFakeSourceElementKind . DelegatingConstructorCall <EOL> val calleeSource = constructorDelegationCall . getChildNodeByType ( CONSTRUCTOR_DELEGATION_REFERENCE ) <EOL> ? . toFirSourceElement ( calleeKind ) <EOL> ? : this@buildDelegatedConstructorCall . source ? . fakeElement ( calleeKind ) <EOL> calleeReference = if ( isThis ) { <EOL> buildExplicitThisReference { <EOL> this . source = calleeSource <EOL> } <EOL> } else { <EOL> buildExplicitSuperReference { <EOL> source = calleeSource <EOL> superTypeRef = this@buildDelegatedConstructorCall . constructedTypeRef <EOL> } <EOL> } <EOL> extractArgumentsFrom ( firValueArguments ) <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.convert(
 * KtConstructorDelegationCall, FirTypeRef, Boolean)
 */


private fun convertTypeAlias ( typeAlias : LighterASTNode ) : FirDeclaration

{ <EOL> var modifiers : Modifier ? = null <EOL> var identifier : String ? = null <EOL> lateinit var firType : FirTypeRef <EOL> val aliasAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> typeAlias . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> modifiers = convertModifierList ( it ) <EOL> IDENTIFIER -> identifier = it . asText <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> val typeAliasName = identifier . nameAsSafeName ( ) <EOL> val typeAliasIsExpect = calculatedModifiers . hasExpect ( ) || context . containerIsExpect <EOL> return withChildClassName ( typeAliasName , isExpect = typeAliasIsExpect ) { <EOL> val typeAliasSymbol = FirTypeAliasSymbol ( context . currentClassId ) <EOL> withContainerSymbol ( typeAliasSymbol ) { <EOL> typeAlias . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> { <EOL> aliasAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> } <EOL> } <EOL> val firTypeParameters = mutableListOf < FirTypeParameter > ( ) <EOL> typeAlias . forEachChildren { <EOL> if ( it . tokenType == TYPE_PARAMETER_LIST ) { <EOL> firTypeParameters += convertTypeParameters ( it , emptyList ( ) , typeAliasSymbol ) <EOL> } <EOL> } <EOL> buildTypeAlias { <EOL> source = typeAlias . toFirSourceElement ( ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> name = typeAliasName <EOL> val isLocal = context . inLocalContext <EOL> status = FirDeclarationStatusImpl ( if ( isLocal ) Visibilities . Local else calculatedModifiers . getVisibility ( publicByDefault = true ) , Modality . FINAL , ) . apply { <EOL> isExpect = typeAliasIsExpect <EOL> isActual = calculatedModifiers . hasActual ( ) <EOL> } <EOL> symbol = typeAliasSymbol <EOL> expandedTypeRef = firType <EOL> annotations += aliasAnnotations <EOL> typeParameters += firTypeParameters <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeAlias
 */


fun convertPropertyDeclaration ( property : LighterASTNode , classWrapper : ClassWrapper ? = null ) : FirDeclaration

{ <EOL> var modifiers : Modifier ? = null <EOL> val propertyAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var identifier : String ? = null <EOL> val firTypeParameters = mutableListOf < FirTypeParameter > ( ) <EOL> var isReturnType = false <EOL> var delegate : LighterASTNode ? = null <EOL> var isVar = false <EOL> var receiverType : FirTypeRef ? = null <EOL> var returnType : FirTypeRef = implicitType <EOL> val typeConstraints = mutableListOf < TypeConstraint > ( ) <EOL> val accessors = mutableListOf < LighterASTNode > ( ) <EOL> var propertyInitializer : FirExpression ? = null <EOL> var typeParameterList : LighterASTNode ? = null <EOL> var fieldDeclaration : LighterASTNode ? = null <EOL> property . getChildNodeByType ( IDENTIFIER ) ? . let { <EOL> identifier = it . asText <EOL> } <EOL> val propertyName = identifier . nameAsSafeName ( ) <EOL> val parentNode = property . getParent ( ) <EOL> val isLocal = ! ( parentNode ? . tokenType == KT_FILE || parentNode ? . tokenType == CLASS_BODY ) <EOL> val propertySymbol = if ( isLocal ) { <EOL> FirPropertySymbol ( propertyName ) <EOL> } else { <EOL> FirPropertySymbol ( callableIdForName ( propertyName ) ) <EOL> } <EOL> withContainerSymbol ( propertySymbol , isLocal ) { <EOL> val propertySource = property . toFirSourceElement ( ) <EOL> property . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> { <EOL> modifiers = convertModifierList ( it ) <EOL> propertyAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> TYPE_PARAMETER_LIST -> typeParameterList = it <EOL> COLON -> isReturnType = true <EOL> TYPE_REFERENCE -> if ( isReturnType ) returnType = convertType ( it ) else receiverType = convertType ( it ) <EOL> TYPE_CONSTRAINT_LIST -> typeConstraints += convertTypeConstraints ( it ) <EOL> PROPERTY_DELEGATE -> delegate = it <EOL> VAR_KEYWORD -> isVar = true <EOL> PROPERTY_ACCESSOR -> { <EOL> accessors += it <EOL> } <EOL> BACKING_FIELD -> fieldDeclaration = it <EOL> else -> if ( it . isExpression ( ) ) { <EOL> context . calleeNamesForLambda += null <EOL> propertyInitializer = withForcedLocalContext { <EOL> expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> context . calleeNamesForLambda . removeLast ( ) <EOL> } <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> return buildProperty { <EOL> source = propertySource <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = returnType <EOL> name = propertyName <EOL> this . isVar = isVar <EOL> receiverParameter = receiverType ? . convertToReceiverParameter ( ) <EOL> initializer = propertyInitializer <EOL> val delegateSource = delegate ? . let { <EOL> ( it . getChildExpression ( ) ? : it ) . toFirSourceElement ( ) <EOL> } <EOL> symbol = propertySymbol <EOL> typeParameterList ? . let { firTypeParameters += convertTypeParameters ( it , typeConstraints , symbol ) } <EOL> backingField = fieldDeclaration . convertBackingField ( symbol , calculatedModifiers , returnType , isVar , if ( isLocal ) emptyList ( ) else propertyAnnotations . filter { <EOL> it . useSiteTarget == FIELD || it . useSiteTarget == PROPERTY_DELEGATE_FIELD <EOL> } , property , ) <EOL> if ( isLocal ) { <EOL> this . isLocal = true <EOL> val delegateBuilder = delegate ? . let { <EOL> FirWrappedDelegateExpressionBuilder ( ) . apply { <EOL> source = delegateSource ? . fakeElement ( KtFakeSourceElementKind . WrappedDelegate ) <EOL> expression = expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> status = FirDeclarationStatusImpl ( Visibilities . Local , Modality . FINAL ) . apply { <EOL> isLateInit = calculatedModifiers . hasLateinit ( ) <EOL> } <EOL> typeParameters += firTypeParameters <EOL> generateAccessorsByDelegate ( delegateBuilder , baseModuleData , classWrapper ? . classBuilder ? . ownerRegularOrAnonymousObjectSymbol , context = context , isExtension = false ) <EOL> } else { <EOL> this . isLocal = false <EOL> dispatchReceiverType = currentDispatchReceiverType ( ) <EOL> withCapturedTypeParameters ( true , propertySource , firTypeParameters ) { <EOL> typeParameters += firTypeParameters <EOL> val delegateBuilder = delegate ? . let { <EOL> FirWrappedDelegateExpressionBuilder ( ) . apply { <EOL> source = delegateSource ? . fakeElement ( KtFakeSourceElementKind . WrappedDelegate ) <EOL> expression = expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> val propertyVisibility = calculatedModifiers . getVisibility ( ) <EOL> fun defaultAccessorStatus ( ) = <EOL> FirDeclarationStatusImpl ( propertyVisibility , null ) . apply { <EOL> isInline = calculatedModifiers . hasInline ( ) <EOL> isExternal = calculatedModifiers . hasExternal ( ) <EOL> } <EOL> val convertedAccessors = accessors . map { <EOL> convertGetterOrSetter ( it , returnType , propertyVisibility , symbol , calculatedModifiers , propertyAnnotations ) <EOL> } <EOL> this . getter = convertedAccessors . find { it . isGetter } <EOL> ? : FirDefaultPropertyGetter ( property . toFirSourceElement ( KtFakeSourceElementKind . DefaultAccessor ) , moduleData , FirDeclarationOrigin . Source , returnType . copyWithNewSourceKind ( KtFakeSourceElementKind . DefaultAccessor ) , propertyVisibility , symbol , ) . also { <EOL> it . status = defaultAccessorStatus ( ) <EOL> it . replaceAnnotations ( propertyAnnotations . filterUseSiteTarget ( PROPERTY_GETTER ) ) <EOL> it . initContainingClassAttr ( ) <EOL> } <EOL> this . setter = convertedAccessors . find { it . isSetter } <EOL> ? : if ( isVar ) { <EOL> FirDefaultPropertySetter ( property . toFirSourceElement ( KtFakeSourceElementKind . DefaultAccessor ) , moduleData , FirDeclarationOrigin . Source , returnType . copyWithNewSourceKind ( KtFakeSourceElementKind . DefaultAccessor ) , propertyVisibility , symbol , parameterAnnotations = propertyAnnotations . filterUseSiteTarget ( SETTER_PARAMETER ) ) . also { <EOL> it . status = defaultAccessorStatus ( ) <EOL> it . replaceAnnotations ( propertyAnnotations . filterUseSiteTarget ( PROPERTY_SETTER ) ) <EOL> it . initContainingClassAttr ( ) <EOL> } <EOL> } else null <EOL> status = FirDeclarationStatusImpl ( propertyVisibility , calculatedModifiers . getModality ( isClassOrObject = false ) ) . apply { <EOL> isExpect = calculatedModifiers . hasExpect ( ) || context . containerIsExpect <EOL> isActual = calculatedModifiers . hasActual ( ) <EOL> isOverride = calculatedModifiers . hasOverride ( ) <EOL> isConst = calculatedModifiers . isConst ( ) <EOL> isLateInit = calculatedModifiers . hasLateinit ( ) <EOL> isExternal = calculatedModifiers . hasExternal ( ) <EOL> } <EOL> generateAccessorsByDelegate ( delegateBuilder , baseModuleData , classWrapper ? . classBuilder ? . ownerRegularOrAnonymousObjectSymbol , context , isExtension = receiverType != null , ) <EOL> } <EOL> } <EOL> annotations += when { <EOL> isLocal -> propertyAnnotations <EOL> else -> propertyAnnotations . filterStandalonePropertyRelevantAnnotations ( isVar ) <EOL> } <EOL> contextReceivers . addAll ( convertContextReceivers ( property ) ) <EOL> } . also { <EOL> if ( ! isLocal ) { <EOL> fillDanglingConstraintsTo ( firTypeParameters , typeConstraints , it ) <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseProperty
 */


internal fun convertDestructingDeclaration ( destructingDeclaration : LighterASTNode ) : DestructuringDeclaration

{ <EOL> val annotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var isVar = false <EOL> val entries = mutableListOf < DestructuringEntry > ( ) <EOL> val source = destructingDeclaration . toFirSourceElement ( ) <EOL> var firExpression : FirExpression ? = null <EOL> destructingDeclaration . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> annotations += convertAnnotationList ( it ) <EOL> VAR_KEYWORD -> isVar = true <EOL> DESTRUCTURING_DECLARATION_ENTRY -> entries += convertDestructingDeclarationEntry ( it ) <EOL> PROPERTY_DELEGATE -> { } <EOL> else -> if ( it . isExpression ( ) ) firExpression = <EOL> expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> return DestructuringDeclaration ( isVar , entries , firExpression ? : buildErrorExpression ( null , ConeSyntaxDiagnostic ( "<STR_LIT>" ) ) , source , annotations ) <EOL> }

/**
 * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitDestructuringDeclaration
 */


private fun convertDestructingDeclarationEntry ( entry : LighterASTNode ) : DestructuringEntry

{ <EOL> val annotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var identifier : String ? = null <EOL> var firType : FirTypeRef ? = null <EOL> entry . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> annotations += convertAnnotationList ( it ) <EOL> IDENTIFIER -> identifier = it . asText <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> } <EOL> } <EOL> val name = if ( identifier == "<STR_LIT:_>" ) { <EOL> SpecialNames . UNDERSCORE_FOR_UNUSED_VAR <EOL> } else { <EOL> identifier . nameAsSafeName ( ) <EOL> } <EOL> return DestructuringEntry ( source = entry . toFirSourceElement ( ) , returnTypeRef = firType ? : implicitType , name = name , annotations = annotations , ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseMultiDeclarationName
 */


private fun convertGetterOrSetter ( getterOrSetter : LighterASTNode , propertyTypeRef : FirTypeRef , propertyVisibility : Visibility , propertySymbol : FirPropertySymbol , propertyModifiers : Modifier , propertyAnnotations : List < FirAnnotationCall > , ) : FirPropertyAccessor

{ <EOL> var modifiers : Modifier ? = null <EOL> val accessorAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var isGetter = true <EOL> var returnType : FirTypeRef ? = null <EOL> val propertyTypeRefToUse = propertyTypeRef . copyWithNewSourceKind ( KtFakeSourceElementKind . ImplicitTypeRef ) <EOL> val accessorSymbol = FirPropertyAccessorSymbol ( ) <EOL> var firValueParameters : FirValueParameter = buildDefaultSetterValueParameter { <EOL> moduleData = baseModuleData <EOL> containingFunctionSymbol = accessorSymbol <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = propertyTypeRefToUse <EOL> symbol = FirValueParameterSymbol ( StandardNames . DEFAULT_VALUE_PARAMETER ) <EOL> } <EOL> var block : LighterASTNode ? = null <EOL> var expression : LighterASTNode ? = null <EOL> var outerContractDescription : FirContractDescription ? = null <EOL> getterOrSetter . forEachChildren { <EOL> if ( it . asText == "<STR_LIT:set>" ) isGetter = false <EOL> when ( it . tokenType ) { <EOL> SET_KEYWORD -> isGetter = false <EOL> MODIFIER_LIST -> { <EOL> modifiers = convertModifierList ( it ) <EOL> accessorAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> TYPE_REFERENCE -> returnType = convertType ( it ) <EOL> VALUE_PARAMETER_LIST -> firValueParameters = convertSetterParameter ( it , accessorSymbol , propertyTypeRefToUse , propertyAnnotations . filterUseSiteTarget ( SETTER_PARAMETER ) ) <EOL> CONTRACT_EFFECT_LIST -> outerContractDescription = obtainContractDescription ( it ) <EOL> BLOCK -> block = it <EOL> else -> if ( it . isExpression ( ) ) expression = it <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> var accessorVisibility = calculatedModifiers . getVisibility ( ) <EOL> if ( accessorVisibility == Visibilities . Unknown ) { <EOL> accessorVisibility = propertyVisibility <EOL> } <EOL> val status = <EOL> FirDeclarationStatusImpl ( accessorVisibility , calculatedModifiers . getModality ( isClassOrObject = false ) ) . apply { <EOL> isInline = propertyModifiers . hasInline ( ) || calculatedModifiers . hasInline ( ) <EOL> isExternal = propertyModifiers . hasExternal ( ) || calculatedModifiers . hasExternal ( ) <EOL> } <EOL> val sourceElement = getterOrSetter . toFirSourceElement ( ) <EOL> val accessorAdditionalAnnotations = propertyAnnotations . filterUseSiteTarget ( if ( isGetter ) PROPERTY_GETTER else PROPERTY_SETTER ) <EOL> if ( block == null && expression == null ) { <EOL> return FirDefaultPropertyAccessor <EOL> . createGetterOrSetter ( sourceElement , baseModuleData , FirDeclarationOrigin . Source , propertyTypeRefToUse , accessorVisibility , propertySymbol , isGetter ) <EOL> . also { accessor -> <EOL> accessor . replaceAnnotations ( accessorAnnotations + accessorAdditionalAnnotations ) <EOL> accessor . status = status <EOL> accessor . initContainingClassAttr ( ) <EOL> } <EOL> } <EOL> val target = FirFunctionTarget ( labelName = null , isLambda = false ) <EOL> return buildPropertyAccessor { <EOL> source = sourceElement <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = returnType ? : if ( isGetter ) propertyTypeRefToUse else implicitUnitType <EOL> symbol = accessorSymbol <EOL> this . isGetter = isGetter <EOL> this . status = status <EOL> context . firFunctionTargets += target <EOL> annotations += accessorAdditionalAnnotations <EOL> annotations += accessorAnnotations <EOL> if ( ! isGetter ) { <EOL> valueParameters += firValueParameters <EOL> } <EOL> val allowLegacyContractDescription = outerContractDescription == null <EOL> val bodyWithContractDescription = withForcedLocalContext { <EOL> convertFunctionBody ( block , expression , allowLegacyContractDescription ) <EOL> } <EOL> this . body = bodyWithContractDescription . first <EOL> val contractDescription = outerContractDescription ? : bodyWithContractDescription . second <EOL> contractDescription ? . let { <EOL> this . contractDescription = it <EOL> } <EOL> context . firFunctionTargets . removeLast ( ) <EOL> this . propertySymbol = propertySymbol <EOL> } . also { <EOL> target . bind ( it ) <EOL> it . initContainingClassAttr ( ) <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyComponent
 */


private fun LighterASTNode ? . convertBackingField ( propertySymbol : FirPropertySymbol , propertyModifiers : Modifier , propertyReturnType : FirTypeRef , isVar : Boolean , annotationsFromProperty : List < FirAnnotationCall > , property : LighterASTNode , ) : FirBackingField

{ <EOL> var modifiers : Modifier ? = null <EOL> val fieldAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var returnType : FirTypeRef = implicitType <EOL> var backingFieldInitializer : FirExpression ? = null <EOL> this ? . forEachChildren { <EOL> when { <EOL> it . tokenType == MODIFIER_LIST -> { <EOL> modifiers = convertModifierList ( it ) <EOL> fieldAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> it . tokenType == TYPE_REFERENCE -> returnType = convertType ( it ) <EOL> it . isExpression ( ) -> { <EOL> backingFieldInitializer = expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> var componentVisibility = calculatedModifiers . getVisibility ( ) <EOL> if ( componentVisibility == Visibilities . Unknown ) { <EOL> componentVisibility = Visibilities . Private <EOL> } <EOL> val status = obtainPropertyComponentStatus ( componentVisibility , calculatedModifiers , propertyModifiers ) <EOL> val sourceElement = this ? . toFirSourceElement ( ) <EOL> return if ( this != null ) { <EOL> buildBackingField { <EOL> source = sourceElement <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = returnType <EOL> name = StandardNames . BACKING_FIELD <EOL> symbol = FirBackingFieldSymbol ( CallableId ( name ) ) <EOL> this . status = status <EOL> annotations += fieldAnnotations <EOL> annotations += annotationsFromProperty <EOL> this . propertySymbol = propertySymbol <EOL> this . initializer = backingFieldInitializer <EOL> this . isVar = isVar <EOL> this . isVal = ! isVar <EOL> } <EOL> } else { <EOL> FirDefaultPropertyBackingField ( moduleData = baseModuleData , origin = FirDeclarationOrigin . Source , source = property . toFirSourceElement ( KtFakeSourceElementKind . DefaultAccessor ) , annotations = annotationsFromProperty . toMutableList ( ) , returnTypeRef = propertyReturnType . copyWithNewSourceKind ( KtFakeSourceElementKind . DefaultAccessor ) , isVar = isVar , propertySymbol = propertySymbol , status = status , ) <EOL> } <EOL> }


private fun convertSetterParameter ( setterParameter : LighterASTNode , functionSymbol : FirFunctionSymbol < * > , propertyTypeRef : FirTypeRef , additionalAnnotations : List < FirAnnotation > ) : FirValueParameter

{ <EOL> var modifiers : Modifier ? = null <EOL> lateinit var firValueParameter : FirValueParameter <EOL> setterParameter . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> modifiers = convertModifierList ( it ) <EOL> VALUE_PARAMETER -> firValueParameter = convertValueParameter ( it , functionSymbol , ValueParameterDeclaration . SETTER ) . firValueParameter <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> return buildValueParameter { <EOL> source = firValueParameter . source <EOL> containingFunctionSymbol = functionSymbol <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = if ( firValueParameter . returnTypeRef == implicitType ) propertyTypeRef else firValueParameter . returnTypeRef <EOL> name = firValueParameter . name <EOL> symbol = FirValueParameterSymbol ( firValueParameter . name ) <EOL> defaultValue = firValueParameter . defaultValue <EOL> isCrossinline = calculatedModifiers . hasCrossinline ( ) || firValueParameter . isCrossinline <EOL> isNoinline = calculatedModifiers . hasNoinline ( ) || firValueParameter . isNoinline <EOL> isVararg = calculatedModifiers . hasVararg ( ) || firValueParameter . isVararg <EOL> annotations += firValueParameter . annotations <EOL> annotations += additionalAnnotations <EOL> } <EOL> }

/**
 * this is just a VALUE_PARAMETER_LIST
 *
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyComponent
 * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter
 */


fun convertFunctionDeclaration ( functionDeclaration : LighterASTNode ) : FirStatement

{ <EOL> var modifiers : Modifier ? = null <EOL> val functionAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var identifier : String ? = null <EOL> var valueParametersList : LighterASTNode ? = null <EOL> var isReturnType = false <EOL> var receiverType : FirTypeRef ? = null <EOL> var returnType : FirTypeRef ? = null <EOL> val typeConstraints = mutableListOf < TypeConstraint > ( ) <EOL> var block : LighterASTNode ? = null <EOL> var expression : LighterASTNode ? = null <EOL> var hasEqToken = false <EOL> var typeParameterList : LighterASTNode ? = null <EOL> var outerContractDescription : FirContractDescription ? = null <EOL> functionDeclaration . getChildNodeByType ( IDENTIFIER ) ? . let { <EOL> identifier = it . asText <EOL> } <EOL> val parentNode = functionDeclaration . getParent ( ) <EOL> val isLocal = ! ( parentNode ? . tokenType == KT_FILE || parentNode ? . tokenType == CLASS_BODY ) <EOL> val functionSource = functionDeclaration . toFirSourceElement ( ) <EOL> val isAnonymousFunction = identifier == null && isLocal <EOL> val functionName = identifier . nameAsSafeName ( ) <EOL> val functionSymbol : FirFunctionSymbol < * > = if ( isAnonymousFunction ) { <EOL> FirAnonymousFunctionSymbol ( ) <EOL> } else { <EOL> FirNamedFunctionSymbol ( callableIdForName ( functionName ) ) <EOL> } <EOL> withContainerSymbol ( functionSymbol , isLocal ) { <EOL> val target : FirFunctionTarget <EOL> functionDeclaration . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> { <EOL> modifiers = convertModifierList ( it ) <EOL> functionAnnotations += convertAnnotationList ( it ) <EOL> } <EOL> TYPE_PARAMETER_LIST -> typeParameterList = it <EOL> VALUE_PARAMETER_LIST -> valueParametersList = it <EOL> COLON -> isReturnType = true <EOL> TYPE_REFERENCE -> if ( isReturnType ) returnType = convertType ( it ) else receiverType = convertType ( it ) <EOL> TYPE_CONSTRAINT_LIST -> typeConstraints += convertTypeConstraints ( it ) <EOL> CONTRACT_EFFECT_LIST -> outerContractDescription = obtainContractDescription ( it ) <EOL> BLOCK -> block = it <EOL> EQ -> hasEqToken = true <EOL> else -> if ( it . isExpression ( ) ) expression = it <EOL> } <EOL> } <EOL> val calculatedModifiers = modifiers ? : Modifier ( ) <EOL> if ( returnType == null ) { <EOL> returnType = <EOL> if ( block != null || ! hasEqToken ) implicitUnitType <EOL> else implicitType <EOL> } <EOL> val functionBuilder = if ( isAnonymousFunction ) { <EOL> FirAnonymousFunctionBuilder ( ) . apply { <EOL> source = functionSource <EOL> receiverParameter = receiverType ? . convertToReceiverParameter ( ) <EOL> symbol = functionSymbol as FirAnonymousFunctionSymbol <EOL> isLambda = false <EOL> hasExplicitParameterList = true <EOL> label = context . getLastLabel ( functionDeclaration ) <EOL> val labelName = label ? . name ? : context . calleeNamesForLambda . lastOrNull ( ) ? . identifier <EOL> target = FirFunctionTarget ( labelName = labelName , isLambda = false ) <EOL> if ( calculatedModifiers . hasSuspend ( ) ) { <EOL> status = FirResolvedDeclarationStatusImpl . DEFAULT_STATUS_FOR_SUSPEND_FUNCTION_EXPRESSION <EOL> } <EOL> } <EOL> } else { <EOL> val labelName = <EOL> context . getLastLabel ( functionDeclaration ) ? . name ? : runIf ( ! functionName . isSpecial ) { functionName . identifier } <EOL> target = FirFunctionTarget ( labelName , isLambda = false ) <EOL> FirSimpleFunctionBuilder ( ) . apply { <EOL> source = functionSource <EOL> receiverParameter = receiverType ? . convertToReceiverParameter ( ) <EOL> name = functionName <EOL> status = FirDeclarationStatusImpl ( if ( isLocal ) Visibilities . Local else calculatedModifiers . getVisibility ( ) , calculatedModifiers . getModality ( isClassOrObject = false ) ) . apply { <EOL> isExpect = calculatedModifiers . hasExpect ( ) || context . containerIsExpect <EOL> isActual = calculatedModifiers . hasActual ( ) <EOL> isOverride = calculatedModifiers . hasOverride ( ) <EOL> isOperator = calculatedModifiers . hasOperator ( ) <EOL> isInfix = calculatedModifiers . hasInfix ( ) <EOL> isInline = calculatedModifiers . hasInline ( ) <EOL> isTailRec = calculatedModifiers . hasTailrec ( ) <EOL> isExternal = calculatedModifiers . hasExternal ( ) <EOL> isSuspend = calculatedModifiers . hasSuspend ( ) <EOL> } <EOL> symbol = functionSymbol as FirNamedFunctionSymbol <EOL> dispatchReceiverType = runIf ( ! isLocal ) { currentDispatchReceiverType ( ) } <EOL> contextReceivers . addAll ( convertContextReceivers ( functionDeclaration ) ) <EOL> } <EOL> } <EOL> val firTypeParameters = mutableListOf < FirTypeParameter > ( ) <EOL> typeParameterList ? . let { firTypeParameters += convertTypeParameters ( it , typeConstraints , functionSymbol ) } <EOL> val function = functionBuilder . apply { <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> returnTypeRef = returnType ! ! <EOL> context . firFunctionTargets += target <EOL> annotations += functionAnnotations <EOL> val actualTypeParameters = if ( this is FirSimpleFunctionBuilder ) { <EOL> typeParameters += firTypeParameters <EOL> typeParameters <EOL> } else { <EOL> listOf ( ) <EOL> } <EOL> withCapturedTypeParameters ( true , functionSource , actualTypeParameters ) { <EOL> valueParametersList ? . let { list -> <EOL> valueParameters += convertValueParameters ( list , functionSymbol , if ( isAnonymousFunction ) ValueParameterDeclaration . LAMBDA else ValueParameterDeclaration . FUNCTION ) . map { it . firValueParameter } <EOL> } <EOL> val allowLegacyContractDescription = outerContractDescription == null <EOL> val bodyWithContractDescription = withForcedLocalContext { <EOL> convertFunctionBody ( block , expression , allowLegacyContractDescription ) <EOL> } <EOL> this . body = bodyWithContractDescription . first <EOL> val contractDescription = outerContractDescription ? : bodyWithContractDescription . second <EOL> contractDescription ? . let { <EOL> if ( this is FirSimpleFunctionBuilder ) { <EOL> this . contractDescription = it <EOL> } else if ( this is FirAnonymousFunctionBuilder ) { <EOL> this . contractDescription = it <EOL> } <EOL> } <EOL> } <EOL> context . firFunctionTargets . removeLast ( ) <EOL> } . build ( ) . also { <EOL> target . bind ( it ) <EOL> if ( it is FirSimpleFunction ) { <EOL> fillDanglingConstraintsTo ( firTypeParameters , typeConstraints , it ) <EOL> } <EOL> } <EOL> return if ( function is FirAnonymousFunction ) { <EOL> buildAnonymousFunctionExpression { <EOL> source = functionSource <EOL> anonymousFunction = function <EOL> } <EOL> } else { <EOL> function <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunction
 */


private fun convertFunctionBody ( blockNode : LighterASTNode ? , expression : LighterASTNode ? , allowLegacyContractDescription : Boolean ) : Pair < FirBlock ? , FirContractDescription ? >

{ <EOL> return when { <EOL> blockNode != null -> { <EOL> val block = convertBlock ( blockNode ) <EOL> val contractDescription = runIf ( allowLegacyContractDescription ) { <EOL> val blockSource = block . source <EOL> val diagnostic = when { <EOL> blockSource == null || ! isCallTheFirstStatement ( blockSource ) -> ConeContractShouldBeFirstStatement <EOL> else -> null <EOL> } <EOL> processLegacyContractDescription ( block , diagnostic ) <EOL> } <EOL> block to contractDescription <EOL> } <EOL> expression != null -> FirSingleExpressionBlock ( expressionConverter . getAsFirExpression < FirExpression > ( expression , "<STR_LIT>" ) . toReturn ( ) ) to null <EOL> else -> null to null <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunctionBody
 * @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.buildFirBody
 */


fun convertBlock ( block : LighterASTNode ? ) : FirBlock

{ <EOL> if ( block == null ) return buildEmptyExpressionBlock ( ) <EOL> if ( block . tokenType != BLOCK ) { <EOL> return FirSingleExpressionBlock ( expressionConverter . getAsFirStatement ( block ) ) <EOL> } <EOL> return convertBlockExpression ( block ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseBlock
 */


private fun convertConstructorInvocation ( constructorInvocation : LighterASTNode ) : Pair < FirTypeRef , List < FirExpression > >

{ <EOL> var firTypeRef : FirTypeRef = implicitType <EOL> val firValueArguments = mutableListOf < FirExpression > ( ) <EOL> constructorInvocation . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> CONSTRUCTOR_CALLEE -> firTypeRef = convertType ( it ) <EOL> VALUE_ARGUMENT_LIST -> firValueArguments += expressionConverter . convertValueArguments ( it ) <EOL> } <EOL> } <EOL> return Pair ( firTypeRef , firValueArguments ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseDelegationSpecifier
 *
 * constructorInvocation
 * : userType valueArguments
 * ;
 */


private fun convertExplicitDelegation ( explicitDelegation : LighterASTNode , delegateFieldsMap : MutableMap < Int , FirFieldSymbol > , index : Int ) : FirTypeRef

{ <EOL> lateinit var firTypeRef : FirTypeRef <EOL> var firExpression : FirExpression ? = null <EOL> explicitDelegation . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> TYPE_REFERENCE -> firTypeRef = convertType ( it ) <EOL> else -> if ( it . isExpression ( ) ) firExpression = expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> val calculatedFirExpression = firExpression ? : buildErrorExpression ( explicitDelegation . toFirSourceElement ( ) , ConeSyntaxDiagnostic ( "<STR_LIT>" ) ) <EOL> delegateFieldsMap . put ( index , buildField { <EOL> source = explicitDelegation . toFirSourceElement ( ) . fakeElement ( KtFakeSourceElementKind . ClassDelegationField ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Synthetic . DelegateField <EOL> name = NameUtils . delegateFieldName ( delegateFieldsMap . size ) <EOL> returnTypeRef = firTypeRef <EOL> symbol = FirFieldSymbol ( CallableId ( context . currentClassId , name ) ) <EOL> isVar = false <EOL> status = FirDeclarationStatusImpl ( Visibilities . Private , Modality . FINAL ) <EOL> initializer = calculatedFirExpression <EOL> dispatchReceiverType = currentDispatchReceiverType ( ) <EOL> } . symbol ) <EOL> return firTypeRef <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseDelegationSpecifier
 *
 * explicitDelegation
 * : userType "by" element
 * ;
 */


private fun convertTypeParameters ( typeParameterList : LighterASTNode , typeConstraints : List < TypeConstraint > , containingDeclarationSymbol : FirBasedSymbol < * > ) : List < FirTypeParameter >

{ <EOL> return typeParameterList . forEachChildrenReturnList { node , container -> <EOL> when ( node . tokenType ) { <EOL> TYPE_PARAMETER -> container += convertTypeParameter ( node , typeConstraints , containingDeclarationSymbol ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeParameterList
 */


private fun convertTypeConstraints ( typeConstraints : LighterASTNode ) : List < TypeConstraint >

{ <EOL> return typeConstraints . forEachChildrenReturnList { node , container -> <EOL> when ( node . tokenType ) { <EOL> TYPE_CONSTRAINT -> container += convertTypeConstraint ( node ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeConstraintList
 */


private fun convertTypeConstraint ( typeConstraint : LighterASTNode ) : TypeConstraint

{ <EOL> var identifier : String ? = null <EOL> var firType : FirTypeRef ? = null <EOL> var referenceExpression : LighterASTNode ? = null <EOL> val annotations = mutableListOf < FirAnnotation > ( ) <EOL> typeConstraint . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> ANNOTATION_ENTRY -> { <EOL> annotations += <EOL> convertAnnotationEntry ( it , diagnostic = ConeSimpleDiagnostic ( "<STR_LIT>" , DiagnosticKind . AnnotationNotAllowed , ) ) <EOL> } <EOL> REFERENCE_EXPRESSION -> { <EOL> identifier = it . asText <EOL> referenceExpression = it <EOL> } <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> } <EOL> } <EOL> return TypeConstraint ( annotations , identifier , firType ? : buildErrorTypeRef { } , ( referenceExpression ? : typeConstraint ) . toFirSourceElement ( ) ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeConstraint
 */


private fun convertTypeParameter ( typeParameter : LighterASTNode , typeConstraints : List < TypeConstraint > , containingSymbol : FirBasedSymbol < * > ) : FirTypeParameter

{ <EOL> var typeParameterModifiers : TypeParameterModifier ? = null <EOL> var identifier : String ? = null <EOL> var firType : FirTypeRef ? = null <EOL> typeParameter . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> typeParameterModifiers = convertTypeParameterModifiers ( it ) <EOL> IDENTIFIER -> identifier = it . asText <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> } <EOL> } <EOL> val calculatedTypeParameterModifiers = typeParameterModifiers ? : TypeParameterModifier ( ) <EOL> return buildTypeParameter { <EOL> source = typeParameter . toFirSourceElement ( ) <EOL> moduleData = baseModuleData <EOL> origin = FirDeclarationOrigin . Source <EOL> name = identifier . nameAsSafeName ( ) <EOL> symbol = FirTypeParameterSymbol ( ) <EOL> containingDeclarationSymbol = containingSymbol <EOL> variance = calculatedTypeParameterModifiers . getVariance ( ) <EOL> isReified = calculatedTypeParameterModifiers . hasReified ( ) <EOL> annotations += calculatedTypeParameterModifiers . annotations <EOL> firType ? . let { bounds += it } <EOL> for ( typeConstraint in typeConstraints ) { <EOL> if ( typeConstraint . identifier == identifier ) { <EOL> bounds += typeConstraint . firTypeRef <EOL> annotations += typeConstraint . annotations <EOL> } <EOL> } <EOL> addDefaultBoundIfNecessary ( ) <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeParameter
 */


fun convertType ( type : LighterASTNode ) : FirTypeRef

{ <EOL> val typeRefSource = type . toFirSourceElement ( ) <EOL> val allTypeModifiers = mutableListOf < Modifier > ( ) <EOL> var firType : FirTypeRef ? = null <EOL> type . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> MODIFIER_LIST -> allTypeModifiers += convertTypeModifierList ( it ) <EOL> USER_TYPE -> firType = convertUserType ( typeRefSource , it ) <EOL> NULLABLE_TYPE -> firType = convertNullableType ( typeRefSource , it , allTypeModifiers ) <EOL> FUNCTION_TYPE -> firType = convertFunctionType ( typeRefSource , it , isSuspend = allTypeModifiers . hasSuspend ( ) ) <EOL> DYNAMIC_TYPE -> firType = buildDynamicTypeRef { <EOL> source = typeRefSource <EOL> isMarkedNullable = false <EOL> } <EOL> INTERSECTION_TYPE -> firType = convertIntersectionType ( typeRefSource , it , false ) <EOL> CONTEXT_RECEIVER_LIST , TokenType . ERROR_ELEMENT -> firType = <EOL> buildErrorTypeRef { <EOL> source = typeRefSource <EOL> diagnostic = ConeSyntaxDiagnostic ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> } <EOL> val calculatedFirType = firType ? : buildErrorTypeRef { <EOL> source = typeRefSource <EOL> diagnostic = ConeSyntaxDiagnostic ( "<STR_LIT>" ) <EOL> } <EOL> for ( modifierList in allTypeModifiers ) { <EOL> calculatedFirType . replaceAnnotations ( calculatedFirType . annotations . smartPlus ( modifierList . annotations ) ) <EOL> } <EOL> return calculatedFirType <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeRef
 */


private fun convertReceiverType ( receiverType : LighterASTNode ) : FirTypeRef

{ <EOL> receiverType . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> TYPE_REFERENCE -> return convertType ( it ) <EOL> } <EOL> } <EOL> throw Exception ( ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeRefContents
 */


private fun convertNullableType ( typeRefSource : KtSourceElement , nullableType : LighterASTNode , allTypeModifiers : MutableList < Modifier > , isNullable : Boolean = true ) : FirTypeRef

{ <EOL> lateinit var firType : FirTypeRef <EOL> nullableType . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> allTypeModifiers += convertTypeModifierList ( it ) <EOL> USER_TYPE -> firType = convertUserType ( typeRefSource , it , isNullable ) <EOL> FUNCTION_TYPE -> firType = convertFunctionType ( typeRefSource , it , isNullable , isSuspend = allTypeModifiers . hasSuspend ( ) ) <EOL> NULLABLE_TYPE -> firType = convertNullableType ( typeRefSource , it , allTypeModifiers ) <EOL> DYNAMIC_TYPE -> firType = buildDynamicTypeRef { <EOL> source = typeRefSource <EOL> isMarkedNullable = true <EOL> } <EOL> INTERSECTION_TYPE -> firType = convertIntersectionType ( typeRefSource , it , isNullable ) <EOL> } <EOL> } <EOL> return firType <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseNullableTypeSuffix
 */


private fun convertUserType ( typeRefSource : KtSourceElement , userType : LighterASTNode , isNullable : Boolean = false ) : FirTypeRef

{ <EOL> var simpleFirUserType : FirUserTypeRef ? = null <EOL> var identifier : String ? = null <EOL> var identifierSource : KtSourceElement ? = null <EOL> val firTypeArguments = mutableListOf < FirTypeProjection > ( ) <EOL> var typeArgumentsSource : KtSourceElement ? = null <EOL> userType . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> USER_TYPE -> simpleFirUserType = convertUserType ( typeRefSource , it ) as? FirUserTypeRef <EOL> REFERENCE_EXPRESSION -> { <EOL> identifierSource = it . toFirSourceElement ( ) <EOL> identifier = it . asText <EOL> } <EOL> TYPE_ARGUMENT_LIST -> { <EOL> typeArgumentsSource = it . toFirSourceElement ( ) <EOL> firTypeArguments += convertTypeArguments ( it , allowedUnderscoredTypeArgument = false ) <EOL> } <EOL> } <EOL> } <EOL> if ( identifier == null ) { <EOL> return buildErrorTypeRef { <EOL> source = typeRefSource <EOL> diagnostic = ConeSyntaxDiagnostic ( "<STR_LIT>" ) <EOL> simpleFirUserType ? . let { qualifierPart -> <EOL> if ( qualifierPart . qualifier . isNotEmpty ( ) ) { <EOL> partiallyResolvedTypeRef = buildUserTypeRef { <EOL> source = qualifierPart . qualifier . last ( ) . source <EOL> isMarkedNullable = false <EOL> this . qualifier . addAll ( qualifierPart . qualifier ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> val qualifierPart = FirQualifierPartImpl ( identifierSource ! ! , identifier . nameAsSafeName ( ) , FirTypeArgumentListImpl ( typeArgumentsSource ? : typeRefSource ) . apply { <EOL> typeArguments += firTypeArguments <EOL> } ) <EOL> return buildUserTypeRef { <EOL> source = typeRefSource <EOL> isMarkedNullable = isNullable <EOL> qualifier . add ( qualifierPart ) <EOL> simpleFirUserType ? . qualifier ? . let { this . qualifier . addAll ( <NUM_LIT:0> , it ) } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseUserType
 */


fun convertTypeArguments ( typeArguments : LighterASTNode , allowedUnderscoredTypeArgument : Boolean ) : List < FirTypeProjection >

{ <EOL> return typeArguments . forEachChildrenReturnList { node , container -> <EOL> when ( node . tokenType ) { <EOL> TYPE_PROJECTION -> container += convertTypeProjection ( node , allowedUnderscoredTypeArgument ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeArgumentList
 */


private fun convertTypeProjection ( typeProjection : LighterASTNode , allowedUnderscoredTypeArgument : Boolean ) : FirTypeProjection

{ <EOL> var modifiers : TypeProjectionModifier ? = null <EOL> lateinit var firType : FirTypeRef <EOL> var isStarProjection = false <EOL> typeProjection . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> modifiers = convertTypeArgumentModifierList ( it ) <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> MUL -> isStarProjection = true <EOL> } <EOL> } <EOL> return when { <EOL> isStarProjection -> buildStarProjection { source = typeProjection . toFirSourceElement ( ) } <EOL> allowedUnderscoredTypeArgument && ( firType as? FirUserTypeRef ) ? . isUnderscored == true -> buildPlaceholderProjection { <EOL> source = typeProjection . toFirSourceElement ( ) <EOL> } <EOL> else -> buildTypeProjectionWithVariance { <EOL> source = typeProjection . toFirSourceElement ( ) <EOL> typeRef = firType <EOL> variance = ( modifiers ? : TypeProjectionModifier ( ) ) . getVariance ( ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.tryParseTypeArgumentList
 */


private fun convertFunctionType ( typeRefSource : KtSourceElement , functionType : LighterASTNode , isNullable : Boolean = false , isSuspend : Boolean = false ) : FirTypeRef

{ <EOL> var receiverTypeReference : FirTypeRef ? = null <EOL> lateinit var returnTypeReference : FirTypeRef <EOL> val parameters = mutableListOf < FirFunctionTypeParameter > ( ) <EOL> functionType . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> FUNCTION_TYPE_RECEIVER -> receiverTypeReference = convertReceiverType ( it ) <EOL> VALUE_PARAMETER_LIST -> parameters += convertFunctionTypeParameters ( it ) <EOL> TYPE_REFERENCE -> returnTypeReference = convertType ( it ) <EOL> } <EOL> } <EOL> return buildFunctionTypeRef { <EOL> source = typeRefSource <EOL> isMarkedNullable = isNullable <EOL> receiverTypeRef = receiverTypeReference <EOL> returnTypeRef = returnTypeReference <EOL> this . parameters += parameters <EOL> this . isSuspend = isSuspend <EOL> this . contextReceiverTypeRefs . addAll ( functionType . getChildNodeByType ( CONTEXT_RECEIVER_LIST ) ? . getChildNodesByType ( CONTEXT_RECEIVER ) ? . mapNotNull { <EOL> it . getChildNodeByType ( TYPE_REFERENCE ) ? . let ( :: convertType ) <EOL> } . orEmpty ( ) ) <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunctionType
 */


fun convertValueParameters ( valueParameters : LighterASTNode , functionSymbol : FirFunctionSymbol < * > , valueParameterDeclaration : ValueParameterDeclaration , additionalAnnotations : List < FirAnnotation > = emptyList ( ) ) : List < ValueParameter >

{ <EOL> return valueParameters . forEachChildrenReturnList { node , container -> <EOL> when ( node . tokenType ) { <EOL> VALUE_PARAMETER -> container += convertValueParameter ( node , functionSymbol , valueParameterDeclaration , additionalAnnotations ) <EOL> } <EOL> } <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseValueParameterList
 */


fun convertValueParameter ( valueParameter : LighterASTNode , functionSymbol : FirFunctionSymbol < * > ? , valueParameterDeclaration : ValueParameterDeclaration , additionalAnnotations : List < FirAnnotation > = emptyList ( ) ) : ValueParameter

{ <EOL> var modifiers : Modifier ? = null <EOL> val valueAnnotations = mutableListOf < FirAnnotationCall > ( ) <EOL> var isVal = false <EOL> var isVar = false <EOL> var identifier : String ? = null <EOL> var firType : FirTypeRef ? = null <EOL> var firExpression : FirExpression ? = null <EOL> var destructuringDeclaration : DestructuringDeclaration ? = null <EOL> valueParameter . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> modifiers = convertModifierList ( it ) <EOL> VAL_KEYWORD -> isVal = true <EOL> VAR_KEYWORD -> isVar = true <EOL> IDENTIFIER -> identifier = it . asText <EOL> TYPE_REFERENCE -> { } <EOL> DESTRUCTURING_DECLARATION -> destructuringDeclaration = convertDestructingDeclaration ( it ) <EOL> else -> if ( it . isExpression ( ) ) firExpression = expressionConverter . getAsFirExpression ( it , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> val name = convertValueParameterName ( identifier . nameAsSafeName ( ) , valueParameterDeclaration ) { identifier } <EOL> val valueParameterSymbol = FirValueParameterSymbol ( name ) <EOL> withContainerSymbol ( valueParameterSymbol , isLocal = valueParameterDeclaration != ValueParameterDeclaration . FUNCTION ) { <EOL> valueParameter . forEachChildren { <EOL> when ( it . tokenType ) { <EOL> MODIFIER_LIST -> valueAnnotations += convertAnnotationList ( it ) <EOL> TYPE_REFERENCE -> firType = convertType ( it ) <EOL> } <EOL> } <EOL> } <EOL> val valueParameterSource = valueParameter . toFirSourceElement ( ) <EOL> return ValueParameter ( valueParameterSymbol = valueParameterSymbol , isVal = isVal , isVar = isVar , modifiers = modifiers ? : Modifier ( ) , valueParameterAnnotations = valueAnnotations , returnTypeRef = firType ? : when { <EOL> valueParameterDeclaration . shouldExplicitParameterTypeBePresent -> createNoTypeForParameterTypeRef ( valueParameterSource ) <EOL> else -> implicitType <EOL> } , source = valueParameterSource , moduleData = baseModuleData , isFromPrimaryConstructor = valueParameterDeclaration == ValueParameterDeclaration . PRIMARY_CONSTRUCTOR , additionalAnnotations = additionalAnnotations , name = name , defaultValue = firExpression , containingFunctionSymbol = functionSymbol , destructuringDeclaration = destructuringDeclaration ) <EOL> }

/**
 * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseValueParameter
 */


public fun Sink . writeString ( string : String , charset : Charset , startIndex : Int = <NUM_LIT:0> , endIndex : Int = string . length )

{ <EOL> checkBounds ( string . length , startIndex , endIndex ) <EOL> if ( charset == Charsets . UTF_8 ) return writeString ( string , startIndex , endIndex ) <EOL> val data = string . substring ( startIndex , endIndex ) . toByteArray ( charset ) <EOL> write ( data , <NUM_LIT:0> , data . size ) <EOL> }

/**
 * Encodes substring of [string] starting at [startIndex] and ending at [endIndex] using [charset]
 * and writes into this sink.
 *
 * @param string the string to encode into this sink.
 * @param charset the [Charset] to use for encoding.
 * @param startIndex the index of the first character to encode, inclusive, 0 by default.
 * @param endIndex the index of the last character to encode, exclusive, `string.length` by default.
 *
 * @throws IndexOutOfBoundsException when [startIndex] or [endIndex] is out of range of [string] indices.
 * @throws IllegalArgumentException when `startIndex > endIndex`.
 * @throws IllegalStateException when the sink is closed.
 *
 * @sample kotlinx.io.samples.KotlinxIoSamplesJvm.readWriteStrings
 */


@ OptIn ( DelicateIoApi :: class ) <EOL> public fun Sink . asOutputStream ( ) : OutputStream

{ <EOL> val isClosed : ( ) -> Boolean = when ( this ) { <EOL> is RealSink -> this :: closed <EOL> is Buffer -> { <EOL> { false } <EOL> } <EOL> } <EOL> return object : OutputStream ( ) { <EOL> override fun write ( byte : Int ) { <EOL> if ( isClosed ( ) ) throw IOException ( "<STR_LIT>" ) <EOL> writeToInternalBuffer { it . writeByte ( byte . toByte ( ) ) } <EOL> } <EOL> override fun write ( data : ByteArray , offset : Int , byteCount : Int ) { <EOL> if ( isClosed ( ) ) throw IOException ( "<STR_LIT>" ) <EOL> writeToInternalBuffer { it . write ( data , offset , offset + byteCount ) } <EOL> } <EOL> override fun flush ( ) { <EOL> if ( ! isClosed ( ) ) { <EOL> this@asOutputStream . flush ( ) <EOL> } <EOL> } <EOL> override fun close ( ) = this@asOutputStream . close ( ) <EOL> override fun toString ( ) = "<STR_LIT>" <EOL> } <EOL> }

/**
 * Returns an output stream that writes to this sink. Closing the stream will also close this sink.
 *
 * @sample kotlinx.io.samples.KotlinxIoSamplesJvm.asStream
 */


@ OptIn ( InternalIoApi :: class ) <EOL> public fun Sink . write ( source : ByteBuffer ) : Int

{ <EOL> val sizeBefore = buffer . size <EOL> buffer . transferFrom ( source ) <EOL> val bytesRead = buffer . size - sizeBefore <EOL> hintEmit ( ) <EOL> return bytesRead . toInt ( ) <EOL> }

/**
 * Writes data from the [source] into this sink and returns the number of bytes written.
 *
 * @param source the source to read from.
 *
 * @throws IllegalStateException when the sink is closed.
 *
 * @sample kotlinx.io.samples.KotlinxIoSamplesJvm.readWriteByteBuffer
 */


public fun Sink . asByteChannel ( ) : WritableByteChannel

{ <EOL> val isClosed : ( ) -> Boolean = when ( this ) { <EOL> is RealSink -> this :: closed <EOL> is Buffer -> { <EOL> { false } <EOL> } <EOL> } <EOL> return object : WritableByteChannel { <EOL> override fun close ( ) { <EOL> this@asByteChannel . close ( ) <EOL> } <EOL> override fun isOpen ( ) : Boolean = ! isClosed ( ) <EOL> override fun write ( source : ByteBuffer ) : Int { <EOL> check ( ! isClosed ( ) ) { "<STR_LIT>" } <EOL> return this@asByteChannel . write ( source ) <EOL> } <EOL> } <EOL> }

/**
 * Returns [WritableByteChannel] backed by this sink. Closing the channel will also close the sink.
 */


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun UIntProgression . first ( ) : UInt

{ <EOL> if ( isEmpty ( ) ) <EOL> throw NoSuchElementException ( "<STR_LIT>" ) <EOL> return this . first <EOL> }

/**
 * Returns the first element.
 *
 * @throws NoSuchElementException if the progression is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun ULongProgression . first ( ) : ULong


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun UIntProgression . firstOrNull ( ) : UInt ?

{ <EOL> return if ( isEmpty ( ) ) null else this . first <EOL> }

/**
 * Returns the first element, or `null` if the progression is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun ULongProgression . firstOrNull ( ) : ULong ?


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun UIntProgression . last ( ) : UInt

{ <EOL> if ( isEmpty ( ) ) <EOL> throw NoSuchElementException ( "<STR_LIT>" ) <EOL> return this . last <EOL> }

/**
 * Returns the last element.
 *
 * @throws NoSuchElementException if the progression is empty.
 *
 * @sample samples.collections.Collections.Elements.last
 */


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun ULongProgression . last ( ) : ULong


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun UIntProgression . lastOrNull ( ) : UInt ?

{ <EOL> return if ( isEmpty ( ) ) null else this . last <EOL> }

/**
 * Returns the last element, or `null` if the progression is empty.
 *
 * @sample samples.collections.Collections.Elements.last
 */


@ SinceKotlin ( "<STR_LIT:1.7>" ) <EOL> public fun ULongProgression . lastOrNull ( ) : ULong ?


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun UIntRange . random ( ) : UInt

{ <EOL> return random ( Random ) <EOL> }

/**
 * Returns a random element from this range.
 *
 * @throws IllegalArgumentException if this range is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun ULongRange . random ( ) : ULong


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UIntRange . random ( random : Random ) : UInt

{ <EOL> try { <EOL> return random . nextUInt ( this ) <EOL> } catch ( e : IllegalArgumentException ) { <EOL> throw NoSuchElementException ( e . message ) <EOL> } <EOL> }

/**
 * Returns a random element from this range using the specified source of randomness.
 *
 * @throws IllegalArgumentException if this range is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULongRange . random ( random : Random ) : ULong

{ <EOL> try { <EOL> return random . nextULong ( this ) <EOL> } catch ( e : IllegalArgumentException ) { <EOL> throw NoSuchElementException ( e . message ) <EOL> } <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalStdlibApi :: class , ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun UIntRange . randomOrNull ( ) : UInt ?

{ <EOL> return randomOrNull ( Random ) <EOL> }

/**
 * Returns a random element from this range, or `null` if this range is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalStdlibApi :: class , ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun ULongRange . randomOrNull ( ) : ULong ?


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalStdlibApi :: class , ExperimentalUnsignedTypes :: class ) <EOL> public fun UIntRange . randomOrNull ( random : Random ) : UInt ?

{ <EOL> if ( isEmpty ( ) ) <EOL> return null <EOL> return random . nextUInt ( this ) <EOL> }

/**
 * Returns a random element from this range using the specified source of randomness, or `null` if this range is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalStdlibApi :: class , ExperimentalUnsignedTypes :: class ) <EOL> public fun ULongRange . randomOrNull ( random : Random ) : ULong ?

{ <EOL> if ( isEmpty ( ) ) <EOL> return null <EOL> return random . nextULong ( this ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline operator fun UIntRange . contains ( element : UInt ? ) : Boolean

{ <EOL> return element != null && contains ( element ) <EOL> }

/**
 * Returns `true` if this range contains the specified [element].
 *
 * Always returns `false` if the [element] is `null`.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline operator fun ULongRange . contains ( element : ULong ? ) : Boolean


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun UIntRange . contains ( value : UByte ) : Boolean

{ <EOL> return contains ( value . toUInt ( ) ) <EOL> }

/**
 * Checks if the specified [value] belongs to this range.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun ULongRange . contains ( value : UByte ) : Boolean

{ <EOL> return contains ( value . toULong ( ) ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun ULongRange . contains ( value : UInt ) : Boolean


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun UIntRange . contains ( value : ULong ) : Boolean

{ <EOL> return ( value shr UInt . SIZE_BITS ) == <NUM_LIT> && contains ( value . toUInt ( ) ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun UIntRange . contains ( value : UShort ) : Boolean


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public operator fun ULongRange . contains ( value : UShort ) : Boolean


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UByte . downTo ( to : UByte ) : UIntProgression

{ <EOL> return UIntProgression . fromClosedRange ( this . toUInt ( ) , to . toUInt ( ) , - <NUM_LIT:1> ) <EOL> }

/**
 * Returns a progression from this value down to the specified [to] value with the step -1.
 *
 * The [to] value should be less than or equal to `this` value.
 * If the [to] value is greater than `this` value the returned progression is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UInt . downTo ( to : UInt ) : UIntProgression

{ <EOL> return UIntProgression . fromClosedRange ( this , to , - <NUM_LIT:1> ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun ULong . downTo ( to : ULong ) : ULongProgression

{ <EOL> return ULongProgression . fromClosedRange ( this , to , - <NUM_LIT:1L> ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UShort . downTo ( to : UShort ) : UIntProgression


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UIntProgression . reversed ( ) : UIntProgression

{ <EOL> return UIntProgression . fromClosedRange ( last , first , - step ) <EOL> }

/**
 * Returns a progression that goes over the same range in the opposite direction with the same step.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULongProgression . reversed ( ) : ULongProgression

{ <EOL> return ULongProgression . fromClosedRange ( last , first , - step ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UIntProgression . step ( step : Int ) : UIntProgression

{ <EOL> checkStepIsPositive ( step > <NUM_LIT:0> , step ) <EOL> return UIntProgression . fromClosedRange ( first , last , if ( this . step > <NUM_LIT:0> ) step else - step ) <EOL> }

/**
 * Returns a progression that goes over the same range with the given step.
 *
 * @sample samples.ranges.Ranges.stepUInt
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun ULongProgression . step ( step : Long ) : ULongProgression

{ <EOL> checkStepIsPositive ( step > <NUM_LIT:0> , step ) <EOL> return ULongProgression . fromClosedRange ( first , last , if ( this . step > <NUM_LIT:0> ) step else - step ) <EOL> }

/**
 * Returns a progression that goes over the same range with the given step.
 *
 * @sample samples.ranges.Ranges.stepULong
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UByte . until ( to : UByte ) : UIntRange

{ <EOL> if ( to <= UByte . MIN_VALUE ) return UIntRange . EMPTY <EOL> return this . toUInt ( ) .. ( to - <NUM_LIT:1u> ) . toUInt ( ) <EOL> }

/**
 * Returns a range from this value up to but excluding the specified [to] value.
 *
 * If the [to] value is less than or equal to `this` value, then the returned range is empty.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UInt . until ( to : UInt ) : UIntRange

{ <EOL> if ( to <= UInt . MIN_VALUE ) return UIntRange . EMPTY <EOL> return this .. ( to - <NUM_LIT:1u> ) . toUInt ( ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun ULong . until ( to : ULong ) : ULongRange

{ <EOL> if ( to <= ULong . MIN_VALUE ) return ULongRange . EMPTY <EOL> return this .. ( to - <NUM_LIT:1u> ) . toULong ( ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public infix fun UShort . until ( to : UShort ) : UIntRange

{ <EOL> if ( to <= UShort . MIN_VALUE ) return UIntRange . EMPTY <EOL> return this . toUInt ( ) .. ( to - <NUM_LIT:1u> ) . toUInt ( ) <EOL> }


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UInt . coerceAtLeast ( minimumValue : UInt ) : UInt

{ <EOL> return if ( this < minimumValue ) minimumValue else this <EOL> }

/**
 * Ensures that this value is not less than the specified [minimumValue].
 *
 * @return this value if it's greater than or equal to the [minimumValue] or the [minimumValue] otherwise.
 *
 * @sample samples.comparisons.ComparableOps.coerceAtLeastUnsigned
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULong . coerceAtLeast ( minimumValue : ULong ) : ULong


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UByte . coerceAtLeast ( minimumValue : UByte ) : UByte


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UShort . coerceAtLeast ( minimumValue : UShort ) : UShort


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UInt . coerceAtMost ( maximumValue : UInt ) : UInt

{ <EOL> return if ( this > maximumValue ) maximumValue else this <EOL> }

/**
 * Ensures that this value is not greater than the specified [maximumValue].
 *
 * @return this value if it's less than or equal to the [maximumValue] or the [maximumValue] otherwise.
 *
 * @sample samples.comparisons.ComparableOps.coerceAtMostUnsigned
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULong . coerceAtMost ( maximumValue : ULong ) : ULong


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UByte . coerceAtMost ( maximumValue : UByte ) : UByte


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UShort . coerceAtMost ( maximumValue : UShort ) : UShort


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UInt . coerceIn ( minimumValue : UInt , maximumValue : UInt ) : UInt

{ <EOL> if ( minimumValue > maximumValue ) throw IllegalArgumentException ( "<STR_LIT>" ) <EOL> if ( this < minimumValue ) return minimumValue <EOL> if ( this > maximumValue ) return maximumValue <EOL> return this <EOL> }

/**
 * Ensures that this value lies in the specified range [minimumValue]..[maximumValue].
 *
 * @return this value if it's in the range, or [minimumValue] if this value is less than [minimumValue], or [maximumValue] if this value is greater than [maximumValue].
 *
 * @sample samples.comparisons.ComparableOps.coerceInUnsigned
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULong . coerceIn ( minimumValue : ULong , maximumValue : ULong ) : ULong


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UByte . coerceIn ( minimumValue : UByte , maximumValue : UByte ) : UByte


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UShort . coerceIn ( minimumValue : UShort , maximumValue : UShort ) : UShort


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun UInt . coerceIn ( range : ClosedRange < UInt > ) : UInt

{ <EOL> if ( range is ClosedFloatingPointRange ) { <EOL> return this . coerceIn < UInt > ( range ) <EOL> } <EOL> if ( range . isEmpty ( ) ) throw IllegalArgumentException ( "<STR_LIT>" ) <EOL> return when { <EOL> this < range . start -> range . start <EOL> this > range . endInclusive -> range . endInclusive <EOL> else -> this <EOL> } <EOL> }

/**
 * Ensures that this value lies in the specified [range].
 *
 * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
 *
 * @sample samples.comparisons.ComparableOps.coerceInUnsigned
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> @ WasExperimental ( ExperimentalUnsignedTypes :: class ) <EOL> public fun ULong . coerceIn ( range : ClosedRange < ULong > ) : ULong

{ <EOL> if ( range is ClosedFloatingPointRange ) { <EOL> return this . coerceIn < ULong > ( range ) <EOL> } <EOL> if ( range . isEmpty ( ) ) throw IllegalArgumentException ( "<STR_LIT>" ) <EOL> return when { <EOL> this < range . start -> range . start <EOL> this > range . endInclusive -> range . endInclusive <EOL> else -> this <EOL> } <EOL> }


private fun createKSerializerParamsForEachGenericArgument ( parentFunction : FunctionDescriptor , serializableClass : ClassDescriptor , actualArgsOffset : Int = <NUM_LIT:0> ) : Pair < List < TypeParameterDescriptor > , List < ValueParameterDescriptor > >

{ <EOL> val serializerClass = serializableClass . getClassFromSerializationPackage ( SerialEntityNames . KSERIALIZER_CLASS ) <EOL> val args = mutableListOf < ValueParameterDescriptor > ( ) <EOL> val typeArgs = mutableListOf < TypeParameterDescriptor > ( ) <EOL> var i = <NUM_LIT:0> <EOL> serializableClass . declaredTypeParameters . forEach { _ -> <EOL> val targ = TypeParameterDescriptorImpl . createWithDefaultBound ( parentFunction , Annotations . EMPTY , false , Variance . INVARIANT , Name . identifier ( "<STR_LIT>" ) , i , LockBasedStorageManager . NO_LOCKS ) <EOL> val pType = <EOL> KotlinTypeFactory . simpleNotNullType ( TypeAttributes . Empty , serializerClass , listOf ( TypeProjectionImpl ( targ . defaultType ) ) ) <EOL> args . add ( ValueParameterDescriptorImpl ( containingDeclaration = parentFunction , original = null , index = actualArgsOffset + i , annotations = Annotations . EMPTY , name = Name . identifier ( "<STR_LIT>" ) , outType = pType , declaresDefaultValue = false , isCrossinline = false , isNoinline = false , varargElementType = null , source = parentFunction . source ) ) <EOL> typeArgs . add ( targ ) <EOL> i ++ <EOL> } <EOL> return typeArgs to args <EOL> }

/**
 * Creates free type parameters T0, T1, ... for given serializable class
 * Returns [T0, T1, ...] and [KSerializer<T0>, KSerializer<T1>,...]
 */


private fun FunctionDescriptor . incDecCheckForExpectClass ( receiver : ReceiverParameterDescriptor ) : Boolean

{ <EOL> val receiverValue = receiver . value <EOL> if ( receiverValue !is ImplicitClassReceiver ) return false <EOL> val classDescriptor = receiverValue . classDescriptor <EOL> if ( ! classDescriptor . isExpect ) return false <EOL> val potentialActualAliasId = classDescriptor . classId ? : return false <EOL> val actualReceiverTypeAlias = <EOL> classDescriptor . module . findClassifierAcrossModuleDependencies ( potentialActualAliasId ) as? TypeAliasDescriptor ? : return false <EOL> returnType ? . let { returnType -> <EOL> return returnType . isSubtypeOf ( actualReceiverTypeAlias . expandedType ) <EOL> } <EOL> return false <EOL> }

/**
 * See KT-49714
 * Workaround for mismatching types of an implicit dispatch receiver inside an `expect` class
 * and a type resolved from a reference to this class. During compilation all actual type aliases are known,
 * so the explicit return type is `actual`. But the implicit receiver type inside the class remains `expect`
 * because it's received from the default type of the containing class, which is not affected by the `actual` type alias.
 *
 * `actual` classes are not affected, since non-parameterized type constructors with equal fqNames are considered
 * equal, so subtyping check passes in this case despite mismatching expect/actual in the corresponding declaration descriptors.
 */


fun FirTypeScope . retrieveDirectOverriddenOf ( memberSymbol : FirCallableSymbol < * > ) : List < FirCallableSymbol < * > >

{ <EOL> return when ( memberSymbol ) { <EOL> is FirNamedFunctionSymbol -> { <EOL> processFunctionsByName ( memberSymbol . name ) { } <EOL> getDirectOverriddenFunctions ( memberSymbol ) <EOL> } <EOL> is FirPropertySymbol -> { <EOL> processPropertiesByName ( memberSymbol . name ) { } <EOL> getDirectOverriddenProperties ( memberSymbol ) <EOL> } <EOL> else -> throw IllegalArgumentException ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * Provides a list of callables which are directly overridden by the given symbol
 *
 * Please be very accurate with using this function.
 * It can be convenient if the only thing you need is to get directly overridden symbols and nothing more,
 * but even in this case please check that you are using a correct scope.
 * E.g. if you want to get overridden symbols of some Foo.bar,
 * the scope in use must be built from the Foo-based type or Foo class itself.
 *
 * If you need to traverse some complex overridden hierarchy,
 * please consider using processDirectOverriddenFunctions(Properties)WithBaseScope instead.
 *
 * @param memberSymbol A callable symbol to find its directly overridden symbols
 * @receiver Must be an owner scope of the callable symbol to work properly
 * @return A list of callable symbols which are directly overridden by the given symbol
 */


internal fun Configuration . declarable ( visible : Boolean = false , )

{ <EOL> isCanBeResolved = false <EOL> isCanBeConsumed = false <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> isCanBeDeclared = true <EOL> isVisible = visible <EOL> }

/**
 * Mark this [Configuration] as one that should be used to declare dependencies in
 * [org.gradle.api.Project.dependencies] block.
 *
 * Declarable Configurations should be extended by [resolvable] and [consumable] Configurations.
 * They must not have attributes.
 *
 * ```
 * isCanBeResolved = false
 * isCanBeConsumed = false
 * isCanBeDeclared = true
 * ```
 */


internal fun Configuration . consumable ( visible : Boolean = false , )

{ <EOL> isCanBeResolved = false <EOL> isCanBeConsumed = true <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> isCanBeDeclared = false <EOL> isVisible = visible <EOL> }

/**
 * Mark this [Configuration] as one that will be consumed by other subprojects.
 *
 * Consumable Configurations must extend a [declarable] Configuration.
 * They should have attributes.
 *
 * ```
 * isCanBeResolved = false
 * isCanBeConsumed = true
 * isCanBeDeclared = false
 * ```
 */


internal fun Configuration . resolvable ( visible : Boolean = false , )

{ <EOL> isCanBeResolved = true <EOL> isCanBeConsumed = false <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> isCanBeDeclared = false <EOL> isVisible = visible <EOL> }

/**
 * Mark this [Configuration] as one that will consume artifacts from other subprojects (also known as 'resolving')
 *
 * Resolvable Configurations should have attributes.
 *
 * ```
 * isCanBeResolved = true
 * isCanBeConsumed = false
 * isCanBeDeclared = false
 * ```
 */


public fun < T : Any > Publisher < T > . asFlow ( ) : Flow < T >

= <EOL> PublisherAsFlow ( this )

/**
 * Transforms the given reactive [Publisher] into [Flow].
 * Use the [buffer] operator on the resulting flow to specify the size of the back-pressure.
 * In effect, it specifies the value of the subscription's [request][Subscription.request].
 * The [default buffer capacity][Channel.BUFFERED] for a suspending channel is used by default.
 *
 * If any of the resulting flow transformations fails, the subscription is immediately cancelled and all the in-flight
 * elements are discarded.
 *
 * This function is integrated with `ReactorContext` from `kotlinx-coroutines-reactor` module,
 * see its documentation for additional details.
 */


@ JvmOverloads <EOL> public fun < T : Any > Flow < T > . asPublisher ( context : CoroutineContext = EmptyCoroutineContext ) : Publisher < T >

= <EOL> FlowAsPublisher ( this , Dispatchers . Unconfined + context )

/**
 * Transforms the given flow into a reactive specification compliant [Publisher].
 *
 * This function is integrated with `ReactorContext` from `kotlinx-coroutines-reactor` module,
 * see its documentation for additional details.
 *
 * An optional [context] can be specified to control the execution context of calls to the [Subscriber] methods.
 * A [CoroutineDispatcher] can be set to confine them to a specific thread; various [ThreadContextElement] can be set to
 * inject additional context into the caller thread. By default, the [Unconfined][Dispatchers.Unconfined] dispatcher
 * is used, so calls are performed from an arbitrary thread.
 */


public fun markNow ( ) : TimeMark

/**
 * Marks a point in time on this time source.
 *
 * The returned [TimeMark] instance encapsulates the captured time point and allows querying
 * the duration of time interval [elapsed][TimeMark.elapsedNow] from that point.
 */


public operator fun minus ( other : ValueTimeMark ) : Duration

= MonotonicTimeSource . differenceBetween ( this , other )

/**
 * Returns the duration elapsed between the [other] time mark obtained from the same [TimeSource.Monotonic] time source and `this` time mark.
 *
 * The returned duration can be infinite if the time marks are far away from each other and
 * the result doesn't fit into [Duration] type,
 * or if one time mark is infinitely distant, or if both `this` and [other] time marks
 * lie infinitely distant on the opposite sides of the time scale.
 *
 * Two infinitely distant time marks on the same side of the time scale are considered equal and
 * the duration between them is [Duration.ZERO].
 */


public operator fun compareTo ( other : ValueTimeMark ) : Int

= <EOL> ( this - other ) . compareTo ( Duration . ZERO )

/**
 * Compares this time mark with the [other] time mark for order.
 *
 * - Returns zero if this time mark represents *the same moment* of time as the [other] time mark.
 * - Returns a negative number if this time mark is *earlier* than the [other] time mark.
 * - Returns a positive number if this time mark is *later* than the [other] time mark.
 */


public abstract fun elapsedNow ( ) : Duration

/**
 * Returns the amount of time passed from this mark measured with the time source from which this mark was taken.
 *
 * Note that the value returned by this function can change on subsequent invocations.
 *
 * @throws IllegalArgumentException an implementation may throw if calculating the elapsed time involves
 * adding a positive infinite duration to an infinitely distant past time mark or
 * a negative infinite duration to an infinitely distant future time mark.
 */


public operator fun plus ( duration : Duration ) : TimeMark

= AdjustedTimeMark ( this , duration )

/**
 * Returns a time mark on the same time source that is ahead of this time mark by the specified [duration].
 *
 * The returned time mark is more _late_ when the [duration] is positive, and more _early_ when the [duration] is negative.
 *
 * If the time mark is adjusted too far in the past or in the future, it may saturate to an infinitely distant time mark.
 * In that case, [elapsedNow] will return an infinite duration elapsed from such infinitely distant mark.
 *
 * @throws IllegalArgumentException an implementation may throw if a positive infinite duration is added to an infinitely distant past time mark or
 * a negative infinite duration is added to an infinitely distant future time mark.
 */


public open operator fun minus ( duration : Duration ) : TimeMark

= plus ( - duration )

/**
 * Returns a time mark on the same time source that is behind this time mark by the specified [duration].
 *
 * The returned time mark is more _early_ when the [duration] is positive, and more _late_ when the [duration] is negative.
 *
 * If the time mark is adjusted too far in the past or in the future, it may saturate to an infinitely distant time mark.
 * In that case, [elapsedNow] will return an infinite duration elapsed from such infinitely distant mark.
 *
 * @throws IllegalArgumentException an implementation may throw if a positive infinite duration is subtracted from an infinitely distant future time mark or
 * a negative infinite duration is subtracted from an infinitely distant past time mark.
 */


= ! elapsedNow ( ) . isNegative ( )

/**
 * Returns true if this time mark has passed according to the time source from which this mark was taken.
 *
 * Note that the value returned by this function can change on subsequent invocations.
 * If the time source is monotonic, it can change only from `false` to `true`, namely, when the time mark becomes behind the current point of the time source.
 */


public fun hasNotPassedNow ( ) : Boolean

= elapsedNow ( ) . isNegative ( )

/**
 * Returns false if this time mark has not passed according to the time source from which this mark was taken.
 *
 * Note that the value returned by this function can change on subsequent invocations.
 * If the time source is monotonic, it can change only from `true` to `false`, namely, when the time mark becomes behind the current point of the time source.
 */


public operator fun minus ( other : ComparableTimeMark ) : Duration

/**
 * Returns the duration elapsed between the [other] time mark and `this` time mark.
 *
 * The returned duration can be infinite if the time marks are far away from each other and
 * the result doesn't fit into [Duration] type,
 * or if one time mark is infinitely distant, or if both `this` and [other] time marks
 * lie infinitely distant on the opposite sides of the time scale.
 *
 * Two infinitely distant time marks on the same side of the time scale are considered equal and
 * the duration between them is [Duration.ZERO].
 *
 * Note that the other time mark must be obtained from the same time source as this one.
 *
 * @throws IllegalArgumentException if time marks were obtained from different time sources.
 */


public override operator fun compareTo ( other : ComparableTimeMark ) : Int

/**
 * Compares this time mark with the [other] time mark for order.
 *
 * - Returns zero if this time mark represents *the same moment* of time as the [other] time mark.
 * - Returns a negative number if this time mark is *earlier* than the [other] time mark.
 * - Returns a positive number if this time mark is *later* than the [other] time mark.
 *
 * Note that the other time mark must be obtained from the same time source as this one.
 *
 * @throws IllegalArgumentException if time marks were obtained from different time sources.
 */


override fun equals ( other : Any ? ) : Boolean

/**
 * Returns `true` if two time marks from the same time source represent the same moment of time, and `false` otherwise,
 * including the situation when the time marks were obtained from different time sources.
 */


private fun compressSequencesWithoutLineNumber ( loggedItems : List < SteppingTestLoggedData > ) : List < SteppingTestLoggedData >

{ <EOL> if ( loggedItems . isEmpty ( ) ) return listOf ( ) <EOL> val logIterator = loggedItems . iterator ( ) <EOL> var currentItem = logIterator . next ( ) <EOL> val result = mutableListOf ( currentItem ) <EOL> for ( logItem in logIterator ) { <EOL> if ( currentItem . line != - <NUM_LIT:1> || currentItem . expectation != logItem . expectation ) { <EOL> result . add ( logItem ) <EOL> currentItem = logItem <EOL> } <EOL> } <EOL> return result <EOL> }

/**
 * Compresses sequences of the same location without line number in the log:
 * specifically removes locations without linenumber, that would otherwise
 * print as byte offsets. This avoids overspecifying code generation
 * strategy in debug tests.
 */


private fun areRuntimeOrCompileConfigurationsAvailable ( ) : Boolean

= <EOL> GradleVersion . version ( project . gradle . gradleVersion ) <= GradleVersion . version ( "<STR_LIT>" )

/**
 * Check if "compile" and "runtime" configurations are still available in current Gradle version.
 */


public fun < R > Dataset . map ( transform : ( FloatData ) -> R ) : List < R >

{ <EOL> return ( <NUM_LIT:0> until xSize ( ) ) . map { i -> transform ( getX ( i ) ) } <EOL> }

/**
 * Applies the given [transform] function to each element of the dataset and returns a list with results.
 */


public fun OnHeapDataset . partialToString ( ) : String

= buildStringRepr ( x . partialToString ( ) , y . partialToString ( ) )

/**
 * Creates [OnHeapDataset] string representation for part of data.
 */


public fun OnHeapDataset . fullToString ( ) : String

= buildStringRepr ( x . contentDeepToString ( ) , y . contentToString ( ) )

/**
 * Creates [OnHeapDataset] string representation for full of data.
 */


public fun OnHeapDataset . buildStringRepr ( xString : String , yString : String ) : String

= <EOL> "<STR_LIT>"

/**
 * Builds intermediate [OnHeapDataset] string representation.
 */


private fun FloatArray . partialToString ( maxSize : Int = <NUM_LIT:10> , lowPercent : Double = <NUM_LIT> ) : String

{ <EOL> if ( size <= maxSize ) { <EOL> return contentToString ( ) <EOL> } <EOL> val lowCount = ( lowPercent * maxSize ) . roundToInt ( ) <EOL> val upStart = size - maxSize - <NUM_LIT:1> <EOL> return generateSequence ( <NUM_LIT:0> , Int :: inc ) . map { <EOL> when { <EOL> it < lowCount -> this [ it ] <EOL> it > lowCount -> this [ upStart + it ] <EOL> else -> "<STR_LIT:...>" <EOL> } <EOL> } . take ( maxSize + <NUM_LIT:1> ) . joinToString ( prefix = "<STR_LIT:[>" , postfix = "<STR_LIT:]>" , separator = "<STR_LIT:U+002CU+0020>" ) <EOL> }

/**
 * Create String representation of `FloatArray` where only a part of the data is printed to String.
 *
 * @param [maxSize] max number of elements of an array present in its string representation
 * @param [lowPercent] percent of data of [maxSize] to be printed from the beginning of array data.
 * Rest will be obtained from the tail of the array in order matching the order in an array.
 *
 * @return string representation of [FloatArray] in format like
 * `[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, ..., 9.0, 10.0]`
 */


private fun Array < FloatArray > . partialToString ( maxSize : Int = <NUM_LIT:10> , lowPercent : Double = <NUM_LIT> ) : String

{ <EOL> if ( size <= maxSize ) { <EOL> return joinToString ( prefix = "<STR_LIT:[>" , postfix = "<STR_LIT:]>" , separator = "<STR_LIT>" ) { <EOL> it . partialToString ( maxSize , lowPercent ) <EOL> } <EOL> } <EOL> val lowCount = ( lowPercent * maxSize ) . roundToInt ( ) <EOL> val upStart = size - maxSize - <NUM_LIT:1> <EOL> return generateSequence ( <NUM_LIT:0> , Int :: inc ) . map { <EOL> when { <EOL> it < lowCount -> this [ it ] . partialToString ( maxSize , lowPercent ) <EOL> it > lowCount -> this [ upStart + it ] . partialToString ( maxSize , lowPercent ) <EOL> else -> "<STR_LIT:...>" <EOL> } <EOL> } . take ( maxSize + <NUM_LIT:1> ) . joinToString ( prefix = "<STR_LIT:[>" , postfix = "<STR_LIT:]>" , separator = "<STR_LIT>" ) <EOL> }


fun extractNativeCompilerClasspath ( taskOutput : String , toolName : NativeToolKind ) : List < String >

= <EOL> extractNativeToolSettings ( taskOutput , toolName , NativeToolSettingsKind . COMPILER_CLASSPATH ) . toList ( )

/**
 * Extracts classpath of given task's output
 *
 * @param taskOutput debug level output of the task
 * @param toolName compiler type
 *
 * @return list of dependencies in classpath
 */


fun extractNativeCompilerCommandLineArguments ( taskOutput : String , toolName : NativeToolKind ) : List < String >

= <EOL> extractNativeToolSettings ( taskOutput , toolName , NativeToolSettingsKind . COMMAND_LINE_ARGUMENTS ) . toList ( )

/**
 * Extracts command line arguments of given task's output
 *
 * @param taskOutput debug level output of the task
 * @param toolName compiler type
 *
 * @return list of command line arguments
 */


@ kotlin . internal . InlineOnly <EOL> public actual inline fun CharSequence . elementAt ( index : Int ) : Char

{ <EOL> return get ( index ) <EOL> }

/**
 * Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this char sequence.
 *
 * @sample samples.collections.Collections.Elements.elementAt
 */


public fun CharSequence . toSortedSet ( ) : java . util . SortedSet < Char >

{ <EOL> return toCollection ( java . util . TreeSet < Char > ( ) ) <EOL> }

/**
 * Returns a new [SortedSet][java.util.SortedSet] of all characters.
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ OptIn ( kotlin . experimental . ExperimentalTypeInference :: class ) <EOL> @ OverloadResolutionByLambdaReturnType <EOL> @ kotlin . jvm . JvmName ( "<STR_LIT>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun CharSequence . sumOf ( selector : ( Char ) -> java . math . BigDecimal ) : java . math . BigDecimal

{ <EOL> var sum : java . math . BigDecimal = <NUM_LIT:0> . toBigDecimal ( ) <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }

/**
 * Returns the sum of all values produced by [selector] function applied to each character in the char sequence.
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ OptIn ( kotlin . experimental . ExperimentalTypeInference :: class ) <EOL> @ OverloadResolutionByLambdaReturnType <EOL> @ kotlin . jvm . JvmName ( "<STR_LIT>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun CharSequence . sumOf ( selector : ( Char ) -> java . math . BigInteger ) : java . math . BigInteger

{ <EOL> var sum : java . math . BigInteger = <NUM_LIT:0> . toBigInteger ( ) <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }


fun setExecutionSourceFrom ( testExecutable : TestExecutable )

/**
 * Sets this test run to use the specified [testExecutable].
 *
 * This overrides other [executionSource] options.
 */


{ <EOL> runImageRecognitionPrediction ( modelType = TFModels . CV . MobileNet ( ) ) <EOL> }

/**
 * This example demonstrates the inference concept on MobileNet model:
 * - Model configuration, model weights and labels are obtained from [TFModelHub].
 * - Weights are loaded from .h5 file, configuration is loaded from .json file.
 * - Model predicts on a few images located in resources.
 * - Special preprocessing (used in MobileNet during training on ImageNet dataset) is applied to the images before prediction.
 */


= mobileNetPrediction ( )


override fun testCaseWithInvocation ( invocation : NSInvocation ? ) : XCTestCase

{ <EOL> error ( """<STR_LIT>""" . trimIndent ( ) ) <EOL> }

/**
 * This method is invoked by the XCTest when it discovered XCTestCase instance
 * that contains test method.
 *
 * This method should not be called with the current idea and assumptions.
 */


private fun createRunMethod ( selector : SEL )

{ <EOL> val result = class_addMethod ( cls = this . `class` ( ) , name = selector , imp = imp_implementationWithBlock ( this :: runner ) , types = "<STR_LIT>" ) <EOL> check ( result ) { <EOL> "<STR_LIT>" <EOL> } <EOL> }

/**
 * Creates and adds method to the metaclass with implementation block
 * that gets an XCTestCase instance as self to be run.
 */


override fun testInvocations ( ) : List < NSInvocation >

= testMethodsNames . map { <EOL> val selector = NSSelectorFromString ( it ) <EOL> createRunMethod ( selector ) <EOL> this . instanceMethodSignatureForSelector ( selector ) ? . let { signature -> <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> val invocation = NSInvocation . invocationWithMethodSignature ( signature as NSMethodSignature ) <EOL> invocation . setSelector ( selector ) <EOL> invocation <EOL> } ? : error ( "<STR_LIT>" ) <EOL> }

/**
 * Creates Test invocations for each test method to make them resolvable by the XCTest machinery.
 *
 * For each kotlin-test's test case make an NSInvocation with an appropriate selector that represents test name:
 * - Create NSSelector from the given test name.
 * - Create implementation method with block for runner method. This method accepts the instance of the XCTestCaseWrapper
 * to run the actual test code.
 * - Create NSInvocation from the selector using NSMethodSignature.
 *
 * Then this NSInvocation should be used to create an instance of XCTestCaseWrapper that implements XCTestCase.
 * When XCTest runs this instance, it invokes this invocation that passes Wrapper's instance to the `runner(...)` method.
 *
 * @see createRunMethod
 * @see runner
 * @see XCTestCaseWrapper.run
 */