// ĠCopyright Ġ 2 0 0 0 - 2 0 1 8 Ġ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 Ġcom . intellij . stats . completion Ċ Ċ import Ġcom . intellij . code Insight . lookup . Lookup Manager Ċ import Ġcom . intellij . code Insight . lookup . impl . Lookup Impl Ċ import Ġcom . intellij . completion . tracker . Position Tracking Listener Ċ import Ġcom . intellij . openapi . Disposable Ċ import Ġcom . intellij . openapi . action System . ex . An ActionListener Ċ import Ġcom . intellij . openapi . application . Application Manager Ċ import Ġcom . intellij . openapi . components . Base Component Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . project . Project Manager Ċ import Ġcom . intellij . openapi . project . Project Manager Listener Ċ import Ġcom . intellij . reporting . is Send Allowed Ċ import Ġcom . intellij . reporting . is UnitTest Mode Ċ import Ġcom . intellij . stats . experiment . WebService Status Ċ import Ġcom . intellij . stats . personal ization . User Factor Descriptions Ċ import Ġcom . intellij . stats . personal ization . User Factor Storage Ċ import Ġcom . intellij . stats . personal ization . User Factors Manager Ċ import Ġjava . beans . Property ChangeListener Ċ Ċ class ĠCompletion Tracker Initializer ( experiment Helper : ĠWeb Service Status ) Ġ: ĠDis posable , ĠBase Component Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ// ĠLog Ġonly Ġ 1 0 % Ġof Ġall Ġcompletion Ġsessions ĊĠĠĠ Ġprivate Ġconst Ġval ĠSKIP _ SESSION S _ BEFORE _ LOG _ IN _ E AP Ġ= Ġ 1 0 ĊĠĠĠ Ġvar Ġis Enabled In Tests : ĠBoolean Ġ= Ġfalse ĊĠ Ġ} ĊĊĠ Ġprivate Ġvar Ġlogging Strategy : ĠLogging Strategy Ġ= Ġif Ġ( is E AP ()) ĠLog Each N ( SKIP _ SESSION S _ BEFORE _ LOG _ IN _ E AP ) Ġelse ĠLog All Sessions ĊĠ Ġprivate Ġval Ġaction Listener Ġ= ĠLookup Actions Listener () ĊĊĠ Ġprivate Ġval Ġlookup Tracker Initializer Ġ= ĠProperty ChangeListener Ġ{ ĊĠĠĠ Ġval Ġlookup Ġ= Ġit . newValue ĊĠĠĠ Ġif Ġ( lookup Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġaction Listener . listener Ġ= ĠCompletion Popup Listener . Adapter () ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġif Ġ( lookup Ġis ĠLookup Impl ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( is UnitTest Mode () Ġ&& Ġ! isEnabled In Tests ) Ġreturn @ Property ChangeListener ĊĠĠĠĠĠ Ġlookup . put UserData ( Completion Util . COMP LE TION _ START ING _ TIME _ KEY , ĠSystem . currentTimeMillis ()) ĊĊĠĠĠĠĠ Ġval Ġglobal Storage Ġ= ĠUser Factor Storage . getInstance () ĊĠĠĠĠĠ Ġval Ġproject Storage Ġ= ĠUser Factor Storage . getInstance ( lookup . project ) ĊĊĠĠĠĠĠ Ġval Ġuser Factors Ġ= ĠUser Factors Manager . getInstance ( lookup . project ). getAll Factors () ĊĠĠĠĠĠ Ġval Ġuser Factor Values Ġ= Ġmutable Map Of < String , ĠString ?> () ĊĠĠĠĠĠ Ġuser Factors . as Sequence (). map Ġ{ Ġ"${ it . id }: App " Ġto Ġit . compute ( global Storage ) Ġ}. toMap ( user Factor Values ) ĊĠĠĠĠĠ Ġuser Factors . as Sequence (). map Ġ{ Ġ"${ it . id }: Project " Ġto Ġit . compute ( project Storage ) Ġ}. toMap ( user Factor Values ) ĊĊĠĠĠĠĠ Ġlookup . put UserData ( User Factors Manager . USER _ FACT ORS _ KEY , Ġuser Factor Values ) ĊĠĠĠĠĠ Ġval Ġshown Times Tracker Ġ= ĠPosition Tracking Listener ( lookup ) ĊĠĠĠĠĠ Ġlookup . set Prefix ChangeListener ( shown Times Tracker ) ĊĊĠĠĠĠĠ ĠUser Factor Storage . apply On Both ( lookup . project , ĠUser Factor Descriptions . COMP LE TION _ USAGE ) Ġ{ ĊĠĠĠĠĠĠĠ Ġit . fire Completion Used () ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġif Ġ( logging Strategy . shouldBe Logged ( lookup , Ġexperiment Helper )) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtracker Ġ= Ġactions Tracker ( lookup , Ġexperiment Helper ) ĊĠĠĠĠĠĠĠ Ġaction Listener . listener Ġ= Ġtracker ĊĠĠĠĠĠĠĠ Ġlookup . add Lookup Listener ( tracker ) ĊĠĠĠĠĠĠĠ Ġlookup . set Prefix ChangeListener ( tracker ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġ// Ġset Prefix ChangeListener Ġhas Ġadd Prefix ChangeListener Ġsemantics ĊĠĠĠĠĠ Ġlookup . set Prefix ChangeListener ( Time Between Typing Tracker ( lookup . project )) ĊĠĠĠĠĠ Ġlookup . add Lookup Listener ( Lookup Completed Tracker ()) ĊĠĠĠĠĠ Ġlookup . add Lookup Listener ( Lookup Started Tracker ()) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Suppress (" unused ") ĊĠ Ġfun Ġset Logging Strategy ( strategy : ĠLogging Strategy ) Ġ{ ĊĠĠĠ Ġlogging Strategy Ġ= Ġstrategy ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġactions Tracker ( lookup : ĠLookup Impl , Ġexperiment Helper : ĠWeb Service Status ): ĠCompletion Actions Tracker Ġ{ ĊĠĠĠ Ġval Ġlogger Ġ= ĠCompletion Logger Provider . getInstance (). new Completion Logger () ĊĠĠĠ Ġreturn ĠCompletion Actions Tracker ( lookup , Ġlogger , Ġexperiment Helper ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshould Initialize () Ġ= Ġis Send Allowed () Ġ|| Ġis UnitTest Mode () ĊĊĠ Ġprivate Ġfun Ġis E AP (): ĠBoolean Ġ= ĠApplication Manager . getApplication (). is E AP Ġ&& Ġ! is UnitTest Mode () ĊĊĠ Ġoverride Ġfun Ġinit Component () Ġ{ ĊĠĠĠ Ġif Ġ(! should Initialize ()) Ġreturn ĊĊĠĠĠ Ġval Ġbus Connection Ġ= ĠApplication Manager . getApplication (). message Bus . connect ( this ) ĊĠĠĠ Ġbus Connection . subscribe ( An ActionListener . TOPIC , Ġaction Listener ) ĊĠĠĠ Ġbus Connection . subscribe ( Project Manager . TOPIC , Ġobject Ġ: ĠProject Manager Listener Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġproject Opened ( project : ĠProject ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlookup Manager Ġ= ĠLookup Manager . getInstance ( project ) ĊĠĠĠĠĠĠĠ Ġlookup Manager . addProperty ChangeListener ( lookup Tracker Initializer ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġproject Closed ( project : ĠProject ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlookup Manager Ġ= ĠLookup Manager . getInstance ( project ) ĊĠĠĠĠĠĠĠ Ġlookup Manager . remove Property ChangeListener ( lookup Tracker Initializer ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġdispose () Ġ{ ĊĠ Ġ} Ċ }