// Ġ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 Ġcom . intellij . java . property Based Ċ Ċ import Ġcom . intellij . ide . plugins . load Extension With Text Ċ import Ġcom . intellij . openapi . file Types . FileType Ċ import Ġcom . intellij . openapi . file Types . FileType Manager Ċ import Ġcom . intellij . openapi . file Types . FileType Registry Ċ import Ġcom . intellij . openapi . util . Dis poser Ċ import Ġcom . intellij . openapi . util . io . Byte Sequence Ċ import Ġcom . intellij . openapi . vfs . Virtual File Ċ import Ġcom . intellij . psi . search . FileType Index Ċ import Ġcom . intellij . psi . stubs . Stub Updating Index Ċ import Ġcom . intellij . test Framework . Skip Slow Test Loc ally Ċ import Ġcom . intellij . test Framework . fixtures . Light Java Code Insight Fixture TestCase Ċ import Ġcom . intellij . test Framework . property Based . Psi Index Consistency Tester Ċ import Ġcom . intellij . util . indexing . File Based Index Ċ import Ġorg . jetbrains . jet Check . Generator Ċ import Ġorg . jetbrains . jet Check . Property Checker Ċ import Ġkotlin . test . assertEquals Ċ Ċ private Ġconst Ġval ĠFILE _ NAME Ġ= Ġ" File Ident ifiable By Text " Ċ Ċ @ Skip Slow Test Loc ally Ċ class ĠFile Type Index Consistency Test Ġ: ĠLight Java Code Insight Fixture TestCase () Ġ{ ĊĠ Ġfun Ġtest F uzz Actions () Ġ{ ĊĠĠĠ ĠDis poser . register ( test Root Disposable , Ġload Extension With Text ("< fileType Detector Ġimplementation =\" ${ My FileType Detector :: class . java . name }\" /> ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMy FileType Detector :: class . java . class Loader )) ĊĊĠĠĠ Ġval Ġgen Action : ĠGenerator < Psi Index Consistency Tester . Action > Ġ= Ġ ĠGenerator . from Ġ{ Ġdata Ġ-> ĊĠĠĠĠĠ ĠMy Text Change ( ĊĠĠĠĠĠĠĠ Ġdata . generate ( Generator . sampled From (" java ", Ġ" txt ", Ġ" xml ", Ġ" dll ", Ġ"") ), ĊĠĠĠĠĠĠĠ Ġdata . generate ( Generator . b ooleans ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠProperty Checker . custom ized (). with Iteration Count ( 5 0 ). for All ( Generator . lists Of ( gen Action )) Ġ{ Ġactions Ġ-> ĊĠĠĠĠĠ ĠPsi Index Consistency Tester . run Actions ( ĊĠĠĠĠĠĠĠ ĠPsi Index Consistency Tester . Model ( my Fixture . add File To Project ( FILE _ NAME , Ġ""). virtual File , Ġmy Fixture ), Ġ* actions . to Typed Array ()) ĊĠĠĠĠĠ Ġtrue ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ class ĠMy Text Change ( text : ĠString , Ġvia Document : ĠBoolean ) Ġ: ĠJava Psi Index Consistency Test . Text Change ( text , Ġvia Document ) Ġ{ ĊĠ Ġoverride Ġfun Ġperform Action ( model : ĠPsi Index Consistency Tester . Model ) Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġmodel . v File ĊĠĠĠ Ġval Ġproject Ġ= Ġmodel . project ĊĊĠĠĠ Ġif Ġ( file . fileType . is Binary Ġ&& Ġvia Document ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĠĠĠ Ġsuper . perform Action ( model ) ĊĊĠĠĠ Ġ// ensure Ġwe 've Ġupdated Ġcontent Ġdependent Ġindexes ĊĠĠĠ Ġ// file - type Ġindex Ġis Ġnot Ġvery Ġhonest ĊĠĠĠ ĠFile Based Index . getInstance (). getFile Data ( Stub Updating Index . INDEX _ ID , Ġfile , Ġproject ) ĊĊĠĠĠ Ġval ĠfileType FromFile Ġ= Ġfile . fileType ĊĠĠĠ Ġval ĠfileType From Index Ġ= ĠFile Type Index . get Indexed FileType ( file , Ġproject ) ĊĠĠĠ ĠassertEquals ( fileType FromFile , ĠfileType From Index ) ĊĠ Ġ} Ċ Ċ } Ċ Ċ class ĠMy FileType Detector Ġ: ĠFile Type Registry . FileType Detector Ġ{ ĊĠ Ġoverride Ġfun Ġdetect ( file : ĠVirtual File , Ġfirst Bytes : ĠByte Sequence , Ġfirst Chars If Text : ĠCharSequence ?): ĠFile Type ? Ġ{ ĊĠĠĠ Ġif Ġ( file . name Ġ!= ĠFILE _ NAME ) Ġreturn Ġnull ĊĠĠĠ Ġval Ġextension Ġ= Ġfirst Chars If Text !!. toString () ĊĠĠĠ Ġif Ġ( extension . isEmpty ()) Ġreturn Ġnull ĊĠĠĠ Ġreturn ĠFile Type Manager . getInstance (). get FileType By Extension ( extension ) ĊĠ Ġ} Ċ } Ċ