/* Ċ Ġ* ĠCopyright Ġ 2 0 1 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . Ġand ĠKotlin ĠProgramming ĠLanguage Ġcontributors . Ċ Ġ* ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe Ġlicense / LICENSE . txt Ġfile . Ċ Ġ*/ Ċ Ċ package Ġorg . jetbrains . kotlin . fir . resolve . calls Ċ Ċ import Ġorg . jetbrains . kotlin . descriptors . Class Kind Ċ import Ġorg . jetbrains . kotlin . descriptors . Modal ity Ċ import Ġorg . jetbrains . kotlin . descriptors . is Class Ċ import Ġorg . jetbrains . kotlin . fir . declarations . F ir Callable Declaration Ċ import Ġorg . jetbrains . kotlin . fir . declarations . F ir Variable Ċ import Ġorg . jetbrains . kotlin . fir . declarations . utils . modal ity Ċ import Ġorg . jetbrains . kotlin . fir . dispatch Receiver Class OrNull Ċ import Ġorg . jetbrains . kotlin . fir . expressions . F ir Function Call Ċ import Ġorg . jetbrains . kotlin . fir . expressions . F ir Qualified Access Ċ import Ġorg . jetbrains . kotlin . fir . references . F ir Named Reference Ċ import Ġorg . jetbrains . kotlin . fir . resolve . Body Resolve Components Ċ import Ġorg . jetbrains . kotlin . fir . resolve . scope Ċ import Ġorg . jetbrains . kotlin . fir . resolve . to Symbol Ċ import Ġorg . jetbrains . kotlin . fir . scopes . Fake Override Type Calculator Ċ import Ġorg . jetbrains . kotlin . fir . symbols . impl . F ir Regular Class Symbol Ċ import Ġorg . jetbrains . kotlin . fir . types .* Ċ import Ġorg . jetbrains . kotlin . fir . unwrap Fake Overrides Ċ import Ġorg . jetbrains . kotlin . name . Name Ċ import Ġorg . jetbrains . kotlin . name . Standard Class Ids Ċ import Ġorg . jetbrains . kotlin . types . Abstract Type Checker Ċ import Ġorg . jetbrains . kotlin . utils . Smart List Ċ import Ġorg . jetbrains . kotlin . utils . add If NotNull Ċ Ċ fun ĠBody Resolve Components . find Types For Super Candidates ( ĊĠĠĠ Ġsuper Type Refs : ĠList < F ir Type Ref >, ĊĠĠĠ Ġcontaining Call : ĠF ir Qualified Access , Ċ ): ĠList < Con e Kotlin Type > Ġ{ ĊĠĠĠ Ġval Ġsup ert ypes Ġ= Ġsuper Type Refs . map Ġ{ Ġ( it Ġas ĠF ir Resolved Type Ref ). type Ġ} ĊĠĠĠ Ġval Ġis Method Of Any Ġ= Ġcontaining Call Ġis ĠF ir Function Call Ġ&& Ġis Calling Method Of Any ( containing Call ) ĊĠĠĠ Ġif Ġ( sup ert ypes . size Ġ<= Ġ 1 Ġ&& Ġ! is Method Of Any ) Ġreturn Ġsup ert ypes ĊĊĠĠĠ Ġreturn Ġwhen Ġ( containing Call ) Ġ{ ĊĠĠĠĠĠĠĠ Ġis ĠF ir Function Call Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcal lee Name Ġ= Ġcontaining Call . callee Reference . name ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( is Method Of Any ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresolve Sup ert ypes For Method Of Any ( sup ert ypes , Ġcal lee Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresolve Sup ert ypes By Cal lee Name ( sup ert ypes , Ġcal lee Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresolve Sup ert ypes By PropertyName ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsup ert ypes , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( containing Call . callee Reference Ġas ? ĠF ir Named Reference )?. name Ġ?: Ġreturn Ġempty List () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġval ĠAR ITY _ OF _ METHO DS _ OF _ ANY Ġ= Ġhash Map Of (" hashCode " Ġto Ġ 0 , Ġ" equals " Ġto Ġ 1 , Ġ" toString " Ġto Ġ 0 ) Ċ Ċ private Ġfun Ġis Calling Method Of Any ( call Expression : ĠF ir Function Call ): ĠBoolean Ġ= ĊĠĠĠ ĠAR ITY _ OF _ METHO DS _ OF _ ANY . getOrElse ( call Expression . callee Reference . name . asString ()) Ġ{ Ġ- 1 Ġ} Ġ== Ġcall Expression . argument List . arguments . size Ċ Ċ private Ġfun ĠBody Resolve Components . resolve Sup ert ypes For Method Of Any ( ĊĠĠĠ Ġsup ert ypes : ĠCollection < Con e Kotlin Type >, ĊĠĠĠ Ġcal lee Name : ĠName Ċ ): ĠList < Con e Kotlin Type > Ġ{ ĊĠĠĠ Ġval Ġtypes With Concrete Override Ġ= Ġresolve Sup ert ypes By Members ( sup ert ypes , Ġallow Non Concrete Interface Members Ġ= Ġfalse ) Ġ{ ĊĠĠĠĠĠĠĠ Ġget Function Members ( it , Ġcal lee Name ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġtypes With Concrete Override . if Empty Ġ{ ĊĠĠĠĠĠĠĠ ĠlistOf ( session . builtin Types . any Type . type ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠBody Resolve Components . resolve Sup ert ypes By Cal lee Name ( ĊĠĠĠ Ġsup ert ypes : ĠCollection < Con e Kotlin Type >, ĊĠĠĠ Ġcal lee Name : ĠName Ċ ): ĠList < Con e Kotlin Type > Ġ= ĊĠĠĠ Ġresolve Sup ert ypes By Members ( sup ert ypes , Ġallow Non Concrete Interface Members Ġ= Ġtrue ) Ġ{ ĊĠĠĠĠĠĠĠ Ġget Function Members ( it , Ġcal lee Name ) Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠgetProperty Members ( it , Ġcal lee Name ) ĊĠĠĠ Ġ} Ċ Ċ private Ġfun ĠBody Resolve Components . resolve Sup ert ypes By PropertyName ( ĊĠĠĠ Ġsup ert ypes : ĠCollection < Con e Kotlin Type >, ĊĠĠĠ ĠpropertyName : ĠName Ċ ): ĠList < Con e Kotlin Type > Ġ= ĊĠĠĠ Ġresolve Sup ert ypes By Members ( sup ert ypes , Ġallow Non Concrete Interface Members Ġ= Ġtrue ) Ġ{ ĊĠĠĠĠĠĠĠ ĠgetProperty Members ( it , ĠpropertyName ) ĊĠĠĠ Ġ} Ċ Ċ private Ġinline Ġfun ĠBody Resolve Components . resolve Sup ert ypes By Members ( ĊĠĠĠ Ġsup ert ypes : ĠCollection < Con e Kotlin Type >, ĊĠĠĠ Ġallow Non Concrete Interface Members : ĠBoolean , ĊĠĠĠ Ġget Members : Ġ( Con e Kotlin Type ) Ġ-> ĠCollection < F ir Callable Declaration > Ċ ): ĠList < Con e Kotlin Type > Ġ{ ĊĠĠĠ Ġval Ġtypes With Concrete Members Ġ= ĠSmart List < Con e Kotlin Type >() ĊĠĠĠ Ġval Ġtypes With Non Concrete Members Ġ= ĠSmart List < Con e Kotlin Type >() ĊĊĠĠĠ Ġfor Ġ( sup ertype Ġin Ġsup ert ypes ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmembers Ġ= Ġget Members ( sup ertype ) ĊĠĠĠĠĠĠĠ Ġif Ġ( members . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( members . any Ġ{ Ġis Concrete Member ( sup ertype , Ġit ) Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtypes With Concrete Members . add ( sup ertype ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġif Ġ( members . any Ġ{ Ġit . dispatch Receiver Type ?. is Any Ġ== Ġfalse Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtypes With Non Concrete Members . add ( sup ertype ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġtypes With Concrete Members . removeAll Ġ{ Ġtype With Concrete Member Ġ-> ĊĠĠĠĠĠĠĠ Ġtypes With Non Concrete Members . any Ġ{ Ġtype With Non Concrete Member Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAbstract Type Checker . is Subtype Of ( session . type Context , Ġsub Type Ġ= Ġtype With Non Concrete Member , Ġsuper Type Ġ= Ġtype With Concrete Member ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġwhen Ġ{ ĊĠĠĠĠĠĠĠ Ġtypes With Concrete Members . isNotEmpty () Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtypes With Concrete Members ĊĠĠĠĠĠĠĠ Ġallow Non Concrete Interface Members Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtypes With Non Concrete Members ĊĠĠĠĠĠĠĠ Ġelse Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtypes With Non Concrete Members . filter Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠWe Ġaren 't Ġinterested Ġin Ġobjects Ġor Ġenum Ġclasses Ġhere ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġ( objects Ġcan 't Ġbe Ġinherited , Ġenum Ġclasses Ġcannot Ġhave Ġspecific Ġequals / hashCode ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit Ġis ĠC one Class Like Type Ġ&& Ġ( it . lookup Tag . to Symbol ( session ) Ġas ? ĠF ir Regular Class Symbol )?. class Kind ?. is Class Ġ== Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ Opt In ( Experimental Std lib Api :: class ) Ċ private Ġfun ĠBody Resolve Components . get Function Members ( type : ĠC one Kotlin Type , Ġname : ĠName ): ĠCollection < F ir Callable Declaration > Ġ= ĊĠĠĠ Ġbuild List Ġ{ ĊĠĠĠĠĠĠĠ Ġtype . scope ( session , Ġscope Session , ĠFake Override Type Calculator . Do Nothing )?. process Functions ByName ( name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd ( it . fir ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ @ Opt In ( Experimental Std lib Api :: class ) Ċ private Ġfun ĠBody Resolve Components . getProperty Members ( type : ĠC one Kotlin Type , Ġname : ĠName ): ĠCollection < F ir Callable Declaration > Ġ= ĊĠĠĠ Ġbuild List Ġ{ ĊĠĠĠĠĠĠĠ Ġtype . scope ( session , Ġscope Session , ĠFake Override Type Calculator . Do Nothing )?. process Properties ByName ( name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd If NotNull ( it . fir Ġas ? ĠF ir Variable ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊ Ċ private Ġfun ĠBody Resolve Components . is Concrete Member ( sup ertype : ĠC one Kotlin Type , Ġmember : ĠF ir Callable Declaration ): ĠBoolean Ġ{ ĊĠĠĠ Ġ// Ġ" Concrete Ġmember " Ġis Ġa Ġfunction Ġor Ġa Ġproperty Ġthat Ġis Ġnot Ġabstract , ĊĠĠĠ Ġ// Ġand Ġis Ġnot Ġan Ġimplicit Ġfake Ġoverride Ġfor Ġa Ġmethod Ġof ĠAny Ġon Ġan Ġinterface . ĊĊĠĠĠ Ġif Ġ( member . modal ity Ġ== ĠMod ality . AB STR ACT ) ĊĠĠĠĠĠĠĠ Ġreturn Ġfalse ĊĊĠĠĠ Ġval Ġclass Symbol Ġ= ĊĠĠĠĠĠĠĠ Ġ( sup ertype Ġas ? ĠC one Class Like Type )?. lookup Tag ?. to Symbol ( session ) Ġas ? ĠF ir Regular Class Symbol Ġ?: Ġreturn Ġtrue ĊĠĠĠ Ġif Ġ( class Symbol . fir . class Kind Ġ!= ĠClass Kind . INTERFACE ) Ġreturn Ġtrue ĊĠĠĠ Ġreturn Ġmember . symbol . unwrap Fake Overrides (). dispatch Receiver Class OrNull ()?. class Id Ġ!= ĠStandard Class Ids . Any Ċ } Ċ