/* Ċ Ġ* ĠCopyright Ġ 2 0 0 0 - 2 0 2 1 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ Ġ*/ Ċ Ċ package Ġorg . jetbrains . r . classes . r 6 Ċ Ċ import Ġcom . intellij . psi . Psi Element Ċ import Ġcom . intellij . psi . util . Psi Tree Util Ċ import Ġcom . intellij . psi . util . elementType Ċ import Ġorg . jetbrains . r . hints . parameter Info . R Argument Info Ċ import Ġorg . jetbrains . r . parsing . RE lement Types . R _ IDENTIFIER _ EXPRESSION Ċ import Ġorg . jetbrains . r . parsing . RE lement Types . R _ MEMBER _ EXPRESSION Ċ import Ġorg . jetbrains . r . psi . api .* Ċ import Ġorg . jetbrains . r . psi . impl . R Call Expression Impl Ċ import Ġorg . jetbrains . r . psi . isFunction From Library Soft Ċ import Ġorg . jetbrains . r . psi . references . R Search Scope Util Ċ import Ġorg . jetbrains . r . psi . stubs . classes . R 6 ClassName Index Ċ Ċ object ĠR 6 Class Psi Util Ġ{ ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġdepend ant Identifier Ġ` some Member ` Ġpsi - element Ġof Ġexpression Ġ` obj $ some Member ` ĊĠĠ Ġ* Ġ@ return ĠRP si Element Ġwith Ġname Ġof Ġ` some Member ` ĊĠĠ Ġ*/ ĊĠ Ġfun Ġget Se ar ched Identifier ( depend ant Identifier : ĠR Identifier Expression ?) Ġ: ĠRP si Element ? Ġ{ ĊĠĠĠ Ġif Ġ( depend ant Identifier Ġ== Ġnull ) Ġreturn Ġnull ĊĊĠĠĠ Ġval Ġclass Definition Call Ġ= ĠgetClass Definition Call From Member Usage ( depend ant Identifier ) Ġ?: Ġreturn Ġnull ĊĠĠĠ Ġval ĠclassName Ġ= ĠR 6 Class Info Util . get Associated ClassName From R 6 Class Call ( class Definition Call ) Ġ?: Ġreturn Ġnull ĊĠĠĠ Ġval ĠclassNames Hierarchy Ġ= ĠR 6 Class Info Util . get Associated Super Classes Hierarchy ( class Definition Call ) ĊĠĠĠ ĠclassNames Hierarchy ?. add ( 0 , ĠclassName ) ĊĊĠĠĠ Ġval Ġcall Search Scope Ġ= ĠR Search Scope Util . get Scope ( class Definition Call ) ĊĠĠĠ Ġval Ġproject Ġ= Ġclass Definition Call . project ĊĊĠĠĠ Ġval Ġr 6 Class Info Ġ= Ġrun Ġfind Member Definition @ Ġ{ ĊĠĠĠĠĠ Ġ( class Names Hierarchy )?. reversed ()?. forEach Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġr 6 Class Info Ġ= ĠR 6 ClassName Index . find Class Infos ( it , Ġproject , Ġcall Search Scope ). first OrNull () ĊĊĠĠĠĠĠĠĠ Ġif Ġ( r 6 Class Info Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( r 6 Class Info . contains Member ( depend ant Identifier . name )) Ġreturn @ find Member Definition Ġr 6 Class Info ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ġas ĠR 6 Class Info ? ĊĊĠĠĠ Ġr 6 Class Info Ġ?: Ġreturn Ġnull ĊĠĠĠ Ġval Ġr 6 Class Definition Call Ġ= ĠR 6 ClassName Index . find Class Definitions ( r 6 Class Info . className , Ġproject , Ġcall Search Scope ). first OrNull () ĊĠĠĠ Ġval Ġargument Info Ġ= ĠgetClass Definition Argument Info ( r 6 Class Definition Call ) Ġ?: Ġreturn Ġnull ĊĊĠĠĠ Ġval Ġpublic Members Ġ= ĠgetClass Member Expressions Of Argument ( argument Info , ĠR 6 Class Info Util . argument Public ) ĊĠĠĠ Ġval Ġprivate Members Ġ= ĠgetClass Member Expressions Of Argument ( argument Info , ĠR 6 Class Info Util . argument Private ) ĊĠĠĠ Ġval Ġactive Members Ġ= ĠgetClass Member Expressions Of Argument ( argument Info , ĠR 6 Class Info Util . argument Active ) ĊĊĠĠĠ Ġreturn Ġextract Named Argument ByName ( depend ant Identifier . name , Ġpublic Members ?. map NotNull Ġ{ Ġit Ġas ? ĠR Named Argument Ġ}) ĊĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġextract Named Argument ByName ( depend ant Identifier . name , Ġprivate Members ?. map NotNull Ġ{ Ġit Ġas ? ĠR Named Argument Ġ}) ĊĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġextract Named Argument ByName ( depend ant Identifier . name , Ġactive Members ?. map NotNull Ġ{ Ġit Ġas ? ĠR Named Argument Ġ}) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġdepend ant Identifier Ġ` some Member ` Ġpsi - element Ġof Ġexpression Ġ` obj $ some Member ` ĊĠĠ Ġ* Ġ@ param Ġobject Instantiation Call ĠR Assignment Statement Ġexpression Ġ` obj Ġ<- ĠMy Class $ new ()` ĊĠĠ Ġ* Ġ@ return Ġclass Ġdefinition Ġexpression Ġ` My Class Ġ<- ĠR 6 Class (" My Class ", Ġlist ( Ġsome Field Ġ= Ġ 0 )) ` ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun ĠgetClass Definition Expression ( depend ant Identifier : ĠR Identifier Expression ?, Ġobject Instantiation Call : ĠR Assignment Statement ?): ĠR Assignment Statement ? Ġ{ ĊĠĠĠ Ġif Ġ( depend ant Identifier Ġ== Ġnull ) Ġreturn Ġnull ĊĊĠĠĠ Ġ// Ġhandling Ġsearch Ġrequest Ġfrom Ġinside Ġof Ġclass Ġusage Ġwith Ġ` self $ field ` ĊĠĠĠ Ġif Ġ( object Instantiation Call Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( depend ant Identifier . parent ?. firstChild ?. text Ġ== ĠR 6 Class Info Util . R 6 Class This Keyword ){ ĊĠĠĠĠĠĠĠ Ġvar Ġcurrent Parent Ġ= Ġdepend ant Identifier . parent ĊĠĠĠĠĠĠĠ Ġvar Ġcurrent Call Ġ= Ġcurrent Parent Ġas ? ĠR Call Expression ĊĊĠĠĠĠĠĠĠ Ġwhile Ġ( depend ant Identifier . parent Ġ!= Ġnull ){ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( current Call ?. isFunction From Library Soft ( R 6 Class Info Util . R 6 Create Class Method , ĠR 6 Class Info Util . R 6 PackageName ) Ġ== Ġtrue ) Ġbreak ĊĠĠĠĠĠĠĠĠĠ Ġcurrent Parent Ġ= Ġcurrent Parent . parent ĊĠĠĠĠĠĠĠĠĠ Ġcurrent Call Ġ= Ġcurrent Parent Ġas ? ĠR Call Expression ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcurrent Call ?. parent Ġas ? ĠR Assignment Statement ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġhandling Ġsearch Ġrequest Ġfrom Ġclassic Ġout - of - class - definition Ġusage ĊĠĠĠ Ġval Ġobject Creation Call Ġ= Ġobject Instantiation Call . last Child Ġ// ĠMy Class $ new () ĊĠĠĠ Ġval Ġclass Element Ġ= Ġobject Creation Call ?. firstChild ?. firstChild Ġ// ĠMy Class ĊĊĠĠĠ Ġreturn Ġclass Element ?. reference ?. resolve () Ġas ? ĠR Assignment Statement ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġr Identifier Expression Ġ` some Member ` Ġof Ġexpression Ġlike Ġ` class Object $ some Member ` Ġor Ġ` self $ some Member ` ĊĠĠ Ġ* Ġ@ return Ġ` R 6 Class ` Ġfunction Ġcall , Ġwhich Ġdefines Ġclass Ġcontaining Ġ` some Member ` ĊĠĠ Ġ*/ ĊĠ Ġfun ĠgetClass Definition Call From Member Usage ( r Identifier Expression : ĠR Identifier Expression ?) Ġ: ĠR Call Expression ? Ġ{ ĊĠĠĠ Ġif Ġ( r Identifier Expression Ġ== Ġnull ) Ġreturn Ġnull ĊĠĠĠ Ġval Ġused Class Variable Ġ= ĠgetClass Identifier From Chain ed Usage s ( r Identifier Expression . parent Ġas ? ĠR Member Expression ) ĊĠĠĠ Ġreturn ĠgetClass Definition From Class Variable Usage ( used Class Variable ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġr Member Expression Ġexpression Ġlike Ġ` class Object $ some Member ` Ġor Ġ` self $ some Member ` ĊĠĠ Ġ* Ġ@ return Ġ` R 6 Class ` Ġfunction Ġcall , Ġwhich Ġdefines Ġclass Ġcontaining Ġ` some Member ` ĊĠĠ Ġ*/ ĊĠ Ġfun ĠgetClass Definition Call From Member Usage ( r Member Expression : ĠR Member Expression ?) Ġ: ĠR Call Expression ? Ġ{ ĊĠĠĠ Ġif Ġ( r Member Expression Ġ== Ġnull ) Ġreturn Ġnull ĊĠĠĠ Ġval Ġclass Object Ġ= ĠgetClass Identifier From Chain ed Usage s ( r Member Expression ) ĊĠĠĠ Ġreturn ĠgetClass Definition From Class Variable Usage ( class Object ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠgetClass Definition From Class Variable Usage ( class Object : ĠPsi Element ?) Ġ: ĠR Call Expression ? Ġ{ ĊĠĠĠ Ġ// Ġ` self $ some Member ` ĊĠĠĠ Ġif Ġ( class Object ?. text Ġ== ĠR 6 Class Info Util . R 6 Class This Keyword ) Ġ{ ĊĠĠĠĠĠ Ġval Ġparent Function Ġ= ĠPsi Tree Util . get Stub Or Psi Parent OfType ( class Object , ĠR Call Expression :: class . java ) ĊĠĠĠĠĠ Ġval Ġr 6 Class Definition Call Ġ= ĠPsi Tree Util . get Stub Or Psi Parent OfType ( parent Function , ĠR Call Expression :: class . java ) ĊĊĠĠĠĠĠ Ġif Ġ( r 6 Class Definition Call ?. isFunction From Library Soft ( R 6 Class Info Util . R 6 Create Class Method , ĠR 6 Class Info Util . R 6 PackageName ) Ġ== Ġtrue ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġr 6 Class Definition Call ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// Ġ` class Object $ some Member ` ĊĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠ Ġ// Ġ` class Object Ġ<- ĠMy Class $ new ()` Ġfrom Ġ` class Object $ some Member $ some Method () $ some Method 2 () $ some Member ` ĊĠĠĠĠĠ Ġval Ġr 6 Object Creation Expression Ġ= Ġclass Object ?. reference ?. resolve () Ġas ? ĠR Assignment Statement ĊĠĠĠĠĠ Ġ// Ġ` My Class ` Ġfrom Ġ` class Object Ġ<- ĠMy Class $ new ()` ĊĠĠĠĠĠ Ġval Ġused Class Variable Ġ= Ġr 6 Object Creation Expression ?. assigned Value ?. firstChild ?. firstChild ĊĠĠĠĠĠ Ġ// Ġ` My Class Ġ<- ĠR 6 Class (... )` Ġfrom Ġ` My Class ` ĊĠĠĠĠĠ Ġval Ġclass Definition Assignment Ġ= Ġused Class Variable ?. reference ?. resolve () Ġas ? ĠR Assignment Statement ĊĊĠĠĠĠĠ Ġreturn Ġclass Definition Assignment ?. assigned Value Ġas ? ĠR Call Expression ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġnull ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġclass Definition Assignment Ġclass Ġdefinition Ġexpression Ġ` My Class Ġ<- ĠR 6 Class (" My Class ", Ġlist ( Ġsome Field Ġ= Ġ 0 )) ` ĊĠĠ Ġ* Ġ@ return Ġargument Ġinfo Ġcontaining Ġall Ġinternal Ġmembers Ġof Ġclass ĊĠĠ Ġ*/ ĊĠ Ġfun ĠgetClass Definition Argument Info ( class Definition Assignment : ĠR Assignment Statement ?) Ġ: ĠR Argument Info ? Ġ{ ĊĠĠĠ Ġif Ġ( class Definition Assignment Ġ== Ġnull ) Ġreturn Ġnull ĊĠĠĠ Ġval Ġclass Definition Call Ġ= Ġclass Definition Assignment . children . last () Ġas ? ĠR Call Expression ĊĠĠĠ Ġreturn ĠgetClass Definition Argument Info ( class Definition Call ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġclass Definition Call Ġclass Ġdefinition Ġexpression Ġ` R 6 Class (" My Class ", Ġlist ( Ġsome Field Ġ= Ġ 0 )) ` ĊĠĠ Ġ* Ġ@ return Ġargument Ġinfo Ġcontaining Ġall Ġinternal Ġmembers Ġof Ġclass ĊĠĠ Ġ*/ ĊĠ Ġfun ĠgetClass Definition Argument Info ( class Definition Call : ĠR Call Expression ?) Ġ: ĠR Argument Info ? Ġ{ ĊĠĠĠ Ġif Ġ( class Definition Call Ġ== Ġnull ) Ġreturn Ġnull ĊĠĠĠ Ġreturn ĠR Argument Info . get Argument Info ( class Definition Call ) ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġargument Info Ġinformation Ġabout Ġarguments Ġof ĠR 6 Ġclass Ġdefinition Ġcall ĊĠĠ Ġ* Ġ@ param Ġargument Name Ġname Ġof Ġargument Ġ( i . e . Ġ` public `, Ġ` private `, Ġ` active `) Ġfrom Ġwhere Ġto Ġpick Ġclass Ġmembers ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun ĠgetClass Member Expressions Of Argument ( argument Info : ĠR Argument Info , Ġargument Name : ĠString ) Ġ: ĠList < R Expression >? Ġ{ ĊĠĠĠ Ġval Ġmembers Ġ= Ġargument Info . get Argument Passed To Parameter ( argument Name ) Ġas ? ĠR Call Expression Impl ĊĠĠĠ Ġreturn Ġmembers ?. argument List ?. expression List ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġdepend ant Identifier Ġ` some Member ` Ġpsi - element Ġof Ġexpression Ġ` class Object $ some Member $ some Method () $ some Active $ some Method 2 ()` ĊĠĠ Ġ* Ġ@ return ĠR Identifier Ġof ĠR 6 - class Ġobject ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun Ġget R 6 Object Identifier From Chain ed Usage ( depend ant Identifier : ĠR Identifier Expression ?): ĠR Identifier Expression ? Ġ{ ĊĠĠĠ Ġif Ġ( depend ant Identifier Ġ== Ġnull ) Ġreturn Ġnull ĊĊĠĠĠ Ġval Ġusage Expression Ġ= Ġdepend ant Identifier . parent ĊĠĠĠ Ġif Ġ( usage Expression . elementType Ġ!= ĠR _ MEMBER _ EXPRESSION ) Ġreturn Ġnull ĊĊĠĠĠ Ġvar Ġr 6 Object Ġ= Ġusage Expression . firstChild ĊĠĠĠ Ġwhile Ġ( r 6 Object Ġ!= Ġnull Ġ&& Ġr 6 Object . elementType Ġ!= ĠR _ IDENTIFIER _ EXPRESSION ){ ĊĠĠĠĠĠ Ġr 6 Object Ġ= Ġr 6 Object . firstChild ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġr 6 Object Ġas ĠR Identifier Expression ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* Ġ@ param Ġr Member Expression Ġ` class Object $ some Member $ some Method () $ some Active ()` ĊĠĠ Ġ* Ġ@ return Ġ` class Object ` Ġidentifier Ġas Ġthe Ġmost Ġleft Ġpsi - element Ġin Ġchained Ġusage Ġexpression ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun ĠgetClass Identifier From Chain ed Usage s ( r Member Expression : ĠR Member Expression ?) Ġ: ĠR Identifier Expression ? Ġ{ ĊĠĠĠ Ġif Ġ( r Member Expression Ġ== Ġnull ) Ġreturn Ġnull ĊĠĠĠ Ġval Ġclass Identifier Ġ= ĠPsi Tree Util . firstChild ( r Member Expression ). parent Ġas ? ĠR Identifier Expression ĊĠĠĠ Ġif Ġ( class Identifier ?. parent . elementType Ġ!= ĠR _ MEMBER _ EXPRESSION ) Ġreturn Ġnull ĊĠĠĠ Ġreturn Ġclass Identifier ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġextract Named Argument ByName ( element Name : ĠString , Ġnamed Arguments : ĠList < R Named Argument ?> ?) Ġ: ĠRP si Element ? Ġ{ ĊĠĠĠ Ġnamed Arguments ?. forEach Ġ{ ĊĠĠĠĠĠ Ġif Ġ( it Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( it . name Ġ== Ġelement Name ) Ġreturn Ġit ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġnull ĊĠ Ġ} Ċ }