/* Ċ Ġ* ĠCopyright Ġ 2 0 1 0 - 2 0 1 9 Ġ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 . util Ċ Ċ import Ġorg . jetbrains . kotlin . descriptors .* Ċ import Ġorg . jetbrains . kotlin . cfg . containing Declaration For Pseudo code Ċ import Ġorg . jetbrains . kotlin . lexer . Kt Tokens Ċ import Ġorg . jetbrains . kotlin . psi . Kt Class Ċ import Ġorg . jetbrains . kotlin . psi . Kt Declaration Ċ import Ġorg . jetbrains . kotlin . psi . Kt Element Ċ import Ġorg . jetbrains . kotlin . psi . Kt Psi Util Ċ import Ġorg . jetbrains . kotlin . resolve . Descriptor Utils Ċ import Ġorg . jetbrains . kotlin . resolve . Over riding Util Ċ import Ġorg . jetbrains . kotlin . resolve . calls . call Resolver Util . is Or Overrides Synt hesized Ċ import Ġorg . jetbrains . kotlin . resolve . descriptor Util . is Type Ref inement Enabled Ċ import Ġorg . jetbrains . kotlin . resolve . descriptor Util . module Ċ Ċ fun ĠK t Element . containing Non Local Declaration (): ĠK t Declaration ? Ġ{ ĊĠĠĠ Ġvar Ġcontainer Ġ= Ġthis . containing Declaration For Pseudo code ĊĠĠĠ Ġwhile Ġ( container Ġ!= Ġnull Ġ&& ĠK t Psi Util . is Local ( container )) Ġ{ ĊĠĠĠĠĠĠĠ Ġcontainer Ġ= Ġcontainer . containing Declaration For Pseudo code ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġcontainer Ċ } Ċ Ċ val ĠK t Declaration . is Ord inary Class ĊĠĠĠ Ġget () Ġ= Ġthis Ġis ĠK t Class Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ! this . has Modifier ( Kt Tokens . INLINE _ KEYWORD ) Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ! this . is Annotation () Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ! this . is Interface () Ċ Ċ val ĠK t Declaration . is Annotated Ġget () Ġ= Ġthis . annotation Entries . isNotEmpty () Ċ Ċ /** Ċ Ġ* ĠGiven Ġa Ġfake Ġoverride , Ġreturns Ġan Ġoverridden Ġnon - abstract Ġfunction Ġfrom Ġan Ġinterface Ġwhich Ġis Ġthe Ġactual Ġimplementation Ġof Ġthis Ġfunction Ċ Ġ* Ġthat Ġshould Ġbe Ġcalled Ġwhen Ġthe Ġgiven Ġfake Ġoverride Ġis Ġcalled . Ċ Ġ*/ Ċ fun Ġfind Implementation From Interface ( descriptor : ĠCallable Member Descriptor ): ĠCallable Member Descriptor ? Ġ{ ĊĠĠĠ Ġval Ġoverridden Ġ= ĠOver riding Util . get Over ridden Declarations ( descriptor ) ĊĠĠĠ Ġval Ġfiltered Ġ= ĠOver riding Util . filter Out Over ridden ( over ridden ) ĊĊĠĠĠ Ġval Ġresult Ġ= Ġfiltered . first OrNull Ġ{ Ġit . modal ity Ġ!= ĠMod ality . AB STR ACT Ġ} Ġ?: Ġreturn Ġnull ĊĊĠĠĠ Ġif Ġ( Descriptor Utils . is Class Or Enum Class ( result . containing Declaration )) Ġreturn Ġnull ĊĊĠĠĠ Ġreturn Ġresult Ċ } Ċ Ċ /** Ċ Ġ* ĠGiven Ġa Ġfake Ġoverride Ġin Ġa Ġclass , Ġreturns Ġan Ġoverridden Ġdeclaration Ġwith Ġimplementation Ġin Ġtrait , Ġsuch Ġthat Ġa Ġmethod Ġdeleg ating Ġto Ġthat Ċ Ġ* Ġtrait Ġimplementation Ġshould Ġbe Ġgenerated Ġinto Ġthe Ġclass Ġcontaining Ġthe Ġfake Ġoverride ; Ġor Ġnull Ġif Ġthe Ġgiven Ġfunction Ġis Ġnot Ġa Ġfake Ċ Ġ* Ġoverride Ġof Ġany Ġtrait Ġimplementation Ġor Ġsuch Ġmethod Ġwas Ġalready Ġgenerated Ġinto Ġthe Ġsuperclass Ġor Ġis Ġa Ġmethod Ġfrom ĠAny . Ċ Ġ*/ Ċ @ Jvm Over loads Ċ fun Ġfind Interface Implementation ( descriptor : ĠCallable Member Descriptor , Ġreturn Impl Not Delegate : ĠBoolean Ġ= Ġfalse ): ĠCallable Member Descriptor ? Ġ{ ĊĠĠĠ Ġif Ġ( descriptor . kind . is Real ) Ġreturn Ġnull ĊĠĠĠ Ġif Ġ( is Or Overrides Synt hesized ( descriptor )) Ġreturn Ġnull ĊĊĠĠĠ Ġval Ġimplementation Ġ= Ġfind Implementation From Interface ( descriptor ) Ġ?: Ġreturn Ġnull ĊĠĠĠ Ġval Ġimmediate Concrete Super Ġ= Ġfirst Super Method From Kotlin ( descriptor , Ġimplementation ) Ġ?: Ġreturn Ġnull ĊĊĠĠĠ Ġif Ġ(! Descriptor Utils . is Interface ( immediate Concrete Super . containing Declaration )) Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠIf Ġthis Ġimplementation Ġis Ġalready Ġgenerated Ġinto Ġthe Ġsuperclass , Ġwe Ġneed Ġnot Ġgenerate Ġit Ġagain , Ġit 'll Ġbe Ġinherited ĊĠĠĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġif Ġ( return Impl Not Delegate ) Ġimplementation Ġelse Ġimmediate Concrete Super Ċ } Ċ Ċ /** Ċ Ġ* ĠGiven Ġa Ġfake Ġoverride Ġand Ġits Ġimplementation Ġ( non - abstract Ġdeclaration ) Ġsomewhere Ġin Ġsup ert ypes , Ċ Ġ* Ġreturns Ġthe Ġfirst Ġimmediate Ġsuper Ġfunction Ġof Ġthe Ġgiven Ġfake Ġoverride Ġwhich Ġoverrides Ġthat Ġimplementation . Ċ Ġ* ĠThe Ġreturned Ġfunction Ġshould Ġbe Ġcalled Ġfrom ĠT Impl - brid ges Ġgenerated Ġfor Ġthe Ġgiven Ġfake Ġoverride . Ċ Ġ*/ Ċ fun Ġfirst Super Method From Kotlin ( ĊĠĠĠ Ġdescriptor : ĠCallable Member Descriptor , ĊĠĠĠ Ġimplementation : ĠCallable Member Descriptor Ċ ): ĠCallable Member Descriptor ? Ġ{ ĊĠĠĠ Ġreturn Ġdescriptor . over ridden Descriptors . first OrNull Ġ{ Ġoverridden Ġ-> ĊĠĠĠĠĠĠĠ Ġoverridden . modal ity Ġ!= ĠMod ality . AB STR ACT Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( over ridden Ġ== Ġimplementation Ġ|| ĠOver riding Util . overrides ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverridden , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġimplementation , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverridden . module . is Type Ref inement Enabled (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} Ċ } ĊĊ Ċ fun Ġget Non Private Trait Members For Deleg ation ( ĊĠĠĠ Ġdescriptor : ĠClass Descriptor , ĊĠĠĠ Ġreturn Impl Not Delegate : ĠBoolean Ġ= Ġfalse , Ċ ): ĠMap < Callable Member Descriptor , ĠCallable Member Descriptor > Ġ{ ĊĠĠĠ Ġval Ġresult Ġ= Ġlinked Map Of < Callable Member Descriptor , ĠCallable Member Descriptor >() ĊĠĠĠ Ġfor Ġ( declaration Ġin ĠDescriptor Utils . getAll Descriptors ( descriptor . default Type . member Scope )) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( declaration Ġ! is ĠCallable Member Descriptor ) Ġcontinue ĊĠĠĠĠĠĠĠ Ġresult [ declaration ] Ġ= Ġget Non Private Trait Members For Deleg ation ( declaration , Ġreturn Impl Not Delegate ) Ġ?: Ġcontinue ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġresult Ċ } Ċ Ċ fun Ġget Non Private Trait Members For Deleg ation ( ĊĠĠĠ Ġdescriptor : ĠCallable Member Descriptor , ĊĠĠĠ Ġreturn Impl Not Delegate : ĠBoolean Ġ= Ġfalse , Ċ ): ĠCallable Member Descriptor ? Ġ{ ĊĠĠĠ Ġval Ġtrait Member Ġ= Ġfind Interface Implementation ( descriptor , Ġreturn Impl Not Delegate ) ĊĠĠĠ Ġif Ġ( trait Member Ġ== Ġnull Ġ|| ĊĠĠĠĠĠĠĠ ĠDescriptor Vis ibilities . is Private ( trait Member . visibility ) Ġ|| ĊĠĠĠĠĠĠĠ Ġtrait Member . visibility Ġ== ĠDescriptor Vis ibilities . IN VISIBLE _ FA KE ĊĠĠĠ Ġ) Ġreturn Ġnull ĊĠĠĠ Ġreturn Ġtrait Member Ċ } Ċ