private fun getFunctionTypeForSamType ( samType : SimpleType , samResolver : SamConversionResolver , samConversionOracle : SamConversionOracle ) : SimpleType ?

{ <EOL> val classifier = samType . constructor . declarationDescriptor <EOL> if ( classifier !is ClassDescriptor ) return null <EOL> if ( ! samConversionOracle . isPossibleSamType ( samType ) ) return null <EOL> val functionTypeDefault = samResolver . resolveFunctionTypeIfSamInterface ( classifier ) ? : return null <EOL> val noProjectionsSamType = nonProjectionParametrization ( samType ) ? : return null <EOL> val type = TypeSubstitutor . create ( noProjectionsSamType ) . substitute ( functionTypeDefault , Variance . IN_VARIANCE ) <EOL> assert ( type != null ) { <EOL> "<STR_LIT>" <EOL> } <EOL> val simpleType = type ! ! . asSimpleType ( ) <EOL> return simpleType . makeNullableAsSpecified ( samType . isMarkedNullable ) <EOL> }


fun nonProjectionParametrization ( samType : SimpleType ) : SimpleType ?

{ <EOL> if ( samType . arguments . none { it . projectionKind != Variance . INVARIANT } ) return samType <EOL> val parameters = samType . constructor . parameters <EOL> val parametersSet = parameters . toSet ( ) <EOL> return samType . replace ( newArguments = samType . arguments . zip ( parameters ) . map { <EOL> val ( projection , parameter ) = it <EOL> when { <EOL> projection . projectionKind == Variance . INVARIANT -> projection <EOL> projection . isStarProjection -> <EOL> parameter . upperBounds . first ( ) . takeUnless { t -> <EOL> t . contains { it . constructor . declarationDescriptor in parametersSet } <EOL> } ? . asTypeProjection ( ) ? : return@nonProjectionParametrization null <EOL> else -> projection . type . asTypeProjection ( ) <EOL> } <EOL> } ) <EOL> }


= "<STR_LIT>"


{ <EOL> val sum = Sign . plus . func ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> if ( sum != <NUM_LIT:5> ) return "<STR_LIT>" <EOL> val product = Sign . mult . toString ( ) <EOL> if ( product != "<STR_LIT>" ) return "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


fun PropertyAccessorDescriptor . hasBody ( ) : Boolean

{ <EOL> val ktAccessor = DescriptorToSourceUtils . getSourceFromDescriptor ( this ) as? KtDeclarationWithBody <EOL> return ktAccessor != null && ktAccessor . hasBody ( ) <EOL> }


fun isBackingFieldReference ( descriptor : DeclarationDescriptor ? ) : Boolean

{ <EOL> return descriptor is SyntheticFieldDescriptor <EOL> }


{ <EOL> val f0 = :: fn0 as Any <EOL> val f1 = :: fn1 as Any <EOL> val ef = Any :: extFun as Any <EOL> val afoo = A :: foo <EOL> fun local0 ( ) { } <EOL> fun local1 ( x : Any ) { } <EOL> val localFun0 = :: local0 as Any <EOL> val localFun1 = :: local1 as Any <EOL> if ( f0 !is Function0 < * > ) return "<STR_LIT>" <EOL> if ( f1 !is Function1 < * , * > ) return "<STR_LIT>" <EOL> if ( lambda0 !is Function0 < * > ) return "<STR_LIT>" <EOL> if ( lambda1 !is Function1 < * , * > ) return "<STR_LIT>" <EOL> if ( localFun0 !is Function0 < * > ) return "<STR_LIT>" <EOL> if ( localFun1 !is Function1 < * , * > ) return "<STR_LIT>" <EOL> if ( ef !is Function1 < * , * > ) return "<STR_LIT>" <EOL> if ( afoo !is Function1 < * , * > ) return "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> test ( <NUM_LIT:4> . foo ) <EOL> test ( foo ) <EOL> }


fun calculateResult ( context : Context ? )

{ <EOL> context ! ! <EOL> val project = context . project ! ! <EOL> }


fun functionStarted ( )


fun functionEnded ( tokenStream : TokenStream )


fun resolvePackageHeader ( packageDirective : KtPackageDirective , module : ModuleDescriptor , trace : BindingTrace )

{ <EOL> val packageNames = packageDirective . packageNames <EOL> for ( ( index , nameExpression ) in packageNames . withIndex ( ) ) { <EOL> storeResult ( trace , nameExpression , module . getPackage ( packageDirective . getFqName ( nameExpression ) ) , shouldBeVisibleFrom = null , position = QualifierPosition . PACKAGE_HEADER , isQualifier = index != packageNames . lastIndex ) <EOL> } <EOL> }


fun LexicalScope . findClassifierAndReportDeprecationIfNeeded ( name : Name , lookupLocation : KotlinLookupLocation , reportOn : KtExpression ? , trace : BindingTrace ) : ClassifierDescriptor ?

{ <EOL> val ( classifier , isDeprecated ) = findFirstClassifierWithDeprecationStatus ( name , lookupLocation ) ? : return null <EOL> if ( isDeprecated && reportOn != null ) { <EOL> trace . record ( BindingContext . DEPRECATED_SHORT_NAME_ACCESS , reportOn ) <EOL> if ( ! classifier . canBeResolvedWithoutDeprecation ( this , lookupLocation ) ) { <EOL> trace . report ( Errors . DEPRECATED_ACCESS_BY_SHORT_NAME . on ( reportOn , classifier ) ) <EOL> } <EOL> } <EOL> return classifier <EOL> }


fun resolveDescriptorForType ( userType : KtUserType , scope : LexicalScope , trace : BindingTrace , isDebuggerContext : Boolean ) : TypeQualifierResolutionResult

{ <EOL> val ownerDescriptor = if ( ! isDebuggerContext ) scope . ownerDescriptor else null <EOL> if ( userType . qualifier == null ) { <EOL> val descriptor = userType . referenceExpression ? . let { expression -> <EOL> val classifier = scope . findClassifierAndReportDeprecationIfNeeded ( expression . getReferencedNameAsName ( ) , KotlinLookupLocation ( expression ) , expression , trace ) <EOL> checkNotEnumEntry ( classifier , trace , expression ) <EOL> storeResult ( trace , expression , classifier , ownerDescriptor , position = QualifierPosition . TYPE , isQualifier = false ) <EOL> classifier <EOL> } <EOL> return TypeQualifierResolutionResult ( userType . asQualifierPartList ( ) . first , descriptor ) <EOL> } <EOL> val ( qualifierPartList , hasError ) = userType . asQualifierPartList ( ) <EOL> if ( hasError ) { <EOL> val descriptor = resolveToPackageOrClass ( qualifierPartList , scope . ownerDescriptor . module , trace , ownerDescriptor , scope , position = QualifierPosition . TYPE ) as? ClassifierDescriptor <EOL> return TypeQualifierResolutionResult ( qualifierPartList , descriptor ) <EOL> } <EOL> return resolveQualifierPartListForType ( qualifierPartList , ownerDescriptor , scope , trace , isQualifier = false ) <EOL> }


private fun resolveQualifierPartListForType ( qualifierPartList : List < ExpressionQualifierPart > , ownerDescriptor : DeclarationDescriptor ? , scope : LexicalScope , trace : BindingTrace , isQualifier : Boolean ) : TypeQualifierResolutionResult

{ <EOL> assert ( qualifierPartList . isNotEmpty ( ) ) { "<STR_LIT>" } <EOL> val qualifier = resolveToPackageOrClass ( qualifierPartList . subList ( <NUM_LIT:0> , qualifierPartList . size - <NUM_LIT:1> ) , scope . ownerDescriptor . module , trace , ownerDescriptor , scope , position = QualifierPosition . TYPE ) ? : return TypeQualifierResolutionResult ( qualifierPartList , null ) <EOL> val lastPart = qualifierPartList . last ( ) <EOL> val classifier = when ( qualifier ) { <EOL> is PackageViewDescriptor -> qualifier . memberScope . getContributedClassifier ( lastPart . name , lastPart . location ) <EOL> is ClassDescriptor -> { <EOL> val descriptor = qualifier . unsubstitutedInnerClassesScope . getContributedClassifier ( lastPart . name , lastPart . location ) <EOL> checkNotEnumEntry ( descriptor , trace , lastPart . expression ) <EOL> descriptor <EOL> } <EOL> else -> null <EOL> } <EOL> storeResult ( trace , lastPart . expression , classifier , ownerDescriptor , position = QualifierPosition . TYPE , isQualifier = isQualifier ) <EOL> return TypeQualifierResolutionResult ( qualifierPartList , classifier ) <EOL> }


private fun checkNotEnumEntry ( descriptor : DeclarationDescriptor ? , trace : BindingTrace , expression : KtSimpleNameExpression ? )

{ <EOL> expression ? : return <EOL> if ( descriptor != null && DescriptorUtils . isEnumEntry ( descriptor ) ) { <EOL> val qualifiedParent = expression . getTopmostParentQualifiedExpressionForSelector ( ) <EOL> if ( qualifiedParent == null || qualifiedParent . parent !is KtDoubleColonExpression ) { <EOL> trace . report ( Errors . ENUM_ENTRY_AS_TYPE . on ( expression ) ) <EOL> } <EOL> } <EOL> }


fun resolveDescriptorForDoubleColonLHS ( expression : KtExpression , scope : LexicalScope , trace : BindingTrace , isDebuggerContext : Boolean ) : TypeQualifierResolutionResult

{ <EOL> val ownerDescriptor = if ( ! isDebuggerContext ) scope . ownerDescriptor else null <EOL> val qualifierPartList = expression . asQualifierPartList ( doubleColonLHS = true ) <EOL> if ( qualifierPartList . isEmpty ( ) ) { <EOL> return TypeQualifierResolutionResult ( qualifierPartList , null ) <EOL> } <EOL> if ( qualifierPartList . size == <NUM_LIT:1> ) { <EOL> val ( name , simpleNameExpression ) = qualifierPartList . single ( ) <EOL> val descriptor = scope . findClassifierAndReportDeprecationIfNeeded ( name , KotlinLookupLocation ( simpleNameExpression ) , simpleNameExpression , trace ) <EOL> storeResult ( trace , simpleNameExpression , descriptor , ownerDescriptor , position = QualifierPosition . TYPE , isQualifier = true ) <EOL> return TypeQualifierResolutionResult ( qualifierPartList , descriptor ) <EOL> } <EOL> return resolveQualifierPartListForType ( qualifierPartList , ownerDescriptor , scope , trace , isQualifier = true ) <EOL> }


private fun KtUserType . asQualifierPartList ( ) : Pair < List < ExpressionQualifierPart > , Boolean >

{ <EOL> var hasError = false <EOL> val result = SmartList < ExpressionQualifierPart > ( ) <EOL> var userType : KtUserType ? = this <EOL> while ( userType != null ) { <EOL> val referenceExpression = userType . referenceExpression <EOL> if ( referenceExpression != null ) { <EOL> result . add ( ExpressionQualifierPart ( referenceExpression . getReferencedNameAsName ( ) , referenceExpression , userType . typeArgumentList ) ) <EOL> } else { <EOL> hasError = true <EOL> } <EOL> userType = userType . qualifier <EOL> } <EOL> return result . asReversed ( ) to hasError <EOL> }


fun processImportReference ( importDirective : KtImportInfo , moduleDescriptor : ModuleDescriptor , trace : BindingTrace , excludedImportNames : Collection < FqName > , packageFragmentForVisibilityCheck : PackageFragmentDescriptor ? <EOL> ) : ImportingScope ?

{ <EOL> fun processReferenceInContextOf ( moduleDescriptor : ModuleDescriptor ) : ImportingScope ? = <EOL> doProcessImportReference ( importDirective , moduleDescriptor , trace , excludedImportNames , packageFragmentForVisibilityCheck ) <EOL> val primaryImportingScope = processReferenceInContextOf ( moduleDescriptor ) <EOL> if ( ! languageVersionSettings . isLibraryToSourceAnalysisEnabled ) return primaryImportingScope <EOL> val resolutionAnchor = moduleDescriptor . getResolutionAnchorIfAny ( ) ? : return primaryImportingScope <EOL> val anchorImportingScope = processReferenceInContextOf ( resolutionAnchor ) ? : return primaryImportingScope <EOL> if ( primaryImportingScope == null ) return anchorImportingScope <EOL> return CompositePrioritizedImportingScope ( anchorImportingScope , primaryImportingScope ) <EOL> }


private fun doProcessImportReference ( importDirective : KtImportInfo , moduleDescriptor : ModuleDescriptor , trace : BindingTrace , excludedImportNames : Collection < FqName > , packageFragmentForVisibilityCheck : PackageFragmentDescriptor ? <EOL> ) : ImportingScope ?

{ <EOL> ProgressIndicatorAndCompilationCanceledStatus . checkCanceled ( ) <EOL> val importedReference = importDirective . importContent ? : return null <EOL> val path = importedReference . asQualifierPartList ( ) <EOL> val lastPart = path . lastOrNull ( ) ? : return null <EOL> val packageFragmentForCheck = <EOL> if ( importDirective is KtImportDirective ) <EOL> computePackageFragmentToCheck ( importDirective . containingKtFile , packageFragmentForVisibilityCheck ) <EOL> else <EOL> null <EOL> if ( importDirective . isAllUnder ) { <EOL> val packageOrClassDescriptor = resolveToPackageOrClass ( path , moduleDescriptor , trace , packageFragmentForCheck , scopeForFirstPart = null , position = QualifierPosition . IMPORT ) . classDescriptorFromTypeAlias ( ) ? : return null <EOL> if ( packageOrClassDescriptor is ClassDescriptor && packageOrClassDescriptor . kind . isSingleton && lastPart . expression != null ) { <EOL> trace . report ( Errors . CANNOT_ALL_UNDER_IMPORT_FROM_SINGLETON . on ( lastPart . expression ! ! , packageOrClassDescriptor ) ) <EOL> return null <EOL> } <EOL> return AllUnderImportScope . create ( packageOrClassDescriptor , excludedImportNames ) <EOL> } else { <EOL> return processSingleImport ( moduleDescriptor , trace , importDirective , path , lastPart , packageFragmentForCheck ) <EOL> } <EOL> }


private fun DeclarationDescriptor ? . classDescriptorFromTypeAlias ( ) : DeclarationDescriptor ?

{ <EOL> return if ( this is TypeAliasDescriptor ) classDescriptor else this <EOL> }


private fun computePackageFragmentToCheck ( containingFile : KtFile , packageFragmentForVisibilityCheck : PackageFragmentDescriptor ? <EOL> ) : PackageFragmentDescriptor ?

= <EOL> when { <EOL> containingFile . suppressDiagnosticsInDebugMode ( ) -> null <EOL> packageFragmentForVisibilityCheck is DeclarationDescriptorWithSource && <EOL> packageFragmentForVisibilityCheck . source == SourceElement . NO_SOURCE -> { <EOL> PackageFragmentWithCustomSource ( packageFragmentForVisibilityCheck , KotlinSourceElement ( containingFile ) ) <EOL> } <EOL> else -> packageFragmentForVisibilityCheck <EOL> }


private fun processSingleImport ( moduleDescriptor : ModuleDescriptor , trace : BindingTrace , importDirective : KtImportInfo , path : List < QualifierPart > , lastPart : QualifierPart , packageFragmentForVisibilityCheck : PackageFragmentDescriptor ? <EOL> ) : ImportingScope ?

{ <EOL> val aliasName = importDirective . importedName <EOL> if ( aliasName == null ) { <EOL> resolveToPackageOrClass ( path , moduleDescriptor , trace , packageFragmentForVisibilityCheck , scopeForFirstPart = null , position = QualifierPosition . IMPORT ) <EOL> return null <EOL> } <EOL> val resolvedDescriptor = resolveToPackageOrClass ( path . subList ( <NUM_LIT:0> , path . size - <NUM_LIT:1> ) , moduleDescriptor , trace , packageFragmentForVisibilityCheck , scopeForFirstPart = null , position = QualifierPosition . IMPORT ) ? : return null <EOL> val packageOrClassDescriptor = <EOL> ( resolvedDescriptor as? TypeAliasDescriptor ) ? . let { it . classDescriptor ? : return null } ? : resolvedDescriptor <EOL> return LazyExplicitImportScope ( languageVersionSettings , packageOrClassDescriptor , packageFragmentForVisibilityCheck , lastPart . name , aliasName , CallOnceFunction ( Unit ) { candidates -> <EOL> if ( candidates . isNotEmpty ( ) ) { <EOL> storeResult ( trace , lastPart . expression , candidates , packageFragmentForVisibilityCheck , position = QualifierPosition . IMPORT , isQualifier = false ) <EOL> } else { <EOL> tryResolveDescriptorsWhichCannotBeImported ( trace , moduleDescriptor , packageOrClassDescriptor , lastPart ) <EOL> } <EOL> } ) <EOL> }


private fun tryResolveDescriptorsWhichCannotBeImported ( trace : BindingTrace , moduleDescriptor : ModuleDescriptor , packageOrClassDescriptor : DeclarationDescriptor , lastPart : QualifierPart )

{ <EOL> val lastPartExpression = lastPart . expression ? : return <EOL> val descriptors = SmartList < DeclarationDescriptor > ( ) <EOL> val lastName = lastPart . name <EOL> when ( packageOrClassDescriptor ) { <EOL> is PackageViewDescriptor -> { <EOL> val packageDescriptor = moduleDescriptor . getPackage ( packageOrClassDescriptor . fqName . child ( lastName ) ) <EOL> if ( ! packageDescriptor . isEmpty ( ) ) { <EOL> trace . report ( Errors . PACKAGE_CANNOT_BE_IMPORTED . on ( lastPartExpression ) ) <EOL> descriptors . add ( packageOrClassDescriptor ) <EOL> } <EOL> } <EOL> is ClassDescriptor -> { <EOL> val memberScope = packageOrClassDescriptor . unsubstitutedMemberScope <EOL> descriptors . addAll ( memberScope . getContributedFunctions ( lastName , lastPart . location ) ) <EOL> descriptors . addAll ( memberScope . getContributedVariables ( lastName , lastPart . location ) ) <EOL> if ( descriptors . isNotEmpty ( ) ) { <EOL> trace . report ( Errors . CANNOT_BE_IMPORTED . on ( lastPartExpression , lastName ) ) <EOL> } <EOL> } <EOL> else -> throw IllegalStateException ( "<STR_LIT>" ) <EOL> } <EOL> storeResult ( trace , lastPart . expression , descriptors , shouldBeVisibleFrom = null , position = QualifierPosition . IMPORT , isQualifier = false ) <EOL> }


private fun KtImportInfo . ImportContent . asQualifierPartList ( ) : List < QualifierPart >

= <EOL> when ( this ) { <EOL> is KtImportInfo . ImportContent . ExpressionBased -> expression . asQualifierPartList ( ) <EOL> is KtImportInfo . ImportContent . FqNameBased -> fqName . pathSegments ( ) . map { QualifierPart ( it ) } <EOL> }


private fun KtExpression . asQualifierPartList ( doubleColonLHS : Boolean = false ) : List < ExpressionQualifierPart >

{ <EOL> val result = SmartList < ExpressionQualifierPart > ( ) <EOL> fun addQualifierPart ( expression : KtExpression ? ) : Boolean { <EOL> if ( expression is KtSimpleNameExpression ) { <EOL> result . add ( ExpressionQualifierPart ( expression ) ) <EOL> return true <EOL> } <EOL> if ( doubleColonLHS && expression is KtCallExpression && expression . isWithoutValueArguments ) { <EOL> val simpleName = expression . calleeExpression <EOL> if ( simpleName is KtSimpleNameExpression ) { <EOL> result . add ( ExpressionQualifierPart ( simpleName . getReferencedNameAsName ( ) , simpleName , expression . typeArgumentList ) ) <EOL> return true <EOL> } <EOL> } <EOL> return false <EOL> } <EOL> var expression : KtExpression ? = this <EOL> while ( true ) { <EOL> if ( addQualifierPart ( expression ) ) break <EOL> if ( expression !is KtQualifiedExpression ) break <EOL> addQualifierPart ( expression . selectorExpression ) <EOL> expression = expression . receiverExpression <EOL> } <EOL> return result . asReversed ( ) <EOL> }


= name


= expression


= typeArguments


private fun resolveToPackageOrClass ( path : List < QualifierPart > , moduleDescriptor : ModuleDescriptor , trace : BindingTrace , shouldBeVisibleFrom : DeclarationDescriptor ? , scopeForFirstPart : LexicalScope ? , position : QualifierPosition ) : DeclarationDescriptor ?

{ <EOL> val ( packageOrClassDescriptor , endIndex ) = <EOL> resolveToPackageOrClassPrefix ( path , moduleDescriptor , trace , shouldBeVisibleFrom , scopeForFirstPart , position ) <EOL> if ( endIndex != path . size ) { <EOL> return null <EOL> } <EOL> return packageOrClassDescriptor <EOL> }


private fun resolveInIDEMode ( path : List < QualifierPart > ) : Boolean

= <EOL> languageVersionSettings . getFlag ( AnalysisFlags . ideMode ) && path . size > <NUM_LIT:1> && path . first ( ) . name . asString ( ) == ROOT_PREFIX_FOR_IDE_RESOLUTION_MODE


private fun resolveToPackageOrClassPrefix ( path : List < QualifierPart > , moduleDescriptor : ModuleDescriptor , trace : BindingTrace , shouldBeVisibleFrom : DeclarationDescriptor ? , scopeForFirstPart : LexicalScope ? , position : QualifierPosition , isValue : ( ( KtSimpleNameExpression ) -> Boolean ) ? = null ) : Pair < DeclarationDescriptor ? , Int >

{ <EOL> if ( resolveInIDEMode ( path ) ) { <EOL> return resolveToPackageOrClassPrefix ( path . subList ( <NUM_LIT:1> , path . size ) , moduleDescriptor , trace , shouldBeVisibleFrom , scopeForFirstPart = null , position = position , isValue = null ) . let { it . first to it . second + <NUM_LIT:1> } <EOL> } <EOL> if ( path . isEmpty ( ) ) { <EOL> return Pair ( moduleDescriptor . getPackage ( FqName . ROOT ) , <NUM_LIT:0> ) <EOL> } <EOL> val firstPart = path . first ( ) <EOL> if ( position == QualifierPosition . EXPRESSION ) { <EOL> if ( scopeForFirstPart != null && isValue != null && firstPart . expression != null && isValue ( firstPart . expression ! ! ) ) { <EOL> return Pair ( null , <NUM_LIT:0> ) <EOL> } <EOL> } <EOL> val classifierDescriptor = scopeForFirstPart ? . findClassifier ( firstPart . name , firstPart . location ) <EOL> if ( classifierDescriptor != null ) { <EOL> storeResult ( trace , firstPart . expression , classifierDescriptor , shouldBeVisibleFrom , position ) <EOL> } <EOL> val ( prefixDescriptor , nextIndexAfterPrefix ) = <EOL> if ( classifierDescriptor != null ) <EOL> Pair ( classifierDescriptor , <NUM_LIT:1> ) <EOL> else <EOL> moduleDescriptor . quickResolveToPackage ( path , trace , position ) <EOL> var currentDescriptor : DeclarationDescriptor ? = prefixDescriptor <EOL> for ( qualifierPartIndex in nextIndexAfterPrefix until path . size ) { <EOL> val qualifierPart = path [ qualifierPartIndex ] <EOL> val nextPackageOrClassDescriptor = <EOL> when ( currentDescriptor ) { <EOL> is TypeAliasDescriptor -> <EOL> null <EOL> is ClassDescriptor -> <EOL> currentDescriptor . getContributedClassifier ( qualifierPart ) <EOL> is PackageViewDescriptor -> { <EOL> val packageView = <EOL> if ( qualifierPart . typeArguments == null ) { <EOL> moduleDescriptor . getPackage ( currentDescriptor . fqName . child ( qualifierPart . name ) ) <EOL> } else null <EOL> if ( packageView != null && ! packageView . isEmpty ( ) ) { <EOL> packageView <EOL> } else { <EOL> currentDescriptor . memberScope . getContributedClassifier ( qualifierPart . name , qualifierPart . location ) <EOL> } <EOL> } <EOL> else -> <EOL> null <EOL> } <EOL> if ( ! ( position == QualifierPosition . EXPRESSION && nextPackageOrClassDescriptor == null ) ) { <EOL> storeResult ( trace , qualifierPart . expression , nextPackageOrClassDescriptor , shouldBeVisibleFrom , position ) <EOL> } <EOL> if ( nextPackageOrClassDescriptor == null ) { <EOL> return Pair ( currentDescriptor , qualifierPartIndex ) <EOL> } <EOL> currentDescriptor = nextPackageOrClassDescriptor <EOL> } <EOL> return Pair ( currentDescriptor , path . size ) <EOL> }


fun ClassDescriptor . getContributedClassifier ( qualifierPart : QualifierPart )

= <EOL> unsubstitutedInnerClassesScope . getContributedClassifier ( qualifierPart . name , qualifierPart . location )


fun resolveNameExpressionAsQualifierForDiagnostics ( expression : KtSimpleNameExpression , receiver : Receiver ? , context : ExpressionTypingContext ) : Qualifier ?

{ <EOL> val name = expression . getReferencedNameAsName ( ) <EOL> if ( ! expression . isPhysical && ! name . isSpecial && name . asString ( ) . endsWith ( CompletionUtilCore . DUMMY_IDENTIFIER_TRIMMED ) ) { <EOL> return null <EOL> } <EOL> val location = KotlinLookupLocation ( expression ) <EOL> val qualifierDescriptor = when ( receiver ) { <EOL> is PackageQualifier -> { <EOL> val childPackageFQN = receiver . descriptor . fqName . child ( name ) <EOL> receiver . descriptor . module . getPackage ( childPackageFQN ) . takeUnless { it . isEmpty ( ) } <EOL> ? : receiver . descriptor . memberScope . getContributedClassifier ( name , location ) <EOL> } <EOL> is ClassQualifier -> receiver . staticScope . getContributedClassifier ( name , location ) <EOL> null -> context . scope . findClassifier ( name , location ) <EOL> ? : context . scope . ownerDescriptor . module . getPackage ( FqName . ROOT . child ( name ) ) . takeUnless { it . isEmpty ( ) } <EOL> is ReceiverValue -> receiver . type . memberScope . memberScopeAsImportingScope ( ) . findClassifier ( name , location ) <EOL> else -> null <EOL> } <EOL> if ( qualifierDescriptor != null ) { <EOL> return storeResult ( context . trace , expression , qualifierDescriptor , context . scope . ownerDescriptor , QualifierPosition . EXPRESSION ) <EOL> } <EOL> return null <EOL> }


fun resolveClassOrPackageInQualifiedExpression ( expression : KtQualifiedExpression , scope : LexicalScope , context : BindingContext ) : QualifiedExpressionResolveResult

{ <EOL> val qualifiedExpressions = unrollToLeftMostQualifiedExpression ( expression ) <EOL> val path = mapToQualifierParts ( qualifiedExpressions , <NUM_LIT:0> ) <EOL> val trace = DelegatingBindingTrace ( context , "<STR_LIT>" ) <EOL> val ( result , index ) = resolveToPackageOrClassPrefix ( path = path , moduleDescriptor = scope . ownerDescriptor . module , trace = trace , shouldBeVisibleFrom = scope . ownerDescriptor , scopeForFirstPart = scope , position = QualifierPosition . EXPRESSION ) <EOL> if ( result == null ) return QualifiedExpressionResolveResult . UNRESOLVED <EOL> return when ( index ) { <EOL> path . size -> QualifiedExpressionResolveResult ( result , null ) <EOL> path . size - <NUM_LIT:1> -> QualifiedExpressionResolveResult ( result , path [ index ] . name ) <EOL> else -> QualifiedExpressionResolveResult . UNRESOLVED <EOL> } <EOL> }


fun resolveQualifierInExpressionAndUnroll ( expression : KtQualifiedExpression , context : ExpressionTypingContext , isValue : ( KtSimpleNameExpression ) -> Boolean ) : List < CallExpressionElement >

{ <EOL> val qualifiedExpressions = unrollToLeftMostQualifiedExpression ( expression ) <EOL> val maxPossibleQualifierPrefix = mapToQualifierParts ( qualifiedExpressions , <NUM_LIT:1> ) <EOL> val nextIndexAfterPrefix = resolveToPackageOrClassPrefix ( path = maxPossibleQualifierPrefix , moduleDescriptor = context . scope . ownerDescriptor . module , trace = context . trace , shouldBeVisibleFrom = context . scope . ownerDescriptor , scopeForFirstPart = context . scope , position = QualifierPosition . EXPRESSION , isValue = isValue ) . second <EOL> val nextExpressionIndexAfterQualifier = <EOL> if ( nextIndexAfterPrefix == <NUM_LIT:0> ) <NUM_LIT:0> else nextIndexAfterPrefix - <NUM_LIT:1> <EOL> return qualifiedExpressions <EOL> . subList ( nextExpressionIndexAfterQualifier , qualifiedExpressions . size ) <EOL> . map ( :: CallExpressionElement ) <EOL> }


private fun mapToQualifierParts ( qualifiedExpressions : List < KtQualifiedExpression > , skipLast : Int ) : List < QualifierPart >

{ <EOL> if ( qualifiedExpressions . isEmpty ( ) ) return emptyList ( ) <EOL> val first = qualifiedExpressions . first ( ) <EOL> if ( first !is KtDotQualifiedExpression ) return emptyList ( ) <EOL> val firstReceiver = first . receiverExpression <EOL> if ( firstReceiver !is KtSimpleNameExpression ) return emptyList ( ) <EOL> val qualifierParts = arrayListOf < QualifierPart > ( ) <EOL> qualifierParts . add ( ExpressionQualifierPart ( firstReceiver ) ) <EOL> for ( qualifiedExpression in qualifiedExpressions . dropLast ( skipLast ) ) { <EOL> if ( qualifiedExpression !is KtDotQualifiedExpression ) break <EOL> val selector = qualifiedExpression . selectorExpression <EOL> if ( selector !is KtSimpleNameExpression ) break <EOL> qualifierParts . add ( ExpressionQualifierPart ( selector ) ) <EOL> } <EOL> return qualifierParts <EOL> }


private fun ModuleDescriptor . quickResolveToPackage ( path : List < QualifierPart > , trace : BindingTrace , position : QualifierPosition ) : Pair < PackageViewDescriptor , Int >

{ <EOL> val possiblePackagePrefixSize = path . indexOfFirst { it . typeArguments != null } . let { if ( it == - <NUM_LIT:1> ) path . size else it + <NUM_LIT:1> } <EOL> var fqName = FqName . fromSegments ( path . subList ( <NUM_LIT:0> , possiblePackagePrefixSize ) . map { it . name . asString ( ) } ) <EOL> var prefixSize = possiblePackagePrefixSize <EOL> while ( ! fqName . isRoot ) { <EOL> val packageDescriptor = getPackage ( fqName ) <EOL> if ( ! packageDescriptor . isEmpty ( ) ) { <EOL> recordPackageViews ( path . subList ( <NUM_LIT:0> , prefixSize ) , packageDescriptor , trace , position ) <EOL> return Pair ( packageDescriptor , prefixSize ) <EOL> } <EOL> fqName = fqName . parent ( ) <EOL> prefixSize -- <EOL> } <EOL> return Pair ( getPackage ( FqName . ROOT ) , <NUM_LIT:0> ) <EOL> }


private fun recordPackageViews ( path : List < QualifierPart > , packageView : PackageViewDescriptor , trace : BindingTrace , position : QualifierPosition )

{ <EOL> path . foldRight ( packageView ) { qualifierPart , currentView -> <EOL> storeResult ( trace , qualifierPart . expression , currentView , shouldBeVisibleFrom = null , position = position ) <EOL> currentView . containingDeclaration <EOL> ? : error ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> } <EOL> }


private fun storeResult ( trace : BindingTrace , referenceExpression : KtSimpleNameExpression ? , descriptors : Collection < DeclarationDescriptor > , shouldBeVisibleFrom : DeclarationDescriptor ? , position : QualifierPosition , isQualifier : Boolean = true )

{ <EOL> referenceExpression ? : return <EOL> if ( descriptors . size > <NUM_LIT:1> ) { <EOL> val visibleDescriptors = descriptors . filter { isVisible ( it , shouldBeVisibleFrom , position , languageVersionSettings ) } <EOL> when { <EOL> visibleDescriptors . isEmpty ( ) -> { <EOL> val descriptor = descriptors . first ( ) as DeclarationDescriptorWithVisibility <EOL> trace . report ( Errors . INVISIBLE_REFERENCE . on ( referenceExpression , descriptor , descriptor . visibility , descriptor ) ) <EOL> } <EOL> visibleDescriptors . size > <NUM_LIT:1> -> { <EOL> trace . record ( BindingContext . AMBIGUOUS_REFERENCE_TARGET , referenceExpression , visibleDescriptors ) <EOL> } <EOL> else -> { <EOL> storeResult ( trace , referenceExpression , visibleDescriptors . single ( ) , null , position , isQualifier ) <EOL> } <EOL> } <EOL> } else { <EOL> storeResult ( trace , referenceExpression , descriptors . singleOrNull ( ) , shouldBeVisibleFrom , position , isQualifier ) <EOL> } <EOL> }


private fun storeResult ( trace : BindingTrace , referenceExpression : KtSimpleNameExpression ? , descriptor : DeclarationDescriptor ? , shouldBeVisibleFrom : DeclarationDescriptor ? , position : QualifierPosition , isQualifier : Boolean = true ) : Qualifier ?

{ <EOL> referenceExpression ? : return null <EOL> if ( descriptor == null ) { <EOL> trace . report ( Errors . UNRESOLVED_REFERENCE . on ( referenceExpression , referenceExpression ) ) <EOL> return null <EOL> } <EOL> trace . record ( BindingContext . REFERENCE_TARGET , referenceExpression , descriptor ) <EOL> UnderscoreUsageChecker . checkSimpleNameUsage ( descriptor , referenceExpression , trace ) <EOL> if ( descriptor is DeclarationDescriptorWithVisibility ) { <EOL> val fromToCheck = <EOL> if ( shouldBeVisibleFrom is PackageFragmentDescriptor && shouldBeVisibleFrom . source == SourceElement . NO_SOURCE && referenceExpression . containingFile !is DummyHolder ) { <EOL> PackageFragmentWithCustomSource ( shouldBeVisibleFrom , KotlinSourceElement ( referenceExpression . containingKtFile ) ) <EOL> } else { <EOL> shouldBeVisibleFrom <EOL> } <EOL> if ( ! isVisible ( descriptor , fromToCheck , position , languageVersionSettings ) ) { <EOL> trace . report ( Errors . INVISIBLE_REFERENCE . on ( referenceExpression , descriptor , descriptor . visibility , descriptor ) ) <EOL> } <EOL> } <EOL> return if ( isQualifier ) storeQualifier ( trace , referenceExpression , descriptor ) else null <EOL> }


private fun storeQualifier ( trace : BindingTrace , referenceExpression : KtSimpleNameExpression , descriptor : DeclarationDescriptor ) : Qualifier ?

{ <EOL> val qualifier = <EOL> when ( descriptor ) { <EOL> is PackageViewDescriptor -> PackageQualifier ( referenceExpression , descriptor ) <EOL> is ClassDescriptor -> ClassQualifier ( referenceExpression , descriptor ) <EOL> is TypeParameterDescriptor -> TypeParameterQualifier ( referenceExpression , descriptor ) <EOL> is TypeAliasDescriptor -> { <EOL> val classDescriptor = descriptor . classDescriptor ? : return null <EOL> TypeAliasQualifier ( referenceExpression , descriptor , classDescriptor ) <EOL> } <EOL> else -> return null <EOL> } <EOL> trace . record ( BindingContext . QUALIFIER , qualifier . expression , qualifier ) <EOL> return qualifier <EOL> }


internal fun isVisible ( descriptor : DeclarationDescriptor , shouldBeVisibleFrom : DeclarationDescriptor ? , position : QualifierPosition , languageVersionSettings : LanguageVersionSettings ) : Boolean

{ <EOL> if ( descriptor !is DeclarationDescriptorWithVisibility || shouldBeVisibleFrom == null ) return true <EOL> val visibility = descriptor . visibility <EOL> if ( position == QualifierPosition . IMPORT ) { <EOL> if ( DescriptorVisibilities . isPrivate ( visibility ) ) return DescriptorVisibilities . inSameFile ( descriptor , shouldBeVisibleFrom ) <EOL> if ( ! visibility . mustCheckInImports ( ) ) return true <EOL> } <EOL> return DescriptorVisibilityUtils . isVisibleIgnoringReceiver ( descriptor , shouldBeVisibleFrom , languageVersionSettings ) <EOL> }


override fun getSource ( ) : SourceElement

= source


fun grabDeclarationsToPatch ( ) : Collection < IrDeclaration >

{ <EOL> val result = declarationsToPatch <EOL> declarationsToPatch = arrayListOf ( ) <EOL> return result <EOL> }


override fun getDeclaration ( symbol : IrSymbol ) : IrDeclaration

{ <EOL> require ( ! symbol . isBound ) <EOL> stubbedSymbols . add ( symbol ) <EOL> return when ( symbol ) { <EOL> is IrClassSymbol -> generateClass ( symbol ) <EOL> is IrSimpleFunctionSymbol -> generateSimpleFunction ( symbol ) <EOL> is IrConstructorSymbol -> generateConstructor ( symbol ) <EOL> is IrPropertySymbol -> generateProperty ( symbol ) <EOL> is IrEnumEntrySymbol -> generateEnumEntry ( symbol ) <EOL> is IrTypeAliasSymbol -> generateTypeAlias ( symbol ) <EOL> else -> throw NotImplementedError ( "<STR_LIT>" ) <EOL> } <EOL> }


private fun generateClass ( symbol : IrClassSymbol ) : IrClass

{ <EOL> return builtIns . irFactory . createClass ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = symbol . guessName ( ) , visibility = DescriptorVisibilities . DEFAULT_VISIBILITY , symbol = symbol , kind = ClassKind . CLASS , modality = Modality . OPEN , ) . apply { <EOL> setCommonParent ( ) <EOL> createImplicitParameterDeclarationWithWrappedDescriptor ( ) <EOL> } <EOL> }


private fun generateSimpleFunction ( symbol : IrSimpleFunctionSymbol ) : IrSimpleFunction

{ <EOL> return builtIns . irFactory . createSimpleFunction ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = symbol . guessName ( ) , visibility = DescriptorVisibilities . DEFAULT_VISIBILITY , isInline = false , isExpect = false , returnType = builtIns . nothingType , modality = Modality . FINAL , symbol = symbol , isTailrec = false , isSuspend = false , isOperator = false , isInfix = false , isExternal = false ) . setCommonParent ( ) <EOL> }


private fun generateConstructor ( symbol : IrConstructorSymbol ) : IrConstructor

{ <EOL> return builtIns . irFactory . createConstructor ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = SpecialNames . INIT , visibility = DescriptorVisibilities . DEFAULT_VISIBILITY , isInline = false , isExpect = false , returnType = builtIns . nothingType , symbol = symbol , isPrimary = false , isExternal = false , ) . setCommonParent ( ) <EOL> }


private fun generateProperty ( symbol : IrPropertySymbol ) : IrProperty

{ <EOL> return builtIns . irFactory . createProperty ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = symbol . guessName ( ) , visibility = DescriptorVisibilities . DEFAULT_VISIBILITY , modality = Modality . FINAL , symbol = symbol , isVar = false , isConst = false , isLateinit = false , isDelegated = false , isExternal = false , isExpect = false ) . setCommonParent ( ) <EOL> }


private fun generateEnumEntry ( symbol : IrEnumEntrySymbol ) : IrEnumEntry

{ <EOL> return builtIns . irFactory . createEnumEntry ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = symbol . guessName ( ) , symbol = symbol , ) . setCommonParent ( ) <EOL> }


private fun generateTypeAlias ( symbol : IrTypeAliasSymbol ) : IrTypeAlias

{ <EOL> return builtIns . irFactory . createTypeAlias ( startOffset = UNDEFINED_OFFSET , endOffset = UNDEFINED_OFFSET , origin = PartiallyLinkedDeclarationOrigin . MISSING_DECLARATION , name = symbol . guessName ( ) , visibility = DescriptorVisibilities . DEFAULT_VISIBILITY , symbol = symbol , isActual = true , expandedType = builtIns . nothingType , ) . setCommonParent ( ) <EOL> }


private fun < T : IrDeclaration > T . setCommonParent ( ) : T

{ <EOL> parent = commonParent <EOL> declarationsToPatch += this <EOL> return this <EOL> }


private fun IrSymbol . guessName ( ) : Name

= <EOL> signature ? . guessName ( nameSegmentsToPickUp = <NUM_LIT:1> ) ? . let ( Name :: guessByFirstCharacter ) ? : PartialLinkageUtils . UNKNOWN_NAME


= fn ( )


{ <EOL> var s = "<STR_LIT>" <EOL> var foo = "<STR_LIT:K>" <EOL> fun foo ( x : String , y : Int ) { <EOL> s += x <EOL> } <EOL> fun test ( ) { <EOL> fun foo ( x : String ) { <EOL> s += x <EOL> } <EOL> eval { <EOL> foo ( "<STR_LIT:O>" ) <EOL> foo ( foo , <NUM_LIT:1> ) <EOL> } <EOL> } <EOL> test ( ) <EOL> return s <EOL> }


private fun renderAmbiguousDescriptors ( descriptors : Collection < CallableDescriptor > ) : String

{ <EOL> val context = RenderingContext . Impl ( descriptors ) <EOL> return descriptors <EOL> . sortedWith ( MemberComparator . INSTANCE ) <EOL> . joinToString ( separator = "<STR_LIT:\n>" , prefix = "<STR_LIT:\n>" ) { <EOL> FQ_NAMES_IN_TYPES . render ( it , context ) <EOL> } <EOL> }


@ JvmStatic <EOL> @ IDEAPluginsCompatibilityAPI ( IDEAPlatforms . _213 , message = "<STR_LIT>" , plugins = "<STR_LIT>" ) <EOL> fun < T > commaSeparated ( itemRenderer : DiagnosticParameterRenderer < T > ) : DiagnosticParameterRenderer < Collection < T > >

= <EOL> CommonRenderers . commaSeparated ( itemRenderer )


@ JvmStatic <EOL> fun renderConflictingSubstitutionsInferenceError ( inferenceErrorData : InferenceErrorData , result : TabledDescriptorRenderer ) : TabledDescriptorRenderer

{ <EOL> LOG . assertTrue ( inferenceErrorData . constraintSystem . status . hasConflictingConstraints ( ) , debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> val substitutedDescriptors = Lists . newArrayList < CallableDescriptor > ( ) <EOL> val substitutors = ConstraintsUtil . getSubstitutorsForConflictingParameters ( inferenceErrorData . constraintSystem ) <EOL> for ( substitutor in substitutors ) { <EOL> val substitutedDescriptor = inferenceErrorData . descriptor . substitute ( substitutor ) <EOL> substitutedDescriptors . add ( substitutedDescriptor ) <EOL> } <EOL> val firstConflictingVariable = ConstraintsUtil . getFirstConflictingVariable ( inferenceErrorData . constraintSystem ) <EOL> if ( firstConflictingVariable == null ) { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> return result <EOL> } <EOL> result . text ( newText ( ) . normal ( "<STR_LIT>" ) . strong ( firstConflictingVariable . name ) . normal ( "<STR_LIT>" ) ) <EOL> val table = newTable ( ) <EOL> result . table ( table ) <EOL> table . descriptor ( inferenceErrorData . descriptor ) . text ( "<STR_LIT>" ) <EOL> for ( substitutedDescriptor in substitutedDescriptors ) { <EOL> val receiverType = DescriptorUtils . getReceiverParameterType ( substitutedDescriptor . extensionReceiverParameter ) <EOL> val errorPositions = hashSetOf < ConstraintPosition > ( ) <EOL> val parameterTypes = Lists . newArrayList < KotlinType > ( ) <EOL> for ( valueParameterDescriptor in substitutedDescriptor . valueParameters ) { <EOL> parameterTypes . add ( valueParameterDescriptor . type ) <EOL> if ( valueParameterDescriptor . index >= inferenceErrorData . valueArgumentsTypes . size ) continue <EOL> val actualType = inferenceErrorData . valueArgumentsTypes . get ( valueParameterDescriptor . index ) <EOL> if ( ! KotlinTypeChecker . DEFAULT . isSubtypeOf ( actualType , valueParameterDescriptor . type ) ) { <EOL> errorPositions . add ( VALUE_PARAMETER_POSITION . position ( valueParameterDescriptor . index ) ) <EOL> } <EOL> } <EOL> if ( receiverType != null && inferenceErrorData . receiverArgumentType != null && ! KotlinTypeChecker . DEFAULT . isSubtypeOf ( inferenceErrorData . receiverArgumentType , receiverType ) ) { <EOL> errorPositions . add ( RECEIVER_POSITION . position ( ) ) <EOL> } <EOL> table . functionArgumentTypeList ( receiverType , parameterTypes , { errorPositions . contains ( it ) } ) <EOL> } <EOL> table . text ( "<STR_LIT>" ) <EOL> . functionArgumentTypeList ( inferenceErrorData . receiverArgumentType , inferenceErrorData . valueArgumentsTypes ) <EOL> return result <EOL> }


@ JvmStatic <EOL> fun renderParameterConstraintError ( inferenceErrorData : InferenceErrorData , renderer : TabledDescriptorRenderer ) : TabledDescriptorRenderer

{ <EOL> val constraintErrors = inferenceErrorData . constraintSystem . status . constraintErrors <EOL> val errorPositions = constraintErrors . filter { it is ParameterConstraintError } . map { it . constraintPosition } <EOL> return renderer . table ( TabledDescriptorRenderer . newTable ( ) . descriptor ( inferenceErrorData . descriptor ) . text ( "<STR_LIT>" ) . functionArgumentTypeList ( inferenceErrorData . receiverArgumentType , inferenceErrorData . valueArgumentsTypes , { errorPositions . contains ( it ) } ) ) <EOL> }


@ JvmStatic <EOL> fun renderNoInformationForParameterError ( inferenceErrorData : InferenceErrorData , result : TabledDescriptorRenderer ) : TabledDescriptorRenderer

{ <EOL> val firstUnknownVariable = inferenceErrorData . constraintSystem . typeVariables . firstOrNull { variable -> <EOL> inferenceErrorData . constraintSystem . getTypeBounds ( variable ) . values . isEmpty ( ) <EOL> } ? : return result . apply { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> } <EOL> return result <EOL> . text ( newText ( ) . normal ( "<STR_LIT>" ) . strong ( firstUnknownVariable . name ) . normal ( "<STR_LIT>" ) ) <EOL> . table ( newTable ( ) . descriptor ( inferenceErrorData . descriptor ) . text ( "<STR_LIT>" ) ) <EOL> }


@ JvmStatic <EOL> fun renderUpperBoundViolatedInferenceError ( inferenceErrorData : InferenceErrorData , result : TabledDescriptorRenderer ) : TabledDescriptorRenderer

{ <EOL> val constraintSystem = inferenceErrorData . constraintSystem <EOL> val status = constraintSystem . status <EOL> LOG . assertTrue ( status . hasViolatedUpperBound ( ) , debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> val systemWithoutWeakConstraints = constraintSystem . filterConstraintsOut ( TYPE_BOUND_POSITION ) <EOL> val typeParameterDescriptor = inferenceErrorData . descriptor . typeParameters . firstOrNull { <EOL> ! ConstraintsUtil . checkUpperBoundIsSatisfied ( systemWithoutWeakConstraints , it , inferenceErrorData . call , true ) <EOL> } <EOL> if ( typeParameterDescriptor == null ) { <EOL> if ( inferenceErrorData . descriptor is TypeAliasConstructorDescriptor ) { <EOL> renderUpperBoundViolatedInferenceErrorForTypeAliasConstructor ( inferenceErrorData , result , systemWithoutWeakConstraints ) ? . let { <EOL> return it <EOL> } <EOL> } <EOL> return if ( status . hasConflictingConstraints ( ) ) <EOL> renderConflictingSubstitutionsInferenceError ( inferenceErrorData , result ) <EOL> else { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" , inferenceErrorData , verbosity = ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE ) ) <EOL> result <EOL> } <EOL> } <EOL> val typeVariable = systemWithoutWeakConstraints . descriptorToVariable ( inferenceErrorData . call . toHandle ( ) , typeParameterDescriptor ) <EOL> val inferredValueForTypeParameter = systemWithoutWeakConstraints . getTypeBounds ( typeVariable ) . value <EOL> if ( inferredValueForTypeParameter == null ) { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" + typeParameterDescriptor . name + "<STR_LIT>" + systemWithoutWeakConstraints , inferenceErrorData ) ) <EOL> return result <EOL> } <EOL> result . text ( newText ( ) . normal ( "<STR_LIT>" ) . strong ( typeParameterDescriptor . name ) . normal ( "<STR_LIT>" ) ) <EOL> . table ( newTable ( ) . descriptor ( inferenceErrorData . descriptor ) ) <EOL> var violatedUpperBound : KotlinType ? = null <EOL> for ( upperBound in typeParameterDescriptor . upperBounds ) { <EOL> val upperBoundWithSubstitutedInferredTypes = <EOL> systemWithoutWeakConstraints . resultingSubstitutor . substitute ( upperBound , Variance . INVARIANT ) <EOL> if ( upperBoundWithSubstitutedInferredTypes != null && ! KotlinTypeChecker . DEFAULT . isSubtypeOf ( inferredValueForTypeParameter , upperBoundWithSubstitutedInferredTypes ) ) { <EOL> violatedUpperBound = upperBoundWithSubstitutedInferredTypes <EOL> break <EOL> } <EOL> } <EOL> if ( violatedUpperBound == null ) { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" + typeParameterDescriptor . name + "<STR_LIT>" , inferenceErrorData ) ) <EOL> return result <EOL> } <EOL> val context = RenderingContext . of ( inferredValueForTypeParameter , violatedUpperBound ) <EOL> val typeRenderer = result . typeRenderer <EOL> result . text ( newText ( ) . normal ( "<STR_LIT>" ) . error ( typeRenderer . render ( inferredValueForTypeParameter , context ) ) . normal ( "<STR_LIT>" ) . strong ( typeRenderer . render ( violatedUpperBound , context ) ) ) <EOL> return result <EOL> }


private fun renderUpperBoundViolatedInferenceErrorForTypeAliasConstructor ( inferenceErrorData : InferenceErrorData , result : TabledDescriptorRenderer , systemWithoutWeakConstraints : ConstraintSystem ) : TabledDescriptorRenderer ?

{ <EOL> val descriptor = inferenceErrorData . descriptor <EOL> if ( descriptor !is TypeAliasConstructorDescriptor ) { <EOL> LOG . error ( "<STR_LIT>" ) <EOL> return result <EOL> } <EOL> val inferredTypesForTypeParameters = descriptor . typeParameters . map { <EOL> val typeVariable = systemWithoutWeakConstraints . descriptorToVariable ( inferenceErrorData . call . toHandle ( ) , it ) <EOL> systemWithoutWeakConstraints . getTypeBounds ( typeVariable ) . value <EOL> } <EOL> val inferredTypeSubstitutor = TypeSubstitutor . create ( object : TypeConstructorSubstitution ( ) { <EOL> override fun get ( key : TypeConstructor ) : TypeProjection ? { <EOL> val typeDescriptor = key . declarationDescriptor as? TypeParameterDescriptor ? : return null <EOL> if ( typeDescriptor . containingDeclaration != descriptor . typeAliasDescriptor ) return null <EOL> return inferredTypesForTypeParameters [ typeDescriptor . index ] ? . let ( :: TypeProjectionImpl ) <EOL> } <EOL> } ) <EOL> for ( constraintError in inferenceErrorData . constraintSystem . status . constraintErrors ) { <EOL> val constraintInfo = constraintError . constraintPosition . getValidityConstraintForConstituentType ( ) ? : continue <EOL> val violatedUpperBound = inferredTypeSubstitutor . safeSubstitute ( constraintInfo . bound , Variance . INVARIANT ) <EOL> val violatingInferredType = inferredTypeSubstitutor . safeSubstitute ( constraintInfo . typeArgument , Variance . INVARIANT ) <EOL> val context = RenderingContext . of ( violatingInferredType , violatedUpperBound ) <EOL> val typeRenderer = result . typeRenderer <EOL> result . text ( newText ( ) . normal ( "<STR_LIT>" ) . strong ( constraintInfo . typeParameter . name ) . normal ( "<STR_LIT>" ) ) <EOL> . table ( newTable ( ) . descriptor ( inferenceErrorData . descriptor ) ) <EOL> result . text ( newText ( ) . normal ( "<STR_LIT>" ) . error ( typeRenderer . render ( violatingInferredType , context ) ) . normal ( "<STR_LIT>" ) . strong ( typeRenderer . render ( violatedUpperBound , context ) ) ) <EOL> return result <EOL> } <EOL> return null <EOL> }


@ JvmStatic <EOL> fun renderCannotCaptureTypeParameterError ( inferenceErrorData : InferenceErrorData , result : TabledDescriptorRenderer ) : TabledDescriptorRenderer

{ <EOL> val system = inferenceErrorData . constraintSystem <EOL> val errors = system . status . constraintErrors <EOL> val typeVariableWithCapturedConstraint = errors . firstIsInstanceOrNull < CannotCapture > ( ) ? . typeVariable <EOL> if ( typeVariableWithCapturedConstraint == null ) { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> return result <EOL> } <EOL> val typeBounds = system . getTypeBounds ( typeVariableWithCapturedConstraint ) <EOL> val boundWithCapturedType = typeBounds . bounds . firstOrNull { it . constrainingType . isCaptured ( ) } <EOL> val capturedTypeConstructor = boundWithCapturedType ? . constrainingType ? . constructor as? CapturedTypeConstructor <EOL> if ( capturedTypeConstructor == null ) { <EOL> LOG . error ( debugMessage ( "<STR_LIT>" , inferenceErrorData ) ) <EOL> return result <EOL> } <EOL> val typeParameter = typeVariableWithCapturedConstraint . originalTypeParameter <EOL> val upperBound = TypeIntersector . getUpperBoundsAsType ( typeParameter ) <EOL> assert ( ! KotlinBuiltIns . isNullableAny ( upperBound ) && capturedTypeConstructor . projection . projectionKind == Variance . IN_VARIANCE ) { <EOL> "<STR_LIT>" <EOL> } <EOL> val explanation = <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> result . text ( newText ( ) . normal ( typeParameter . name . wrapIntoQuotes ( ) + "<STR_LIT>" + "<STR_LIT>" + explanation ) ) <EOL> return result <EOL> }


private fun renderTypes ( types : Collection < KotlinType > , typeRenderer : DiagnosticParameterRenderer < KotlinType > , context : RenderingContext ) : String

{ <EOL> return StringUtil . join ( types , { typeRenderer . render ( it , context ) } , "<STR_LIT:U+002CU+0020>" ) <EOL> }


fun renderConstraintSystem ( constraintSystem : ConstraintSystem , verbosity : ConstraintSystemRenderingVerbosity ) : String

{ <EOL> val typeBounds = linkedSetOf < TypeBounds > ( ) <EOL> for ( variable in constraintSystem . typeVariables ) { <EOL> typeBounds . add ( constraintSystem . getTypeBounds ( variable ) ) <EOL> } <EOL> val separator = if ( verbosity == ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE ) "<STR_LIT>" else "<STR_LIT:\n>" <EOL> return "<STR_LIT>" + <EOL> typeBounds . joinToString ( separator = separator ) { renderTypeBounds ( it , verbosity ) } + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> ConstraintsUtil . getDebugMessageForStatus ( constraintSystem . status ) <EOL> }


private fun renderTypeBounds ( typeBounds : TypeBounds , verbosity : ConstraintSystemRenderingVerbosity ) : String

{ <EOL> val renderedTypeVariable = renderTypeVariable ( typeBounds . typeVariable , includeTypeConstructor = verbosity == ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE ) <EOL> return if ( typeBounds . bounds . isEmpty ( ) ) { <EOL> renderedTypeVariable <EOL> } else { <EOL> val boundsPrefix = if ( verbosity == ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE ) "<STR_LIT:\n>" else "<STR_LIT:U+0020>" <EOL> val boundsSeparator = if ( verbosity == ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE ) "<STR_LIT:\n>" else "<STR_LIT:U+002CU+0020>" <EOL> val renderedBounds = typeBounds . bounds . joinToString ( separator = boundsSeparator ) { renderTypeBound ( it , verbosity ) } <EOL> renderedTypeVariable + boundsPrefix + renderedBounds <EOL> } <EOL> }


private fun renderTypeVariable ( typeVariable : TypeVariable , includeTypeConstructor : Boolean ) : String

{ <EOL> val typeVariableName = typeVariable . name . asString ( ) <EOL> if ( ! includeTypeConstructor ) return typeVariableName <EOL> return "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> }


private fun renderTypeBound ( bound : Bound , verbosity : ConstraintSystemRenderingVerbosity ) : String

{ <EOL> val typeRendered = if ( verbosity == ConstraintSystemRenderingVerbosity . COMPACT ) <EOL> DescriptorRenderer . SHORT_NAMES_IN_TYPES <EOL> else <EOL> DescriptorRenderer . FQ_NAMES_IN_TYPES <EOL> val arrow = when ( bound . kind ) { <EOL> LOWER_BOUND -> "<STR_LIT>" <EOL> UPPER_BOUND -> "<STR_LIT>" <EOL> else -> "<STR_LIT>" <EOL> } <EOL> val initialBoundRender = arrow + typeRendered . renderType ( bound . constrainingType ) + if ( ! bound . isProper ) "<STR_LIT:*>" else "<STR_LIT>" <EOL> return when ( verbosity ) { <EOL> ConstraintSystemRenderingVerbosity . COMPACT -> initialBoundRender <EOL> ConstraintSystemRenderingVerbosity . DEBUG -> "<STR_LIT>" <EOL> ConstraintSystemRenderingVerbosity . EXTRA_VERBOSE -> { <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> TypeUtils . getAllSupertypes ( bound . constrainingType ) . joinToString ( "<STR_LIT:\n>" ) { <EOL> "<STR_LIT>" + typeRendered . renderType ( it ) + "<STR_LIT>" <EOL> } + <EOL> "<STR_LIT:\n>" <EOL> } <EOL> } <EOL> }


@ Suppress ( "<STR_LIT>" ) <EOL> private fun renderTypeConstructor ( typeConstructor : TypeConstructor ) : String

{ <EOL> return "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> }


private fun debugMessage ( message : String , inferenceErrorData : InferenceErrorData , verbosity : ConstraintSystemRenderingVerbosity = ConstraintSystemRenderingVerbosity . DEBUG )

= buildString { <EOL> append ( message ) <EOL> append ( "<STR_LIT>" ) <EOL> append ( renderConstraintSystem ( inferenceErrorData . constraintSystem , verbosity ) ) <EOL> append ( "<STR_LIT>" ) <EOL> append ( inferenceErrorData . descriptor ) <EOL> append ( "<STR_LIT>" ) <EOL> val context = RenderingContext . Empty <EOL> if ( TypeUtils . noExpectedType ( inferenceErrorData . expectedType ) ) { <EOL> append ( inferenceErrorData . expectedType ) <EOL> } else { <EOL> append ( RENDER_TYPE_WITH_ANNOTATIONS . render ( inferenceErrorData . expectedType , context ) ) <EOL> } <EOL> append ( "<STR_LIT>" ) <EOL> if ( inferenceErrorData . receiverArgumentType != null ) { <EOL> append ( RENDER_TYPE_WITH_ANNOTATIONS . render ( inferenceErrorData . receiverArgumentType , context ) ) . append ( "<STR_LIT:.>" ) <EOL> } <EOL> append ( "<STR_LIT:(>" ) . append ( renderTypes ( inferenceErrorData . valueArgumentsTypes , RENDER_TYPE_WITH_ANNOTATIONS , context ) ) . append ( "<STR_LIT:)>" ) <EOL> }


private fun String . wrapIntoQuotes ( ) : String

= "<STR_LIT>"


private fun Name . wrapIntoQuotes ( ) : String

= "<STR_LIT>"


override fun render ( obj : Collection < DeclarationDescriptor > , renderingContext : RenderingContext ) : String

{ <EOL> return buildString { <EOL> for ( descriptor in obj ) { <EOL> mode . newLine ( this ) <EOL> mode . renderDescriptor ( this , descriptor , renderingContext , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }


fun renderExpressionType ( type : KotlinType ? , dataFlowTypes : Set < KotlinType > ? ) : String

{ <EOL> if ( type == null ) <EOL> return "<STR_LIT>" <EOL> if ( dataFlowTypes == null ) <EOL> return DEBUG_TEXT . renderType ( type ) <EOL> val typesAsString = dataFlowTypes . map { DEBUG_TEXT . renderType ( it ) } . toMutableSet ( ) . apply { add ( DEBUG_TEXT . renderType ( type ) ) } <EOL> return typesAsString . sorted ( ) . joinToString ( separator = "<STR_LIT>" ) <EOL> }


fun renderCallInfo ( fqName : FqNameUnsafe ? , typeCall : String )

= <EOL> buildString { <EOL> append ( "<STR_LIT>" ) <EOL> append ( "<STR_LIT>" ) <EOL> }


= SmartDescriptorRenderer ( this )


{ <EOL> println ( "<STR_LIT:OK>" ) <EOL> }


{ <EOL> val valVariable by Delegate ( ) <EOL> val varVariable by Delegate ( ) <EOL> }


operator fun getValue ( thisRef : Any ? , property : KProperty < * > ) : String

= "<STR_LIT>"


operator fun setValue ( thisRef : Any ? , property : KProperty < * > , value : String )

{ <EOL> }


= s


= z + test ( )


{ <EOL> val res = A ( "<STR_LIT:Fail>" ) . B ( "<STR_LIT:OK>" ) . testB ( ) <EOL> return if ( res == "<STR_LIT>" ) "<STR_LIT:OK>" else res ; <EOL> }


inline fun < T > Iterable < T > . myForEach ( action : ( T ) -> Unit ) : Unit

{ <EOL> for ( element in this ) action ( element ) <EOL> }


{ <EOL> val visited = mutableListOf < Pair < Int , Int > > ( ) <EOL> for ( i in <NUM_LIT:1> .. <NUM_LIT:3> ) { <EOL> ( <NUM_LIT:1> .. <NUM_LIT:3> ) . myForEach { j -> <EOL> if ( j == <NUM_LIT:3> ) { <EOL> break <EOL> } <EOL> visited += i to j <EOL> } <EOL> } <EOL> assertEquals ( listOf ( <NUM_LIT:1> to <NUM_LIT:1> , <NUM_LIT:1> to <NUM_LIT:2> ) , visited ) <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> val z : Int ? = <NUM_LIT:1> <EOL> val r = z ! ! + <NUM_LIT:1> <EOL> stubPreventBoxingOptimization ( z ) <EOL> }


fun stubPreventBoxingOptimization ( s : Int ? )

{ <EOL> s <EOL> }


= bar ( "<STR_LIT:OK>" )


suspend inline fun bar ( result : String ) : String

= suspendCoroutineUninterceptedOrReturn { x -> <EOL> x . resume ( result ) <EOL> COROUTINE_SUSPENDED <EOL> }


{ <EOL> c . startCoroutine ( EmptyContinuation ) <EOL> }


{ <EOL> var result = "<STR_LIT>" <EOL> builder { <EOL> result = foo ( ) <EOL> } <EOL> return result <EOL> }


= test . test ( )


override fun replaceVariables ( mapping : Map < String , String > ) : KernelRepository

{ <EOL> return KernelRepository ( replaceVariables ( path , mapping ) , username ? . let { replaceVariables ( it , mapping ) } , password ? . let { replaceVariables ( it , mapping ) } , ) <EOL> }


override fun compareTo ( other : KernelRepository ) : Int

{ <EOL> return compareByProperties ( other , KernelRepository :: path , KernelRepository :: username , KernelRepository :: password , ) <EOL> }


operator fun < T > MyList < T > . plusAssign ( element : T )


{ <EOL> listOfFunctions . plusAssign ( { it -> it } ) <EOL> listOfFunctions += { it -> it } <EOL> }


{ <EOL> return "<STR_LIT:OK>" <EOL> }


= true


fun test ( mh : MethodHandle ? , mt : MethodType ? )

{ <EOL> val constable = if ( cond ( ) ) mh else mt <EOL> }


{ <EOL> test ( null , null ) <EOL> return "<STR_LIT:OK>" <EOL> }


@ Test <EOL> fun incorrectlyCalledRunBlocking_doesNotHaveSameInterceptor ( )

= runBlockingTest { <EOL> val outerInterceptor = coroutineContext [ ContinuationInterceptor ] <EOL> runBlocking { <EOL> assertNotSame ( coroutineContext [ ContinuationInterceptor ] , outerInterceptor ) <EOL> } <EOL> }


@ Test <EOL> fun testSingleThreadExecutor ( )

= runBlocking { <EOL> val mainThread = Thread . currentThread ( ) <EOL> Dispatchers . setMain ( Dispatchers . Unconfined ) <EOL> newSingleThreadContext ( "<STR_LIT>" ) . use { threadPool -> <EOL> withContext ( Dispatchers . Main ) { <EOL> assertSame ( mainThread , Thread . currentThread ( ) ) <EOL> } <EOL> Dispatchers . setMain ( threadPool ) <EOL> withContext ( Dispatchers . Main ) { <EOL> assertNotSame ( mainThread , Thread . currentThread ( ) ) <EOL> } <EOL> assertSame ( mainThread , Thread . currentThread ( ) ) <EOL> withContext ( Dispatchers . Main . immediate ) { <EOL> assertNotSame ( mainThread , Thread . currentThread ( ) ) <EOL> } <EOL> assertSame ( mainThread , Thread . currentThread ( ) ) <EOL> Dispatchers . setMain ( Dispatchers . Unconfined ) <EOL> withContext ( Dispatchers . Main . immediate ) { <EOL> assertSame ( mainThread , Thread . currentThread ( ) ) <EOL> } <EOL> assertSame ( mainThread , Thread . currentThread ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun whenDispatchCalled_runsOnCurrentThread ( )

{ <EOL> val currentThread = Thread . currentThread ( ) <EOL> val subject = TestCoroutineDispatcher ( ) <EOL> val scope = TestCoroutineScope ( subject ) <EOL> val deferred = scope . async ( Dispatchers . Default ) { <EOL> withContext ( subject ) { <EOL> assertNotSame ( currentThread , Thread . currentThread ( ) ) <EOL> <NUM_LIT:3> <EOL> } <EOL> } <EOL> runBlocking { <EOL> assertEquals ( <NUM_LIT:3> , deferred . await ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun whenAllDispatchersMocked_runsOnSameThread ( )

{ <EOL> val currentThread = Thread . currentThread ( ) <EOL> val subject = TestCoroutineDispatcher ( ) <EOL> val scope = TestCoroutineScope ( subject ) <EOL> val deferred = scope . async ( subject ) { <EOL> withContext ( subject ) { <EOL> assertSame ( currentThread , Thread . currentThread ( ) ) <EOL> <NUM_LIT:3> <EOL> } <EOL> } <EOL> runBlocking { <EOL> assertEquals ( <NUM_LIT:3> , deferred . await ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun testResumingFromAnotherThread ( )

= runTest { <EOL> suspendCancellableCoroutine < Unit > { cont -> <EOL> thread { <EOL> Thread . sleep ( <NUM_LIT:10> ) <EOL> cont . resume ( Unit ) <EOL> } <EOL> } <EOL> }

/** Tests that resuming the coroutine of [runTest] asynchronously in reasonable time succeeds. */


@ Test <EOL> fun testStandardTestDispatcherIsConfined ( ) : Unit

= runBlocking { <EOL> val scheduler = TestCoroutineScheduler ( ) <EOL> val initialThread = Thread . currentThread ( ) <EOL> val job = launch ( StandardTestDispatcher ( scheduler ) ) { <EOL> assertEquals ( initialThread , Thread . currentThread ( ) ) <EOL> withContext ( Dispatchers . IO ) { <EOL> val ioThread = Thread . currentThread ( ) <EOL> assertNotSame ( initialThread , ioThread ) <EOL> } <EOL> assertEquals ( initialThread , Thread . currentThread ( ) ) <EOL> } <EOL> scheduler . advanceUntilIdle ( ) <EOL> while ( job . isActive ) { <EOL> scheduler . receiveDispatchEvent ( ) <EOL> scheduler . advanceUntilIdle ( ) <EOL> } <EOL> }

/** Tests that [StandardTestDispatcher] is not executed in-place but confined to the thread in which the
 * virtual time control happens. */


fun registerModuleData ( module : TestModule , moduleData : FirModuleData )

{ <EOL> firModuleDataByModule [ module ] = moduleData <EOL> }


fun getCorrespondingModuleData ( module : TestModule ) : FirModuleData

{ <EOL> return firModuleDataByModule [ module ] ? : error ( "<STR_LIT>" ) <EOL> }


fun getRegularDependentSourceModules ( module : TestModule ) : List < FirModuleData >

{ <EOL> return getDependentModulesImpl ( module . regularDependencies ) <EOL> }


fun getDependentFriendSourceModules ( module : TestModule ) : List < FirModuleData >

{ <EOL> return getDependentModulesImpl ( module . friendDependencies ) <EOL> }


fun getDependentDependsOnSourceModules ( module : TestModule ) : List < FirModuleData >

{ <EOL> return getDependentModulesImpl ( module . dependsOnDependencies ) <EOL> }


private fun getDependentModulesImpl ( dependencies : List < DependencyDescription > ) : List < FirModuleData >

{ <EOL> return dependencies . filter { it . kind == DependencyKind . Source } . map { <EOL> getCorrespondingModuleData ( testServices . dependencyProvider . getTestModule ( it . moduleName ) ) <EOL> } <EOL> }


= action ( )


fun bar ( action : java . lang . Runnable )


= "<STR_LIT>"


{ <EOL> val x = bar ( ) { foo ( ) } <EOL> x . length <EOL> }


@ Test <EOL> fun testChannelSelectLoop ( )

= runTest ( expected = { it is TestException } ) { <EOL> expect ( <NUM_LIT:1> ) <EOL> val channel = Channel < Unit > ( ) <EOL> val job = launch { <EOL> expect ( <NUM_LIT:2> ) <EOL> channel . send ( Unit ) <EOL> expect ( <NUM_LIT:3> ) <EOL> throw TestException ( ) <EOL> } <EOL> try { <EOL> while ( true ) { <EOL> select < Unit > { <EOL> channel . onReceiveCatching { <EOL> expectUnreached ( ) <EOL> } <EOL> job . onJoin { <EOL> expectUnreached ( ) <EOL> } <EOL> } <EOL> } <EOL> } catch ( e : CancellationException ) { <EOL> finish ( <NUM_LIT:4> ) <EOL> } <EOL> }


{ <EOL> return abs ( x - other . x ) < <NUM_LIT> <EOL> }


{ <EOL> return <NUM_LIT:0> <EOL> }


{ <EOL> val set = setOf ( MFVC ( <NUM_LIT:1.0> , <NUM_LIT:100> ) , MFVC ( <NUM_LIT> , <NUM_LIT> ) , MFVC ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> return if ( set . size == <NUM_LIT:2> ) "<STR_LIT:OK>" else "<STR_LIT:Fail>" <EOL> }


= copy ( )


{ <EOL> val system = object : BaseTestSystem ( ) { } <EOL> val diagnose = JavaDiagnostic ( system ) . diagnose ( ) <EOL> val expected = Diagnosis . Builder ( "<STR_LIT>" ) . apply { <EOL> addSuccess ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> addSuccess ( "<STR_LIT>" ) <EOL> addEnvironment ( EnvironmentPiece . Jdk ( Version ( "<STR_LIT>" ) ) ) <EOL> } . build ( ) <EOL> assertEquals ( expected , diagnose ) <EOL> }


{ <EOL> val system = object : BaseTestSystem ( ) { <EOL> override fun executeCmd ( cmd : String ) : ProcessResult = when ( cmd ) { <EOL> "<STR_LIT>" -> { <EOL> ProcessResult ( <NUM_LIT:0> , null ) <EOL> } <EOL> else -> super . executeCmd ( cmd ) <EOL> } <EOL> } <EOL> val diagnose = JavaDiagnostic ( system ) . diagnose ( ) <EOL> val expected = Diagnosis . Builder ( "<STR_LIT>" ) . apply { <EOL> addFailure ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> } . build ( ) <EOL> assertEquals ( expected , diagnose ) <EOL> }


@ Test <EOL> fun `check no JAVA_HOME` ( )

{ <EOL> val system = object : BaseTestSystem ( ) { <EOL> override fun getEnvVar ( name : String ) : String ? = when ( name ) { <EOL> "<STR_LIT>" -> null <EOL> else -> super . getEnvVar ( name ) <EOL> } <EOL> } <EOL> val diagnose = JavaDiagnostic ( system ) . diagnose ( ) <EOL> val expected = Diagnosis . Builder ( "<STR_LIT>" ) . apply { <EOL> addSuccess ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> addInfo ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ) <EOL> addEnvironment ( EnvironmentPiece . Jdk ( Version ( "<STR_LIT>" ) ) ) <EOL> } . build ( ) <EOL> assertEquals ( expected , diagnose ) <EOL> }


@ Test <EOL> fun `check invalid JAVA_HOME` ( )

{ <EOL> val system = object : BaseTestSystem ( ) { <EOL> override fun getEnvVar ( name : String ) : String ? = when ( name ) { <EOL> "<STR_LIT>" -> "<STR_LIT>" <EOL> else -> super . getEnvVar ( name ) <EOL> } <EOL> override fun fileExists ( path : String ) : Boolean = when ( path ) { <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" -> false <EOL> else -> super . fileExists ( path ) <EOL> } <EOL> } <EOL> val diagnose = JavaDiagnostic ( system ) . diagnose ( ) <EOL> val expected = Diagnosis . Builder ( "<STR_LIT>" ) . apply { <EOL> addSuccess ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> addFailure ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ) <EOL> addEnvironment ( EnvironmentPiece . Jdk ( Version ( "<STR_LIT>" ) ) ) <EOL> } . build ( ) <EOL> assertEquals ( expected , diagnose ) <EOL> }


@ Test <EOL> fun `check JAVA_HOME != java location` ( )

{ <EOL> val system = object : BaseTestSystem ( ) { <EOL> override fun getEnvVar ( name : String ) : String ? = when ( name ) { <EOL> "<STR_LIT>" -> "<STR_LIT>" <EOL> else -> super . getEnvVar ( name ) <EOL> } <EOL> } <EOL> val diagnose = JavaDiagnostic ( system ) . diagnose ( ) <EOL> val expected = Diagnosis . Builder ( "<STR_LIT>" ) . apply { <EOL> addSuccess ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> addSuccess ( "<STR_LIT>" , ) <EOL> addInfo ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ) <EOL> addEnvironment ( EnvironmentPiece . Jdk ( Version ( "<STR_LIT>" ) ) ) <EOL> } . build ( ) <EOL> assertEquals ( expected , diagnose ) <EOL> }


override fun generate ( moduleFragment : IrModuleFragment , pluginContext : IrPluginContext )

{ <EOL> val androidSymbols = AndroidSymbols ( pluginContext , moduleFragment ) <EOL> ParcelizeFirIrTransformer ( pluginContext , androidSymbols , parcelizeAnnotations ) . transform ( moduleFragment ) <EOL> }


protected fun doTest ( fileName : String )

{ <EOL> doTestCompiledKotlinWithTypeTable ( fileName ) <EOL> }


{ <EOL> val s = this@Bar <EOL> s . isOpen <EOL> }


{ <EOL> Bar ( ) . Baz ( ) <EOL> return "<STR_LIT:OK>" <EOL> }


public fun thread ( start : Boolean = true , isDaemon : Boolean = false , contextClassLoader : ClassLoader ? = null , name : String ? = null , priority : Int = - <NUM_LIT:1> , block : ( ) -> Unit ) : Thread

{ <EOL> val thread = object : Thread ( ) { <EOL> public override fun run ( ) { <EOL> block ( ) <EOL> } <EOL> } <EOL> if ( isDaemon ) <EOL> thread . isDaemon = true <EOL> if ( priority > <NUM_LIT:0> ) <EOL> thread . priority = priority <EOL> if ( name != null ) <EOL> thread . name = name <EOL> if ( contextClassLoader != null ) <EOL> thread . contextClassLoader = contextClassLoader <EOL> if ( start ) <EOL> thread . start ( ) <EOL> return thread <EOL> }

/**
 * Creates a thread that runs the specified [block] of code.
 *
 * @param start if `true`, the thread is immediately started.
 * @param isDaemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when
 * the only threads running are all daemon threads.
 * @param contextClassLoader the class loader to use for loading classes and resources in this thread.
 * @param name the name of the thread.
 * @param priority the priority of the thread.
 */


@ kotlin . internal . InlineOnly <EOL> public inline fun < T : Any > ThreadLocal < T > . getOrSet ( default : ( ) -> T ) : T

{ <EOL> return get ( ) ? : default ( ) . also ( this :: set ) <EOL> }

/**
 * Gets the value in the current thread's copy of this
 * thread-local variable or replaces the value with the result of calling
 * [default] function in case if that value was `null`.
 *
 * If the variable has no value for the current thread,
 * it is first initialized to the value returned
 * by an invocation of the [ThreadLocal.initialValue] method.
 * Then if it is still `null`, the provided [default] function is called and its result
 * is stored for the current thread and then returned.
 */


suspend fun collect ( collector : FlowCollector < T > )


suspend fun emit ( value : T )


suspend inline fun < T > Flow < T > . collect ( crossinline action : suspend ( value : T ) -> Unit ) : Unit

= <EOL> collect ( object : FlowCollector < T > { <EOL> override suspend fun emit ( value : T ) = action ( value ) <EOL> } )


{ <EOL> c . startCoroutine ( Continuation ( EmptyCoroutineContext ) { <EOL> it . getOrThrow ( ) <EOL> } ) <EOL> }


{ <EOL> val flow : Flow < Result < String > > = object : Flow < Result < String > > { <EOL> override suspend fun collect ( collector : FlowCollector < Result < String > > ) { <EOL> collector . emit ( Result . success ( "<STR_LIT:OK>" ) ) <EOL> } <EOL> } <EOL> var res = "<STR_LIT:FAIL>" <EOL> builder { <EOL> flow . collect { result -> <EOL> result . onSuccess { text -> <EOL> res = text <EOL> } <EOL> } <EOL> } <EOL> return res <EOL> }


{ <EOL> if ( x !is Int ) return "<STR_LIT:FailU+00201>" <EOL> when ( x ) { <EOL> <NUM_LIT:0> -> return "<STR_LIT:OK>" <EOL> else -> return "<STR_LIT:FailU+00202>" <EOL> } <EOL> }


= test ( <NUM_LIT:0> )


/**
 * [LazyThreadSafetyMode.PUB<caret>LICATION]
 */


{ <EOL> var hit = false <EOL> val l = { hit = true ; true } <EOL> assert ( l ( ) ) <EOL> return hit <EOL> }


{ <EOL> var hit = false <EOL> val l = { hit = true ; false } <EOL> assert ( l ( ) ) <EOL> return hit <EOL> }


{ <EOL> var hit = false <EOL> val l = { hit = true ; true } <EOL> assert ( l ( ) ) { "<STR_LIT>" } <EOL> return hit <EOL> }


{ <EOL> var hit = false <EOL> val l = { hit = true ; false } <EOL> assert ( l ( ) ) { "<STR_LIT>" } <EOL> return hit <EOL> }


{ <EOL> val loader = Dummy :: class . java . classLoader <EOL> loader . setPackageAssertionStatus ( "<STR_LIT>" , true ) <EOL> val c = loader . loadClass ( "<STR_LIT>" ) <EOL> return c . newInstance ( ) as Checker <EOL> }


{ <EOL> var c = enableAssertions ( ) <EOL> if ( ! c . checkTrue ( ) ) return "<STR_LIT>" <EOL> if ( ! c . checkTrueWithMessage ( ) ) return "<STR_LIT>" <EOL> try { <EOL> c . checkFalse ( ) <EOL> return "<STR_LIT>" <EOL> } catch ( ignore : AssertionError ) { <EOL> } <EOL> try { <EOL> c . checkFalseWithMessage ( ) <EOL> return "<STR_LIT>" <EOL> } catch ( ignore : AssertionError ) { <EOL> } <EOL> return "<STR_LIT:OK>" <EOL> }


fun removeDuplicateImports ( node : JsNode )

{ <EOL> node . accept ( object : RecursiveJsVisitor ( ) { <EOL> override fun visitBlock ( x : JsBlock ) { <EOL> super . visitBlock ( x ) <EOL> removeDuplicateImports ( x . statements ) <EOL> } <EOL> } ) <EOL> }


private fun removeDuplicateImports ( statements : MutableList < JsStatement > )

{ <EOL> val existingImports = mutableMapOf < String , JsName > ( ) <EOL> val replacements = mutableMapOf < JsName , JsExpression > ( ) <EOL> removeDuplicateImports ( statements , existingImports , replacements ) <EOL> for ( statement in statements ) { <EOL> replaceNames ( statement , replacements ) <EOL> } <EOL> }


private fun removeDuplicateImports ( statements : MutableList < JsStatement > , existingImports : MutableMap < String , JsName > , replacements : MutableMap < JsName , JsExpression > )

{ <EOL> var index = <NUM_LIT:0> <EOL> while ( index < statements . size ) { <EOL> val statement = statements [ index ] <EOL> if ( statement is JsVars ) { <EOL> val importTag = getImportTag ( statement ) <EOL> if ( importTag != null ) { <EOL> val name = statement . vars [ <NUM_LIT:0> ] . name <EOL> val existingName = existingImports [ importTag ] <EOL> if ( existingName != null ) { <EOL> replacements [ name ] = existingName . makeRef ( ) <EOL> statements . removeAt ( index ) <EOL> continue <EOL> } <EOL> else { <EOL> existingImports [ importTag ] = name <EOL> } <EOL> } <EOL> } <EOL> else if ( statement is JsBlock ) { <EOL> removeDuplicateImports ( statement . statements , existingImports , replacements ) <EOL> } <EOL> index ++ <EOL> } <EOL> }


override fun configure ( target : KotlinAndroidTarget , kotlinSourceSet : KotlinSourceSet , @ Suppress ( "<STR_LIT:TYPEALIAS_EXPANSION_DEPRECATION>" ) androidSourceSet : DeprecatedAndroidSourceSet )

{ <EOL> @ Suppress ( "<STR_LIT:TYPEALIAS_EXPANSION_DEPRECATION>" ) <EOL> val androidKotlinSourceDirectorySet = androidSourceSet . javaClass . getMethod ( "<STR_LIT>" ) <EOL> . invoke ( androidSourceSet ) as DeprecatedAndroidSourceDirectorySet <EOL> androidKotlinSourceDirectorySet . setSrcDirs ( listOf ( target . project . provider { kotlinSourceSet . kotlin . srcDirs } ) ) <EOL> }


abstract fun run ( ) : Int


{ <EOL> val c : Int ? = null <EOL> val a : Int ? = <NUM_LIT:1> <EOL> if ( c is Int ) { <EOL> val k = object : Runnable ( a ! ! ) { <EOL> override fun run ( ) = arg <EOL> } <EOL> k . run ( ) <EOL> val d : Int = c <EOL> return a + d <EOL> } <EOL> else return - <NUM_LIT:1> <EOL> }


fun requestFlow ( i : Int ) : Flow < String >

= flow { <EOL> emit ( "<STR_LIT>" ) <EOL> delay ( <NUM_LIT> ) <EOL> emit ( "<STR_LIT>" ) <EOL> }


= runBlocking < Unit > { <EOL> val startTime = currentTimeMillis ( ) <EOL> ( <NUM_LIT:1> .. <NUM_LIT:3> ) . asFlow ( ) . onEach { delay ( <NUM_LIT:100> ) } <EOL> . flatMapLatest { requestFlow ( it ) } <EOL> . collect { value -> <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }


fun lenetOnMnistInferenceWithTensorNames ( )

{ <EOL> val ( train , test ) = mnist ( ) <EOL> SavedModel . load ( PATH_TO_MODEL ) . use { <EOL> println ( it . graphToString ( ) ) <EOL> val prediction = it . predict ( train . getX ( <NUM_LIT:0> ) , "<STR_LIT>" , "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" + train . getY ( <NUM_LIT:0> ) ) <EOL> val predictions = it . predict ( test ) { data -> predict ( data , "<STR_LIT>" , "<STR_LIT>" ) } <EOL> println ( predictions . toString ( ) ) <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This examples demonstrates running [SavedModel] for prediction on [mnist] dataset.
 *
 * It uses string tensor names to get access to input/output tensors in TensorFlow static graph.
 */


= lenetOnMnistInferenceWithTensorNames ( )


= object : ListImpl ( ) { <EOL> override fun func ( ) = <NUM_LIT:42> <EOL> } . func ( )


public fun append ( value : Char ) : Appendable

/**
 * Appends the specified character [value] to this Appendable and returns this instance.
 *
 * @param value the character to append.
 */


public fun append ( value : CharSequence ? ) : Appendable

/**
 * Appends the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence to append. If [value] is `null`, then the four characters `"null"` are appended to this Appendable.
 */


public fun append ( value : CharSequence ? , startIndex : Int , endIndex : Int ) : Appendable

/**
 * Appends a subsequence of the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence from which a subsequence is appended. If [value] is `null`,
 * then characters are appended as if [value] contained the four characters `"null"`.
 * @param startIndex the beginning (inclusive) of the subsequence to append.
 * @param endIndex the end (exclusive) of the subsequence to append.
 *
 * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> public fun < T : Appendable > T . appendRange ( value : CharSequence , startIndex : Int , endIndex : Int ) : T

{ <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> return append ( value , startIndex , endIndex ) as T <EOL> }

/**
 * Appends a subsequence of the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence from which a subsequence is appended.
 * @param startIndex the beginning (inclusive) of the subsequence to append.
 * @param endIndex the end (exclusive) of the subsequence to append.
 *
 * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
 */


public fun < T : Appendable > T . append ( vararg value : CharSequence ? ) : T

{ <EOL> for ( item in value ) <EOL> append ( item ) <EOL> return this <EOL> }

/**
 * Appends all arguments to the given [Appendable].
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( ) : Appendable

= append ( '<CHAR_LIT:\n>' )

/** Appends a line feed character (`\n`) to this Appendable. */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( value : CharSequence ? ) : Appendable

= append ( value ) . appendLine ( )

/** Appends value to the given Appendable and a line feed character (`\n`) after it. */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( value : Char ) : Appendable

= append ( value ) . appendLine ( )


internal fun < T > Appendable . appendElement ( element : T , transform : ( ( T ) -> CharSequence ) ? )

{ <EOL> when { <EOL> transform != null -> append ( transform ( element ) ) <EOL> element is CharSequence ? -> append ( element ) <EOL> element is Char -> append ( element ) <EOL> else -> append ( element . toString ( ) ) <EOL> } <EOL> }


{ <EOL> return """<STR_LIT>""" <EOL> }


{ <EOL> assertSame ( TestNGAsserter , asserter ) <EOL> Assert . assertEquals ( TestNGAsserter :: class . java . simpleName , kotlin . test . asserter . javaClass . simpleName ) <EOL> }


@ Test <EOL> fun parallelThreadGetsTheSameAsserter ( )

{ <EOL> val q = ArrayBlockingQueue < Any > ( <NUM_LIT:1> ) <EOL> Thread { <EOL> q . put ( asserter ) <EOL> } . start ( ) <EOL> assertSame ( asserter , q . take ( ) ) <EOL> }


fun < T > compare ( expected : T , actual : T , block : CompareContext < T > . ( ) -> Unit )

{ <EOL> CompareContext ( expected , actual ) . block ( ) <EOL> }


fun equals ( message : String = "<STR_LIT>" )

{ <EOL> assertEquals ( expected , actual , message ) <EOL> }


fun < P > propertyEquals ( message : String = "<STR_LIT>" , getter : T . ( ) -> P )

{ <EOL> assertEquals ( expected . getter ( ) , actual . getter ( ) , message ) <EOL> }


fun propertyFails ( getter : T . ( ) -> Unit )

{ assertFailEquals ( { expected . getter ( ) } , { actual . getter ( ) } ) }


inline fun < reified E > propertyFailsWith ( noinline getter : T . ( ) -> Unit )

= propertyFailsWith ( { it is E } , getter )


fun propertyFailsWith ( exceptionPredicate : ( Throwable ) -> Boolean , getter : T . ( ) -> Unit )

{ assertFailEquals ( { expected . getter ( ) } , { actual . getter ( ) } , exceptionPredicate ) }


fun < P > compareProperty ( getter : T . ( ) -> P , block : CompareContext < P > . ( ) -> Unit )

{ <EOL> compare ( expected . getter ( ) , actual . getter ( ) , block ) <EOL> }


private fun assertFailEquals ( expected : ( ) -> Unit , actual : ( ) -> Unit , exceptionPredicate : ( ( Throwable ) -> Boolean ) ? = null )

{ <EOL> val expectedFail = assertFails ( expected ) <EOL> val actualFail = assertFails ( actual ) <EOL> if ( exceptionPredicate != null ) { <EOL> assertTrue ( exceptionPredicate ( expectedFail ) , "<STR_LIT>" ) <EOL> assertTrue ( exceptionPredicate ( actualFail ) , "<STR_LIT>" ) <EOL> } else { <EOL> assertTypeEquals ( expectedFail , actualFail ) <EOL> } <EOL> }


{ <EOL> return flow { <EOL> emit ( <NUM_LIT:1> ) <EOL> delay ( <NUM_LIT> . milliseconds ) <EOL> emit ( <NUM_LIT:2> ) <EOL> delay ( <NUM_LIT> . milliseconds ) <EOL> emit ( <NUM_LIT:3> ) <EOL> delay ( <NUM_LIT> . milliseconds ) <EOL> } <EOL> }


= runBlocking { <EOL> val myFlowOfValues = createValues ( ) <EOL> myFlowOfValues . collect { log ( it ) } <EOL> }


override fun getDecompiledText ( file : FileWithMetadata . Compatible , serializerProtocol : SerializerExtensionProtocol , flexibleTypeDeserializer : FlexibleTypeDeserializer ) : DecompiledText

{ <EOL> return decompiledText ( file , serializerProtocol , flexibleTypeDeserializer , renderer ) <EOL> }


internal fun decompiledText ( file : FileWithMetadata . Compatible , serializerProtocol : SerializerExtensionProtocol , flexibleTypeDeserializer : FlexibleTypeDeserializer , renderer : DescriptorRenderer , deserializationConfiguration : DeserializationConfiguration = DeserializationConfiguration . Default ) : DecompiledText

{ <EOL> val packageFqName = file . packageFqName <EOL> val resolver = KlibMetadataDeserializerForDecompiler ( packageFqName , file . proto , file . nameResolver , serializerProtocol , flexibleTypeDeserializer , deserializationConfiguration , ) <EOL> val declarations = arrayListOf < DeclarationDescriptor > ( ) <EOL> declarations . addAll ( resolver . resolveDeclarationsInFacade ( packageFqName ) ) <EOL> for ( classProto in file . classesToDecompile ) { <EOL> val classId = file . nameResolver . getClassId ( classProto . fqName ) <EOL> declarations . addIfNotNull ( resolver . resolveTopLevelClass ( classId ) ) <EOL> } <EOL> return buildDecompiledText ( packageFqName , declarations , renderer ) <EOL> }

/**
 * This function is extracted for [Fe10KlibMetadataDecompiler], [Fe10KlibMetadataStubBuilder] and [K2KlibMetadataDecompiler].
 * TODO: K2 shouldn't use descriptor renderer for building decompiled text.
 * Note that decompiled text is not used for building stubs in K2.
 * That's why in K2 it is important to preserve declaration order during deserialization to not get PSI vs. stubs mismatch.
 */


{ <EOL> contract { <EOL> callsInPlace ( action , InvocationKind . EXACTLY_ONCE ) <EOL> } <EOL> action ( ) <EOL> }


{ <EOL> val foo = Foo ( true ) <EOL> return foo . res <EOL> }


{ <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> <NUM_LIT> <EOL> val d1 : Double = <NUM_LIT> <EOL> val d2 : Double = <NUM_LIT> <EOL> val d3 : Double = <NUM_LIT> <EOL> val d4 : Double = <NUM_LIT> <EOL> val d5 : Double = <NUM_LIT> <EOL> }


override fun getLifetimeTokenFactory ( ) : KtLifetimeTokenFactory

{ <EOL> return KtAlwaysAccessibleLifetimeTokenFactory <EOL> }


fun serializeFields ( ) : String


{ <EOL> return """<STR_LIT>""" <EOL> }


fun < T > arrayToJson ( data : Iterable < T > ) : String

{ <EOL> return data . joinToString ( prefix = "<STR_LIT:[>" , postfix = "<STR_LIT:]>" ) { <EOL> if ( it is JsonSerializable ) it . toJson ( ) else it . toString ( ) <EOL> } <EOL> }


fun create ( data : JsonElement ) : T


fun parseBenchmarksArray ( data : JsonElement ) : List < BenchmarkResult >

{ <EOL> if ( data is JsonArray ) { <EOL> return data . jsonArray . map { <EOL> if ( MeanVarianceBenchmark . isMeanVarianceBenchmark ( it ) ) <EOL> MeanVarianceBenchmark . create ( it as JsonObject ) <EOL> else BenchmarkResult . create ( it as JsonObject ) <EOL> } <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


override fun create ( data : JsonElement ) : BenchmarksReport

{ <EOL> if ( data is JsonObject ) { <EOL> val env = Environment . create ( data . getRequiredField ( "<STR_LIT>" ) ) <EOL> val benchmarksObj = data . getRequiredField ( "<STR_LIT>" ) <EOL> val compiler = Compiler . create ( data . getRequiredField ( "<STR_LIT:kotlin>" ) ) <EOL> val buildNumberField = data . getOptionalField ( "<STR_LIT>" ) <EOL> val benchmarksList = parseBenchmarksArray ( benchmarksObj ) <EOL> val report = BenchmarksReport ( env , benchmarksList , compiler ) <EOL> buildNumberField ? . let { report . buildNumber = ( it as JsonLiteral ) . unquoted ( ) } <EOL> return report <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


private fun structBenchmarks ( benchmarksList : List < BenchmarkResult > )

= <EOL> benchmarksList . groupBy { it . name }


override fun serializeFields ( ) : String

{ <EOL> val buildNumberField = buildNumber ? . let { <EOL> """<STR_LIT>""" <EOL> } ? : "<STR_LIT>" <EOL> return """<STR_LIT>""" . trimIndent ( ) <EOL> }


fun merge ( other : BenchmarksReport ) : BenchmarksReport

{ <EOL> val mergedBenchmarks = HashMap ( benchmarks ) <EOL> other . benchmarks . forEach { <EOL> if ( it . key in mergedBenchmarks ) { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> mergedBenchmarks . putAll ( other . benchmarks ) <EOL> return BenchmarksReport ( env , mergedBenchmarks . flatMap { it . value } , compiler ) <EOL> }


operator fun plus ( other : BenchmarksReport ) : BenchmarksReport

{ <EOL> if ( compiler != other . compiler || env . machine != other . env . machine ) { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> return merge ( other ) <EOL> }


override fun create ( data : JsonElement ) : Compiler

{ <EOL> if ( data is JsonObject ) { <EOL> val backend = Backend . create ( data . getRequiredField ( "<STR_LIT>" ) ) <EOL> val kotlinVersion = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> return Compiler ( backend , kotlinVersion ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


fun backendTypeFromString ( s : String ) : BackendType ?

= BackendType . values ( ) . find { it . type == s }


override fun create ( data : JsonElement ) : Backend

{ <EOL> if ( data is JsonObject ) { <EOL> val typeElement = data . getRequiredField ( "<STR_LIT:type>" ) <EOL> if ( typeElement is JsonLiteral ) { <EOL> val type = backendTypeFromString ( typeElement . unquoted ( ) ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val version = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val flagsArray = data . getOptionalField ( "<STR_LIT>" ) <EOL> var flags : List < String > = emptyList ( ) <EOL> if ( flagsArray != null && flagsArray is JsonArray ) { <EOL> flags = flagsArray . jsonArray . map { it . toString ( ) } <EOL> } <EOL> return Backend ( type , version , flags ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


{ <EOL> val result = """<STR_LIT>""" <EOL> if ( flags . isEmpty ( ) ) { <EOL> return """<STR_LIT>""" <EOL> } else { <EOL> return """<STR_LIT>""" <EOL> } <EOL> }


override fun create ( data : JsonElement ) : Environment

{ <EOL> if ( data is JsonObject ) { <EOL> val machine = Machine . create ( data . getRequiredField ( "<STR_LIT>" ) ) <EOL> val jdk = JDKInstance . create ( data . getRequiredField ( "<STR_LIT>" ) ) <EOL> return Environment ( machine , jdk ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


override fun create ( data : JsonElement ) : Machine

{ <EOL> if ( data is JsonObject ) { <EOL> val cpu = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val os = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> return Machine ( cpu , os ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


override fun create ( data : JsonElement ) : JDKInstance

{ <EOL> if ( data is JsonObject ) { <EOL> val version = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val vendor = elementToString ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> return JDKInstance ( version , vendor ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


override fun create ( data : JsonElement ) : BenchmarkResult

{ <EOL> if ( data is JsonObject ) { <EOL> var name = elementToString ( data . getRequiredField ( "<STR_LIT:name>" ) , "<STR_LIT:name>" ) <EOL> val metricElement = data . getOptionalField ( "<STR_LIT>" ) <EOL> val metric = if ( metricElement != null && metricElement is JsonLiteral ) <EOL> metricFromString ( metricElement . unquoted ( ) ) ? : Metric . EXECUTION_TIME <EOL> else Metric . EXECUTION_TIME <EOL> val statusElement = data . getRequiredField ( "<STR_LIT>" ) <EOL> if ( statusElement is JsonLiteral ) { <EOL> val status = statusFromString ( statusElement . unquoted ( ) ) <EOL> ? : error ( "<STR_LIT>" ) <EOL> val score = elementToDouble ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val runtimeInUs = elementToDouble ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val repeat = elementToInt ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> val warmup = elementToInt ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> return BenchmarkResult ( name , status , score , metric , runtimeInUs , repeat , warmup ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


fun statusFromString ( s : String ) : Status ?

= Status . values ( ) . find { it . value == s }


fun metricFromString ( s : String ) : Metric ?

= Metric . values ( ) . find { it . value == s }


{ <EOL> return """<STR_LIT>""" <EOL> }


fun isMeanVarianceBenchmark ( data : JsonElement )

= data is JsonObject && data . getOptionalField ( "<STR_LIT>" ) != null


override fun create ( data : JsonElement ) : MeanVarianceBenchmark

{ <EOL> if ( data is JsonObject ) { <EOL> val baseBenchmark = BenchmarkResult . create ( data ) <EOL> val variance = elementToDouble ( data . getRequiredField ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> return MeanVarianceBenchmark ( baseBenchmark . name , baseBenchmark . status , baseBenchmark . score , baseBenchmark . metric , baseBenchmark . runtimeInUs , baseBenchmark . repeat , baseBenchmark . warmup , variance ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


override fun create ( data : JsonElement ) : BenchmarkWithStabilityState

{ <EOL> val parsedObject = BenchmarkResult . create ( data ) <EOL> if ( data is JsonObject ) { <EOL> val unstableElement = data . getOptionalField ( "<STR_LIT>" ) <EOL> val unstableFlag = if ( unstableElement != null && unstableElement is JsonPrimitive ) <EOL> unstableElement . boolean else false <EOL> return BenchmarkWithStabilityState ( parsedObject , unstableFlag ) <EOL> } else { <EOL> error ( "<STR_LIT>" ) <EOL> } <EOL> }


{ <EOL> val kProperty : KProperty0 < String > = :: publicField <EOL> checkAccessor ( kProperty , "<STR_LIT:1>" ) <EOL> checkAccessor ( :: internalField , "<STR_LIT:2>" ) <EOL> }


{ <EOL> testAccessors ( ) <EOL> return "<STR_LIT:OK>" <EOL> }


public fun < T , R > checkAccessor ( prop : KProperty0 < T > , value : R )

{ <EOL> assertEquals < Any ? > ( prop . get ( ) , value , "<STR_LIT>" ) <EOL> }


override fun < S : KtFunctionLikeSymbol > asSignature ( symbol : S ) : KtFunctionLikeSignature < S >

{ <EOL> return KtFe10FunctionLikeSignature ( symbol , symbol . returnType , symbol . receiverType , symbol . valueParameters . map { asSignature ( it ) } ) <EOL> }


override fun < S : KtVariableLikeSymbol > asSignature ( symbol : S ) : KtVariableLikeSignature < S >

{ <EOL> return KtFe10VariableLikeSignature ( symbol , symbol . returnType , symbol . receiverType ) <EOL> }


override fun isGenerallyOk ( declaration : FirDeclaration , context : CheckerContext , reporter : DiagnosticReporter ) : Boolean

{ <EOL> return if ( declaration . isLocalMember && context . containingDeclarations . lastOrNull ( ) !is FirScript ) { <EOL> reporter . reportOn ( declaration . source , FirErrors . NOT_YET_SUPPORTED_IN_INLINE , "<STR_LIT>" , context ) <EOL> false <EOL> } else { <EOL> true <EOL> } <EOL> }


override fun checkSuspendFunctionalParameterWithDefaultValue ( param : FirValueParameter , context : CheckerContext , reporter : DiagnosticReporter , )

{ <EOL> reporter . reportOn ( param . source , FirErrors . NOT_YET_SUPPORTED_IN_INLINE , "<STR_LIT>" , context ) <EOL> }


override fun checkFunctionalParametersWithInheritedDefaultValues ( function : FirSimpleFunction , context : CheckerContext , reporter : DiagnosticReporter , overriddenSymbols : List < FirCallableSymbol < FirCallableDeclaration > > , )

{ <EOL> val paramsWithDefaults = overriddenSymbols . flatMap { <EOL> if ( it !is FirFunctionSymbol < * > ) return@flatMap emptyList < Int > ( ) <EOL> it . valueParameterSymbols . mapIndexedNotNull { idx , param -> <EOL> idx . takeIf { param . hasDefaultValue } <EOL> } <EOL> } . toSet ( ) <EOL> function . valueParameters . forEachIndexed { idx , param -> <EOL> if ( param . defaultValue == null && paramsWithDefaults . contains ( idx ) ) { <EOL> reporter . reportOn ( param . source , FirErrors . NOT_YET_SUPPORTED_IN_INLINE , "<STR_LIT>" , context ) <EOL> } <EOL> } <EOL> }


override fun convertSqlTypeToColumnSchemaValue ( tableColumnMetadata : TableColumnMetadata ) : ColumnSchema ?

{ <EOL> if ( tableColumnMetadata . sqlTypeName == "<STR_LIT>" ) { <EOL> val kType = String :: class . createType ( nullable = tableColumnMetadata . isNullable ) <EOL> return ColumnSchema . Value ( kType ) <EOL> } <EOL> return null <EOL> }


override fun isSystemTable ( tableMetadata : TableMetadata ) : Boolean

{ <EOL> return tableMetadata . name . lowercase ( Locale . getDefault ( ) ) . contains ( "<STR_LIT>" ) || <EOL> tableMetadata . schemaName ? . lowercase ( Locale . getDefault ( ) ) ? . contains ( "<STR_LIT>" ) ? : false <EOL> }


override fun buildTableMetadata ( tables : ResultSet ) : TableMetadata

{ <EOL> return TableMetadata ( tables . getString ( "<STR_LIT>" ) , tables . getString ( "<STR_LIT>" ) , tables . getString ( "<STR_LIT>" ) ) <EOL> }


override fun convertSqlTypeToKType ( tableColumnMetadata : TableColumnMetadata ) : KType ?

{ <EOL> if ( tableColumnMetadata . sqlTypeName == "<STR_LIT>" ) { <EOL> return String :: class . createType ( nullable = tableColumnMetadata . isNullable ) <EOL> } <EOL> return null <EOL> }


= imageX * width + x


= imageY * height + y


fun getPreviewImageBounds ( sourceImageWidth : Int , sourceImageHeight : Int , viewWidth : Int , viewHeight : Int , scaleType : PreviewView . ScaleType ) : PreviewImageBounds

{ <EOL> val scale = if ( scaleType == PreviewView . ScaleType . FILL_START || scaleType == PreviewView . ScaleType . FILL_END || scaleType == PreviewView . ScaleType . FILL_CENTER ) { <EOL> max ( viewWidth . toFloat ( ) / sourceImageWidth , viewHeight . toFloat ( ) / sourceImageHeight ) <EOL> } else { <EOL> min ( viewWidth . toFloat ( ) / sourceImageWidth , viewHeight . toFloat ( ) / sourceImageHeight ) <EOL> } <EOL> val previewImageWidth = sourceImageWidth * scale <EOL> val previewImageHeight = sourceImageHeight * scale <EOL> return when ( scaleType ) { <EOL> PreviewView . ScaleType . FILL_START , PreviewView . ScaleType . FIT_START -> { <EOL> PreviewImageBounds ( <NUM_LIT> , <NUM_LIT> , previewImageWidth , previewImageHeight ) <EOL> } <EOL> PreviewView . ScaleType . FILL_END , PreviewView . ScaleType . FIT_END -> { <EOL> PreviewImageBounds ( viewWidth - previewImageWidth , viewHeight - previewImageHeight , previewImageWidth , previewImageHeight ) <EOL> } <EOL> else -> { <EOL> PreviewImageBounds ( viewWidth / <NUM_LIT:2> - previewImageWidth / <NUM_LIT:2> , viewHeight / <NUM_LIT:2> - previewImageHeight / <NUM_LIT:2> , previewImageWidth , previewImageHeight ) <EOL> } <EOL> } <EOL> }

/**
 * Calculate the location of the preview image top-left corner (relative to the component top-left corner)
 * and dimensions, to be used for displaying detected objects, for example with the [DetectorViewBase].
 *
 * When camera preview resolution differs from the dimensions of the [PreviewView] used to display camera input,
 * image is scaled and cropped or padded according to the provided [PreviewView.ScaleType]. Because of this,
 * in order to display detected objects on the [PreviewView], their coordinates need to be converted.
 * This method returns [PreviewImageBounds] object containing the necessary information to preform the conversion
 * from the image coordinate system to the view coordinate system.
 *
 * @param [sourceImageWidth] width of the image from the camera
 * @param [sourceImageHeight] height of the image from the camera
 * @param [viewWidth] width of the target [PreviewView]
 * @param [viewHeight] height of the target [PreviewView]
 * @param [scaleType] scaling option used in the target [PreviewView]
 *
 * @see Scale type
 */


operator fun Array < String > . get ( index1 : Int , index2 : Int )

= this [ index1 + index2 ]


operator fun Array < String > . set ( index1 : Int , index2 : Int , elem : String )

{ <EOL> this [ index1 + index2 ] = elem <EOL> }


{ <EOL> val s = Array < String > ( <NUM_LIT:1> , { "<STR_LIT>" } ) <EOL> s [ <NUM_LIT:1> , - <NUM_LIT:1> ] = "<STR_LIT:OK>" <EOL> return s [ - <NUM_LIT:2> , <NUM_LIT:2> ] <EOL> }


fun buildString ( builderAction : ( StringBuilder ) -> Unit , ) : String

{ <EOL> val sb = StringBuilder ( ) <EOL> builderAction ( sb ) <EOL> return sb . toString ( ) <EOL> }


{ <EOL> val s = buildString { <EOL> it . append ( "<STR_LIT>" ) <EOL> it . append ( "<STR_LIT>" ) <EOL> } <EOL> println ( s ) <EOL> }


@ Test <EOL> fun `test - transitive super interfaces` ( )

{ <EOL> val file = inlineSourceCodeAnalysis . createKtFile ( """<STR_LIT>""" . trimIndent ( ) ) <EOL> analyze ( file ) { <EOL> val foo = file . getClassOrFail ( "<STR_LIT:Foo>" ) <EOL> assertEquals ( listOf ( file . getClassOrFail ( "<STR_LIT:X>" ) , file . getClassOrFail ( "<STR_LIT>" ) ) , foo . getDeclaredSuperInterfaceSymbols ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun `test - super interface and super class` ( )

{ <EOL> val file = inlineSourceCodeAnalysis . createKtFile ( """<STR_LIT>""" . trimIndent ( ) ) <EOL> analyze ( file ) { <EOL> assertEquals ( listOf ( file . getClassOrFail ( "<STR_LIT:A>" ) , file . getClassOrFail ( "<STR_LIT:B>" ) ) , file . getClassOrFail ( "<STR_LIT:Foo>" ) . getDeclaredSuperInterfaceSymbols ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun `test - subclassing Any explicitly` ( )


public fun < T : Comparable < T > > DataColumn < T ? > . min ( ) : T

= minOrNull ( ) . suggestIfNull ( "<STR_LIT>" )


public fun < T : Comparable < T > > DataColumn < T ? > . minOrNull ( ) : T ?

= asSequence ( ) . filterNotNull ( ) . minOrNull ( )


public fun < T , R : Comparable < R > > DataColumn < T > . minBy ( selector : ( T ) -> R ) : T

= <EOL> minByOrNull ( selector ) . suggestIfNull ( "<STR_LIT>" )


public fun < T , R : Comparable < R > > DataColumn < T > . minByOrNull ( selector : ( T ) -> R ) : T ?

= values . minByOrNull ( selector )


public fun < T , R : Comparable < R > > DataColumn < T > . minOf ( selector : ( T ) -> R ) : R

= <EOL> minOfOrNull ( selector ) . suggestIfNull ( "<STR_LIT>" )


public fun < T , R : Comparable < R > > DataColumn < T > . minOfOrNull ( selector : ( T ) -> R ) : R ?

= values . minOfOrNull ( selector )


public fun AnyRow . rowMinOrNull ( ) : Any ?

= values ( ) . filterIsInstance < Comparable < * > > ( ) . minWithOrNull ( compareBy { it } )


= rowMinOrNull ( ) . suggestIfNull ( "<STR_LIT>" )


public inline fun < reified T : Comparable < T > > AnyRow . rowMinOfOrNull ( ) : T ?

= values ( ) . filterIsInstance < T > ( ) . minOrNull ( )


public inline fun < reified T : Comparable < T > > AnyRow . rowMinOf ( ) : T

= rowMinOfOrNull < T > ( ) . suggestIfNull ( "<STR_LIT>" )


public fun < T > DataFrame < T > . min ( ) : DataRow < T >

= minFor ( comparableColumns ( ) )


public fun < T , C : Comparable < C > > DataFrame < T > . minFor ( columns : ColumnsForAggregateSelector < T , C ? > ) : DataRow < T >

= <EOL> Aggregators . min . aggregateFor ( this , columns )


public fun < T > DataFrame < T > . minFor ( vararg columns : String ) : DataRow < T >

= minFor { columns . toComparableColumns ( ) }


public fun < T , C : Comparable < C > > DataFrame < T > . minFor ( vararg columns : ColumnReference < C ? > ) : DataRow < T >

= <EOL> minFor { columns . toColumnSet ( ) }


public fun < T , C : Comparable < C > > DataFrame < T > . minFor ( vararg columns : KProperty < C ? > ) : DataRow < T >


public fun < T , C : Comparable < C > > DataFrame < T > . min ( columns : ColumnsSelector < T , C ? > ) : C

= <EOL> minOrNull ( columns ) . suggestIfNull ( "<STR_LIT>" )