/* Ċ Ġ* Ġ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 . Ċ Ġ*/ Ċ Ċ @ file : Jvm Name (" Resolution Utils ") Ċ Ċ package Ġorg . jetbrains . kotlin . idea . cache s . resolve Ċ Ċ import Ġorg . jetbrains . kotlin . analyzer . Analysis Result Ċ import Ġorg . jetbrains . kotlin . cache s . resolve . Kotlin Cache Service Ċ import Ġorg . jetbrains . kotlin . descriptors . Declaration Descriptor Ċ import Ġorg . jetbrains . kotlin . descriptors . Module Descriptor Ċ import Ġorg . jetbrains . kotlin . descriptors . annotations . Annotation Descriptor Ċ import Ġorg . jetbrains . kotlin . idea . Frontend Internals Ċ import Ġorg . jetbrains . kotlin . diagnostics . Diagnostic Ċ import Ġorg . jetbrains . kotlin . idea . resolve . Resolution Facade Ċ import Ġorg . jetbrains . kotlin . name . Fq Name Ċ import Ġorg . jetbrains . kotlin . psi .* Ċ import Ġorg . jetbrains . kotlin . resolve . Binding Context Ċ import Ġorg . jetbrains . kotlin . resolve . Binding Trace Context Ċ import Ġorg . jetbrains . kotlin . resolve . Import Path Ċ import Ġorg . jetbrains . kotlin . resolve . Qualified Expression Resolver Ċ import Ġorg . jetbrains . kotlin . resolve . lazy . Body Resolve Mode Ċ Ċ fun ĠK t Element . get Resolution Facade (): ĠResolution Facade Ġ= ĊĠĠĠ ĠKotlin Cache Service . getInstance ( project ). get Resolution Facade ( listOf ( this )) Ċ Ċ /** Ċ Ġ* ĠFor Ġlocal Ġdeclarations Ġis Ġequivalent Ġto Ġunsafe Resolve To Descriptor ( body Resolve Mode ) Ċ Ġ* Ċ Ġ* ĠBut Ġfor Ġnon - local Ġdeclarations Ġit Ġignores Ġbody Resolve Mode Ġand Ġuses ĠLazy Declaration Resolver Ġdirectly Ċ Ġ*/ Ċ @ Deprecated ( ĊĠĠĠ Ġmessage Ġ= Ġ" This Ġfunction Ġhas Ġun clear Ġsemantics . ĠPlease Ġuse Ġeither Ġunsafe Resolve To Descriptor Ġor Ġresolve To Descriptor If Any Ġinstead ", ĊĠĠĠ Ġreplace With Ġ= ĠReplace With (" unsafe Resolve To Descriptor ") Ċ ) Ċ fun ĠK t Declaration . resolve To Descriptor ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . FULL ): ĠDeclaration Descriptor Ġ= ĊĠĠĠ Ġget Resolution Facade (). resolve To Descriptor ( this , Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* ĠThis Ġfunction Ġthrows Ġexception Ġwhen Ġresolve To Descriptor If Any Ġreturns Ġnull , Ġotherwise Ġworks Ġequivalent ly . Ċ Ġ* Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Declaration . unsafe Resolve To Descriptor ( ĊĠĠĠ Ġbody Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . FULL Ċ ): ĠDeclaration Descriptor Ġ= ĊĠĠĠ Ġunsafe Resolve To Descriptor ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* ĠThis Ġfunction Ġfirst Ġuses Ġdeclaration Ġresolver s Ġto Ġresolve Ġthis Ġdeclaration Ġand / or Ġadditional Ġdeclarations Ġ( e . g . Ġits Ġparent ), Ċ Ġ* Ġand Ġthen Ġtakes Ġthe Ġrelevant Ġdescriptor Ġfrom Ġbinding Ġcontext . Ċ Ġ* ĠThe Ġexact Ġset Ġof Ġdeclarations Ġto Ġresolve Ġdepends Ġon Ġbody Resolve Mode Ċ Ġ* Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Declaration . resolve To Descriptor If Any ( ĊĠĠĠ Ġbody Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL Ċ ): ĠDeclaration Descriptor ? Ġ= ĊĠĠĠ Ġresolve To Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Class Or Object . resolve To Descriptor If Any ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL ) Ġ= ĊĠĠĠ Ġresolve To Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Named Function . resolve To Descriptor If Any ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL ) Ġ= ĊĠĠĠ Ġresolve To Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Property . resolve To Descriptor If Any ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL ) Ġ= ĊĠĠĠ Ġresolve To Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Parameter . resolve To Parameter Descriptor If Any ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL ) Ġ= ĊĠĠĠ Ġresolve To Parameter Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Element . resolve To Call ( body Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL ) Ġ= ĊĠĠĠ Ġresolve To Call ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ fun ĠK t File . resolve Import Reference ( fq Name : ĠF q Name ): ĠCollection < Declaration Descriptor > Ġ{ ĊĠĠĠ Ġval Ġfac ade Ġ= Ġget Resolution Facade () ĊĠĠĠ Ġreturn Ġfac ade . resolve Import Reference ( facade . module Descriptor , Ġfq Name ) Ċ } Ċ Ċ fun ĠK t Annotation Entry . resolve To Descriptor If Any ( ĊĠĠĠ Ġbody Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . PAR TIAL _ NO _ AD DITION AL Ċ ): ĠAnnotation Descriptor ? Ġ= ĊĠĠĠ Ġresolve To Descriptor If Any ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ // ĠThis Ġand Ġnext Ġfunctions Ġare Ġused Ġfor Ġ' normal ' Ġelement Ġanalysis Ċ // ĠThis Ġanalysis Ġ* should * Ġprovide Ġall Ġinformation Ġextract able Ġfrom Ġthis ĠK t Element Ġexcept : Ċ // Ġ- Ġfor Ġdeclarations , Ġit Ġdoes Ġnot Ġanalyze Ġtheir Ġbodies Ċ // Ġ- Ġfor Ġclasses , Ġit Ġdoes Ġnot Ġanalyze Ġtheir Ġcontent Ċ // Ġ- Ġfor Ġmember Ġ/ Ġtop - level Ġproperties , Ġit Ġdoes Ġnot Ġanalyze Ġinitial izers Ġ/ Ġaccessors Ċ // ĠThis Ġinformation Ġincludes Ġrelated Ġdescriptors , Ġresolved Ġcalls Ġ( but Ġnot Ġinside Ġbody , Ġsee Ġabove !) Ċ // Ġand Ġmany Ġother Ġbinding Ġcontext Ġslices . Ċ // ĠNorm ally , Ġthe Ġfunction Ġis Ġused Ġon Ġlocal Ġdeclarations Ġor Ġstatements Ġ/ Ġexpressions Ċ // ĠAny Ġusage Ġon Ġnon - local Ġdeclaration Ġis Ġa Ġbit Ġsus pic ious , Ċ // Ġconsider Ġreplacing Ġit Ġwith Ġresolve To Descriptor If Any Ġand Ċ // Ġremember Ġthat Ġbody Ġ/ Ġcontent Ġis Ġnot Ġanalyzed ; Ċ // Ġif Ġit 's Ġnecessary , Ġuse Ġanalyze With Content () Ċ // Ċ // ĠIf Ġyou Ġneed Ġdiagnostics Ġin Ġresult Ġcontext , Ġuse ĠBody Resolve Mode . PAR TIAL _ WITH _ DIAG NO ST ICS . Ċ // ĠBody Resolve Mode . FULL Ġanaly zes Ġall Ġstatements Ġon Ġthe Ġlevel Ġof ĠK t Element Ġand Ġabove . Ċ // ĠBody Resolve Mode . PAR TIAL Ġanaly zes Ġonly Ġstatements Ġnecessary Ġfor Ġthis ĠK t Element Ġprecise Ġanalysis . Ċ // Ċ // ĠSee Ġalso : ĠResolve Session For B odies , ĠResolve Element Cache Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ @ Jvm Over loads Ċ fun ĠK t Element . analyze ( ĊĠĠĠ Ġbody Resolve Mode : ĠBody Resolve Mode Ġ= ĠBody Resolve Mode . FULL Ċ ): ĠBinding Context Ġ= ĊĠĠĠ Ġanalyze ( get Resolution Facade (), Ġbody Resolve Mode ) Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Element . analyze AndGet Result (): ĠAnalysis Result Ġ{ ĊĠĠĠ Ġreturn Ġanalyze AndGet Result ( get Resolution Facade ()) Ċ } Ċ Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Element . analyze With Content AndGet Result (): ĠAnalysis Result Ġ= ĊĠĠĠ Ġanalyze With Content AndGet Result ( get Resolution Facade ()) Ċ Ċ fun ĠK t Element . find Module Descriptor (): ĠModule Descriptor Ġ= Ġget Resolution Facade (). module Descriptor Ċ Ċ // ĠThis Ġfunction Ġis Ġused Ġon Ġdeclarations Ġto Ġmake Ġanalysis Ġnot Ġonly Ġdeclaration Ġitself Ġbut Ġalso Ġit Ġcontent : Ċ // Ġbody Ġfor Ġdeclaration Ġwith Ġbody , Ġinitializer Ġ& Ġaccessors Ġfor Ġproperties Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ fun ĠK t Declaration . analyze With Content (): ĠBinding Context Ġ= ĊĠĠĠ Ġanalyze With Content ( get Resolution Facade ()) Ċ Ċ // ĠThis Ġfunction Ġis Ġused Ġto Ġmake Ġfull Ġanalysis Ġof Ġdeclaration Ġcontainer . Ċ // ĠAll Ġits Ġdeclarations , Ġincluding Ġtheir Ġcontent Ġ( see Ġabove ), Ġare Ġanalyzed . Ċ /** Ċ Ġ* Ġ** Please , Ġuse Ġoverload Ġwith Ġproviding Ġresolution Facade Ġfor Ġstable Ġresults Ġof Ġsubsequent Ġcalls ** Ċ Ġ*/ Ċ inline Ġfun Ġ< re ified ĠT > ĠT . analyze With Content (): ĠBinding Context Ġwhere ĠT Ġ: ĠK t Declaration Container , ĠT Ġ: ĠK t Element Ġ= ĊĠĠĠ Ġanalyze With Content ( get Resolution Facade ()) Ċ Ċ /** Ċ Ġ* ĠThis Ġfunction Ġis Ġexpected Ġto Ġproduce Ġthe Ġsame Ġresult Ġas Ġcompiler Ġfor Ġthe Ġwhole Ġfile Ġcontent Ġ( including Ġdiagnostics , Ċ Ġ* Ġtrace Ġslices , Ġdescriptors , Ġetc .). Ċ Ġ* Ċ Ġ* ĠIt 's Ġnot Ġrecommended Ġto Ġcall Ġthis Ġfunction Ġwithout Ġreal Ġneed . Ċ Ġ* Ċ Ġ* Ġ@ ref Ġ[ Kotlin Cache Service ] Ċ Ġ* Ġ@ ref Ġ[ org . jetbrains . kotlin . idea . cache s . resolve . Per File Analysis Cache ] Ċ Ġ*/ Ċ fun ĠK t File . analyze With All Compiler Checks ( var arg Ġextra Files : ĠK t File ): ĠAnalysis Result Ġ= ĊĠĠĠ Ġthis . analyze With All Compiler Checks ( null , Ġ* extra Files ) Ċ Ċ fun ĠK t File . analyze With All Compiler Checks ( callback : Ġ(( Diagnostic ) Ġ-> ĠUnit )? , Ġvar arg Ġextra Files : ĠK t File ): ĠAnalysis Result Ġ= ĊĠĠĠ ĠKotlin Cache Service . getInstance ( project ). get Resolution Facade ( listOf ( this ) Ġ+ Ġextra Files . toList ()) ĊĠĠĠĠĠĠĠ Ġ. analyze With All Compiler Checks ( listOf ( this ), Ġcallback ) Ċ Ċ /** Ċ Ġ* ĠThis Ġfunction Ġis Ġexpected Ġto Ġproduce Ġthe Ġsame Ġresult Ġas Ġcompiler Ġfor Ġthe Ġgiven Ġelement Ġand Ġits Ġchildren Ġ( including Ġdiagnostics , Ċ Ġ* Ġtrace Ġslices , Ġdescriptors , Ġetc .). ĠFor Ġsome Ġexpression Ġelement Ġit Ġactually Ġperforms Ġanalyze Ġfor Ġsome Ġparent Ġ( usually Ġdeclaration ). Ċ Ġ* Ċ Ġ* ĠIt 's Ġnot Ġrecommended Ġto Ġcall Ġthis Ġfunction Ġwithout Ġreal Ġneed . Ċ Ġ* Ċ Ġ* ĠNB : Ġfor Ġstatements Ġ/ Ġexpressions , Ġusually Ġshould Ġbe Ġreplaced Ġwith Ġanalyze (), Ċ Ġ* Ġfor Ġdeclarations , Ġanalyze With Content () Ġwill Ġdo Ġwhat Ġyou Ġwant . Ċ Ġ* Ċ Ġ* Ġ@ ref Ġ[ Kotlin Cache Service ] Ċ Ġ* Ġ@ ref Ġ[ org . jetbrains . kotlin . idea . cache s . resolve . Per File Analysis Cache ] Ċ Ġ*/ Ċ @ Deprecated ( ĊĠĠĠ Ġ" Use Ġeither ĠK t File . analyze With All Compiler Checks () Ġor ĠK t Element . analyze AndGet Result ()", ĊĠĠĠ ĠReplace With (" analyze AndGet Result () ") Ċ ) Ċ fun ĠK t Element . analyze With All Compiler Checks (): ĠAnalysis Result Ġ= Ġget Resolution Facade (). analyze With All Compiler Checks ( listOf ( this )) Ċ Ċ // Ġthis Ġmethod Ġdon 't Ġcheck Ġvisibility Ġand Ġcollect Ġall Ġdescriptors Ġwith Ġgiven Ġfq Name Ċ @ Opt In ( Frontend Internals :: class ) Ċ fun ĠResolution Facade . resolve Import Reference ( ĊĠĠĠ Ġmodule Descriptor : ĠModule Descriptor , ĊĠĠĠ Ġfq Name : ĠF q Name Ċ ): ĠCollection < Declaration Descriptor > Ġ{ ĊĠĠĠ Ġval Ġimport Directive Ġ= ĠK t Psi Factory ( project ). create Import Directive ( Import Path ( fq Name , Ġfalse )) ĊĠĠĠ Ġval Ġqualified Expression Resolver Ġ= Ġthis . get Frontend Service ( module Descriptor , ĠQual ified Expression Resolver :: class . java ) ĊĠĠĠ Ġreturn Ġqualified Expression Resolver . process Import Reference ( ĊĠĠĠĠĠĠĠ Ġimport Directive , ĊĠĠĠĠĠĠĠ Ġmodule Descriptor , ĊĠĠĠĠĠĠĠ ĠBinding Trace Context (), ĊĠĠĠĠĠĠĠ Ġexcluded Import Names Ġ= Ġempty List (), ĊĠĠĠĠĠĠĠ Ġpackage Fragment For Visibility Check Ġ= Ġnull ĊĠĠĠ Ġ) ?. get Cont ributed Descriptors () Ġ?: Ġempty List () Ċ } Ċ Ċ @ Suppress (" DE PREC ATION ") Ċ @ Deprecated ( ĊĠĠĠ Ġ" This Ġmethod Ġis Ġgoing Ġto Ġbe Ġremoved Ġin Ġ 1 . 3 . 0 Ġrelease ", ĊĠĠĠ ĠReplace With (" analyze With All Compiler Checks (). binding Context "), ĊĠĠĠ ĠDeprec ation Level . ERROR Ċ ) Ċ fun ĠK t Element . analyze Fully (): ĠBinding Context Ġ= Ġanalyze With All Compiler Checks (). binding Context Ċ