// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 Ġ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 . file Prediction . features Ċ Ċ import Ġcom . intellij . file Prediction . features . File Prediction Feature . Companion . binary Ċ import Ġcom . intellij . file Prediction . features . File Prediction Feature . Companion . num erical Ċ import Ġcom . intellij . openapi . application . Application Manager Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . project . guess Project Dir Ċ import Ġcom . intellij . openapi . roots . File Index Facade Ċ import Ġcom . intellij . openapi . util . System Info Ċ import Ġcom . intellij . openapi . util . io . File Util Ċ import Ġcom . intellij . openapi . util . text . StringUtil Ċ import Ġcom . intellij . openapi . util . text . StringUtil . toLowerCase Ċ import Ġcom . intellij . openapi . vfs . Virtual File Ċ import Ġcom . intellij . util . Path Util Ċ import Ġjava . io . File Ċ Ċ class ĠFile Prediction General Features : ĠFile Prediction Feature Provider Ġ{ ĊĠ Ġoverride Ġfun ĠgetName (): ĠString Ġ= Ġ"" ĊĊĠ Ġoverride Ġfun Ġcalculate File Features ( project : ĠProject , Ġnew File : ĠVirtual File , Ġprev File : ĠVirtual File ?): ĠMap < String , ĠFile Prediction Feature > Ġ{ ĊĠĠĠ Ġval Ġresult Ġ= ĠHashMap < String , ĠFile Prediction Feature >() ĊĠĠĠ ĠApplication Manager . getApplication (). run Read Action Ġ{ ĊĠĠĠĠĠ Ġif Ġ( new File . isValid ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfile Index Ġ= ĠFile Index Facade . getInstance ( project ) ĊĠĠĠĠĠĠĠ Ġresult [" in _ project "] Ġ= Ġbinary ( file Index . isIn Project Scope ( new File )) ĊĠĠĠĠĠĠĠ Ġresult [" in _ source "] Ġ= Ġbinary ( file Index . isIn Source ( new File )) ĊĠĠĠĠĠĠĠ Ġresult [" in _ library "] Ġ= Ġbinary ( file Index . isIn Library Classes ( new File ) Ġ|| Ġfile Index . isIn Library Source ( new File )) ĊĠĠĠĠĠĠĠ Ġresult [" excluded "] Ġ= Ġbinary ( file Index . is Excluded File ( new File )) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( prev File Ġ!= Ġnull Ġ&& Ġprev File . isValid ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġnew Module Ġ= Ġfile Index . getModule For File ( new File ) ĊĠĠĠĠĠĠĠĠĠ Ġresult [" same _ module "] Ġ= Ġbinary ( new Module Ġ!= Ġnull Ġ&& Ġnew Module Ġ== Ġfile Index . getModule For File ( prev File )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġif Ġ( prev File Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġval Ġnew FileName Ġ= Ġun ify ( new File . name ) ĊĠĠĠĠĠ Ġval Ġnew FilePath Ġ= Ġun ify ( new File . path ) ĊĠĠĠĠĠ Ġval Ġprev FileName Ġ= Ġun ify ( prev File . name ) ĊĠĠĠĠĠ Ġresult [" name _ prefix "] Ġ= Ġnumerical ( StringUtil . common Prefix Length ( new FileName , Ġprev FileName )) ĊĊĠĠĠĠĠ Ġval Ġprev FilePath Ġ= Ġun ify ( prev File . path ) ĊĠĠĠĠĠ Ġresult [" path _ prefix "] Ġ= Ġnumerical ( StringUtil . common Prefix Length ( new FilePath , Ġprev FilePath )) ĊĊĠĠĠĠĠ Ġval Ġbase Dir Ġ= Ġproject . guess Project Dir ()?. path ?. let Ġ{ Ġun ify ( it ) Ġ} ĊĠĠĠĠĠ Ġif Ġ( base Dir Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew RelativePath Ġ= ĠFile Util . get RelativePath ( base Dir , Ġnew FilePath , ĠFile . separator Char , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġval Ġprev RelativePath Ġ= ĠFile Util . get RelativePath ( base Dir , Ġprev FilePath , ĠFile . separator Char , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġif Ġ( new RelativePath Ġ!= Ġnull Ġ&& Ġprev RelativePath Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġresult [" relative _ path _ prefix "] Ġ= Ġnumerical ( StringUtil . common Prefix Length ( new RelativePath , Ġprev RelativePath )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġresult [" same _ dir "] Ġ= Ġbinary ( Path Util . getParent Path ( new FilePath ) Ġ== ĠPath Util . getParent Path ( prev FilePath )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġresult ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġun ify ( path : ĠString ) Ġ: ĠString Ġ{ ĊĠĠĠ Ġval Ġcase Sensitive Ġ= ĠSystem Info . is FileSystem Case Sensitive ĊĠĠĠ Ġreturn Ġif Ġ( case Sensitive ) ĠFile Util . getName Without Extension ( path ) Ġelse ĠFile Util . getName Without Extension ( toLowerCase ( path )) ĊĠ Ġ} Ċ } Ċ