/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 9 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . android . tools . idea . model Ċ Ċ import Ġcom . android . Sdk Constants Ċ import Ġcom . android . ide . common . util . Path String Ċ import Ġcom . android . tools . idea . project system . Project System Sync Manager Ċ import Ġcom . android . tools . idea . project system . getModule System Ċ import Ġcom . android . tools . idea . project system . is Manifest File Ċ import Ġcom . android . tools . idea . util . Lazy File Listener Subscriber Ċ import Ġcom . android . tools . idea . util . Pol ite Android Virtual File Listener Ċ import Ġcom . android . tools . idea . util . listen Until Next Sync Ċ import Ġcom . intellij . App Topics Ċ import Ġcom . intellij . openapi . Disposable Ċ import Ġcom . intellij . openapi . editor . Editor Factory Ċ import Ġcom . intellij . openapi . editor . event . Document Event Ċ import Ġcom . intellij . openapi . editor . event . Document Listener Ċ import Ġcom . intellij . openapi . file Editor . File Document Manager Ċ import Ġcom . intellij . openapi . file Editor . File Document Manager Listener Ċ import Ġcom . intellij . openapi . module . Module Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . startup . Startup Activity Ċ import Ġcom . intellij . openapi . vfs . V fs Util Core Ċ import Ġcom . intellij . openapi . vfs . Virtual File Ċ import Ġcom . intellij . openapi . vfs . Virtual File Event Ċ import Ġcom . intellij . openapi . vfs . Virtual FileManager Ċ import Ġcom . intellij . psi . Psi Document Manager Ċ import Ġcom . intellij . util . containers . Tree Traversal Ċ import Ġorg . jetbrains . android . facet . Android Facet Ċ import Ġorg . jetbrains . android . facet . Source Provider Manager Ċ Ċ /** Ċ Ġ* ĠA Ġproject - wide Ġlistener Ġthat Ġdetermines Ġwhich Ġmodules ' Ġmerged Ġmanifest s Ġare Ġaffected Ġby ĠV FS Ċ Ġ* Ġchanges Ġor ĠDocument Ġchanges Ġand Ġtells Ġthe Ġcorresponding Ġ[ Merged Manifest Modification Tracker ] s Ġto Ċ Ġ* Ġincrement Ġcounter . Ġ[ Merged Manifest Modification Listener ] Ġregisters Ġitself Ġto Ġstart Ġactively Ġlistening Ġfor Ċ Ġ* ĠV FS Ġchanges Ġand ĠDocument Ġchanges Ġafter Ġthe Ġfirst Ġproject Ġsync Ġof Ġthe Ġsession . Ċ Ġ*/ Ċ class ĠMerged Manifest Modification Listener ( ĊĠ Ġproject : ĠProject Ċ ) Ġ: ĠPol ite Android Virtual File Listener ( project ), ĊĠĠĠ ĠDocument Listener , ĊĠĠĠ ĠFile Document Manager Listener Ġ{ ĊĊĠ Ġprivate Ġval Ġpsi Document Manager Ġ= ĠPsi Document Manager . getInstance ( project ) ĊĠ Ġprivate Ġval Ġfile Document Manager Ġ= ĠFile Document Manager . getInstance () ĊĊĠ Ġ// ĠIf Ġa Ġdirectory Ġwas Ġdeleted , Ġwe Ġwon 't Ġget Ġa Ġseparate Ġevent Ġfor Ġeach Ġdesc endant , Ġso Ġwe ĊĠ Ġ// Ġmust Ġlet Ġdirectories Ġpass Ġthrough Ġthis Ġfail - fast Ġfilter Ġin Ġcase Ġthey Ġcontain Ġrelevant Ġfiles . ĊĠ Ġoverride Ġfun Ġis Po ss ibly Re levant ( file : ĠVirtual File ) Ġ= Ġfile . isDirectory Ġ|| Ġfile . extension Ġ== Ġ" xml " ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠDetermines Ġif Ġthe Ġchanged Ġfile Ġcontribut es Ġto Ġmerged Ġmanifest Ġattributes Ġcomputed Ġusing Ġthe Ġ[ Android Manifest Index ]. ĊĠĠ Ġ* ĠThis Ġmeans Ġthe Ġfile Ġis Ġeither : ĊĠĠ Ġ* Ġ 1 . ĠAn ĠAndroid Manifest . xml Ġbelong ing Ġto Ġone Ġof Ġthe Ġcontaining Ġmodule 's Ġsource Ġproviders . ĊĠĠ Ġ* Ġ 2 . ĠA Ġdirectory Ġthat Ġis Ġan Ġancestor Ġof Ġa Ġfile Ġmatching Ġ( 1 ). ĊĠĠ Ġ* ĊĠĠ Ġ* ĠNote Ġthat Ġwe Ġdon 't Ġcare Ġabout Ġnavigation Ġfiles Ġhere , Ġsince Ġwe Ġdon 't Ġuse Ġnavigation Ġfiles Ġfor ĊĠĠ Ġ* Ġany Ġ[ Android Manifest Index ]- based Ġattribute Ġcomput ations . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ see Ġ[ Merged Manifest Modification Tracker ] ĊĠĠ Ġ*/ ĊĠ Ġoverride Ġfun Ġis Re levant ( file : ĠVirtual File , Ġfacet : ĠAndroid Facet ): ĠBoolean Ġ{ ĊĠĠĠ Ġif Ġ( file . name Ġ== ĠS dk Constants . FN _ ANDROID _ MAN IFEST _ XML ) Ġreturn Ġfacet . is Manifest File ( file ) ĊĊĠĠĠ Ġif Ġ(! file . isDirectory ) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn ĠSource Provider Manager . getInstance ( facet ). sources . manifest Files . any Ġ{ ĠV fs Util Core . is Ancestor ( file , Ġit , Ġfalse ) Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġcontents Changed ( event : ĠVirtual File Event ) Ġ{ ĊĠĠĠ Ġ// ĠContent Ġchanges Ġare Ġnot Ġhandled Ġat Ġthe ĠV FS Ġlevel Ġbut Ġeither Ġin Ġfile With No Document Changed Ġor Ġdocument Changed ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġfile With No Document Changed ( file : ĠVirtual File ) Ġ= Ġpossibly Ir relevant File Changed ( file ) ĊĊĠ Ġoverride Ġfun Ġdocument Changed ( event : ĠDocument Event ) Ġ{ ĊĠĠĠ Ġif Ġ( project . is Disposed ()) Ġ{ ĊĠĠĠĠĠ Ġ// Ġnote Ġthat Ġevent Ġmay Ġar rive Ġfrom Ġany Ġproject , Ġnot Ġonly Ġfrom Ġmy Project ĊĠĠĠĠĠ Ġ// Ġmy Project Ġcan Ġbe Ġtemporarily Ġdisposed Ġin Ġlight Ġtests ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġdocument Ġ= Ġevent . document ĊĠĠĠ Ġval Ġpsi File Ġ= Ġpsi Document Manager . get Cached Psi File ( document ) ĊĊĠĠĠ Ġif Ġ( psi File Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġfile Document Manager . getFile ( document )?. let Ġ{ Ġpossibly Ir relevant File Changed ( it ) Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠ Ġpsi File . virtual File ?. let Ġ{ Ġpossibly Ir relevant File Changed ( it ) Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġfile Changed ( path : ĠPath String , Ġfacet : ĠAndroid Facet ) Ġ= Ġupdate Modification Track ers ( facet ) ĊĊĠ Ġprivate Ġfun Ġupdate Modification Track ers ( facet : ĠAndroid Facet ) Ġ{ ĊĠĠĠ Ġfacet . module . get Trans itive Resource Depend ents (). forEach Ġ{ ĊĠĠĠĠĠ ĠMerged Manifest Modification Tracker . getInstance ( it ). manifest Changed () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠService Ġresponsible Ġfor Ġensuring Ġthat Ġa Ġ[ Project ] Ġhas Ġa Ġ[ Merged Manifest Modification Listener ] ĊĠĠ Ġ* Ġsubscribed Ġto Ġlisten Ġfor Ġboth ĠV FS Ġand ĠDocument Ġchanges Ġonce Ġthe Ġinitial Ġproject Ġsync Ġhas Ġcompleted . ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġclass ĠSubscription Service ( ĊĠĠĠ Ġval Ġproject : ĠProject ĊĠ Ġ) Ġ: ĠLazy File Listener Subscriber < Merged Manifest Modification Listener >( Merged Manifest Modification Listener ( project )), ĊĠĠĠĠĠ ĠDis posable Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġsubscribe () Ġ{ ĊĠĠĠĠĠ Ġ// ĠNever Ġuse ĠApplication Ġor ĠProject Ġas Ġparents Ġfor Ġdis pos ables , Ġas Ġthey Ġwill Ġbe Ġle aked Ġon Ġplugin Ġun load . ĊĊĠĠĠĠĠ Ġ// ĠTo Ġreceive Ġall Ġchanges Ġhappening Ġin Ġthe ĠV FS . ĠFile Ġmodifications Ġmay ĊĠĠĠĠĠ Ġ// Ġnot Ġbe Ġpicked Ġup Ġimmediately Ġif Ġsuch Ġchanges Ġare Ġnot Ġsaved Ġon Ġthe Ġdisk Ġyet ĊĠĠĠĠĠ ĠVirtual FileManager . getInstance (). add Virtual File Listener ( listener , Ġthis ) ĊĊĠĠĠĠĠ Ġ// ĠTo Ġreceive Ġall Ġchanges Ġto Ġdocuments Ġthat Ġare Ġopen Ġin Ġan Ġeditor ĊĠĠĠĠĠ ĠEditor Factory . getInstance (). event Mult ic aster . add Document Listener ( listener , Ġthis ) ĊĊĠĠĠĠĠ Ġ// ĠTo Ġreceive Ġnotifications Ġwhen Ġany ĠDocuments Ġare Ġsaved Ġor Ġre loaded Ġfrom Ġdisk ĊĠĠĠĠĠ Ġproject . message Bus . connect (). subscribe ( App Topics . FILE _ DOCUMENT _ SYNC , Ġlistener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġdispose () Ġ{ ĊĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠSubscription Startup Activity Ġ: ĠStartup Activity . D umb Aware Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġrun Activity ( project : ĠProject ) Ġ{ ĊĠĠĠĠĠ Ġproject . listen Until Next Sync ( listener Ġ= Ġobject Ġ: ĠProject System Sync Manager . Sync Result Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġsync Ended ( result : ĠProject System Sync Manager . Sync Result ) Ġ= Ġensure Sub scribed ( project ) ĊĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġensure Sub scribed ( project : ĠProject ) Ġ= Ġproject . getService ( Subscription Service :: class . java ). ensure Sub scribed () ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠModule . get Trans itive Resource Depend ents () Ġ= ĠTRANS ITIVE _ RESOURCE _ DEPEND ENTS .` fun `( this ) Ċ Ċ private Ġval ĠTRANS ITIVE _ RESOURCE _ DEPEND ENTS Ġ= ĠTree Traversal . PLAIN _ B FS . unique (). traversal < Module > Ġ{ ĊĠ Ġit . getModule System (). get Direct Resource Module Depend ents () Ċ }