// Ġ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 . java . code Insight . actions Ċ Ċ import Ġcom . intellij . code Insight . highlight ing . Brace Matching Util Ċ import Ġcom . intellij . openapi . application . Write Action Ċ import Ġcom . intellij . openapi . editor . Document Ċ import Ġcom . intellij . openapi . editor . ex . Editor Ex Ċ import Ġcom . intellij . openapi . editor . highlighter . Highlight er Iterator Ċ import Ġcom . intellij . openapi . file Types . FileType Ċ import Ġcom . intellij . openapi . util . text . StringUtil Ċ import Ġcom . intellij . psi . Java TokenType Ċ import Ġcom . intellij . test Framework . Light Platform Code Insight TestCase Ċ Ċ private Ġtype alias ĠBr ace Matcher Ġ= Ġ( Highlight er Iterator , ĠCharSequence , ĠFile Type ) Ġ-> ĠInt Ċ private Ġconst Ġval ĠTARGET _ MARKER Ġ= Ġ"< target >" Ċ Ċ class ĠBr ace Matcher Util Test Ġ: ĠLight Platform Code Insight TestCase () Ġ{ ĊĠ Ġfun Ġtest Right most RP aren 0 () Ġ= Ġassert Right most RP aren th (" (< caret >() ([{ ()} ]) < target >) [] () ") ĊĠ Ġfun Ġtest Right most RP aren 1 () Ġ= Ġassert Right most RP aren th (" (< caret >( }) ([{ ()} ])) [] () ") ĊĠ Ġfun Ġtest Right most RP aren 2 () Ġ= Ġassert Right most RP aren th (" (< caret > ({}) ([{ ()} ] (){ }) < target >) [] () ") ĊĠ Ġfun Ġtest Right most RP aren 3 () Ġ= Ġassert Right most RP aren th (" (< caret >") ĊĠ Ġfun Ġtest Right most RP aren 4 () Ġ= Ġassert Right most RP aren th (" (< caret >< target >) ") ĊĠ Ġfun Ġtest Right most RP aren 5 () Ġ= Ġassert Right most RP aren th (" (( < caret >< target >) ") ĊĠ Ġfun Ġtest Right most RP aren 6 () Ġ= Ġassert Right most RP aren th (" (< caret >) < target >) ") ĊĠ Ġfun Ġtest Right most RP aren 7 () Ġ= Ġassert Right most RP aren th (" (( < caret >) < target >) ") ĊĠ Ġfun Ġtest Right most RP aren 8 () Ġ= Ġassert Right most RP aren th ("< caret >") ĊĠ Ġfun Ġtest Right most RP aren 9 () Ġ= Ġassert Right most RP aren th ("< caret >< target >) ") ĊĊĠ Ġfun Ġtest Left most LP aren 0 () Ġ= Ġassert Left most LP aren th (" (() ([{ ()} ])) < caret >") ĊĠ Ġfun Ġtest Left most LP aren 1 () Ġ= Ġassert Left most LP aren th (" (() ([{ ()} ]) < caret >) ") ĊĠ Ġfun Ġtest Left most LP aren 2 () Ġ= Ġassert Left most LP aren th ("< target >(( () ([{ ()} ]) < caret >) ") ĊĠ Ġfun Ġtest Left most LP aren 3 () Ġ= Ġassert Left most LP aren th ("< target >(() (() ([{ ()} ]) < caret >) ") ĊĊĠ Ġfun Ġtest Left LP aren 0 () Ġ= Ġassert Left LP aren th (" (< caret >) ") ĊĠ Ġfun Ġtest Left LP aren 1 () Ġ= Ġassert Left LP aren th ("< target >(( < caret >) ") ĊĠ Ġfun Ġtest Left LP aren 2 () Ġ= Ġassert Left LP aren th (" () < target >(( < caret >) ") ĊĠ Ġfun Ġtest Left LP aren 3 () Ġ= Ġassert Left LP aren th ("< target >(< caret >") ĊĊĊĠ Ġprivate Ġfun Ġassert Right most RP aren th ( text : ĠString ) Ġ{ ĊĠĠĠ Ġassert Paren th Sc anning ( text ) Ġ{ Ġiterator , Ġchar Sequence , ĠfileType Ġ-> ĊĠĠĠĠĠ ĠBr ace Matching Util . find Right most RP aren ( iterator , ĠJava TokenType . RP AREN TH , Ġchar Sequence , ĠfileType ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Left most LP aren th ( text : ĠString ) Ġ{ ĊĠĠĠ Ġassert Paren th Sc anning ( text ) Ġ{ Ġiterator , Ġchar Sequence , ĠfileType Ġ-> ĊĠĠĠĠĠ ĠBr ace Matching Util . find Left most LP aren ( iterator , ĠJava TokenType . LP AREN TH , Ġchar Sequence , ĠfileType ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Left LP aren th ( text : ĠString ) Ġ{ ĊĠĠĠ Ġassert Paren th Sc anning ( text ) Ġ{ Ġiterator , Ġchar Sequence , ĠfileType Ġ-> ĊĠĠĠĠĠ ĠBr ace Matching Util . find Left LP aren ( iterator , ĠJava TokenType . LP AREN TH , Ġchar Sequence , ĠfileType ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Paren th Sc anning ( text : ĠString , Ġf : ĠBr ace Matcher ) Ġ{ ĊĠĠĠ Ġval Ġdocument : ĠDocument Ġ= Ġconfigure FromFile Text (" foo . java ", Ġtext ) ĊĊĠĠĠ Ġval Ġexpected Index : ĠInt Ġ= ĠString Util . indexOf ( document . chars Sequence , ĠTARGET _ MARKER ) ĊĠĠĠ Ġif Ġ( expected Index Ġ>= Ġ 0 ) Ġ{ ĊĠĠĠĠĠ ĠWrite Action . run < Throwable > Ġ{ ĊĠĠĠĠĠĠĠ Ġdocument . delete String ( expected Index , Ġexpected Index Ġ+ ĠTARGET _ MARKER . length ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġoffset : ĠInt Ġ= Ġget Editor (). caret Model . offset ĊĠĠĠ Ġval Ġiterator : ĠHighlight er Iterator Ġ= Ġ( get Editor () Ġas ĠEditor Ex ). highlighter . create Iterator ( offset ) ĊĠĠĠ Ġval ĠfileType : ĠFile Type Ġ= ĠgetFile (). virtual File . fileType ĊĠĠĠ Ġval Ġactual Index : ĠInt Ġ= Ġf ( iterator , Ġdocument . chars Sequence , ĠfileType ) ĊĊĠĠĠ ĠassertEquals ( expected Index , Ġactual Index ) ĊĠ Ġ} Ċ } Ċ