package Ġorg . jetbrains . research . common Ċ Ċ import Ġcom . jetbrains . python . psi . Py Function Ċ import Ġorg . jetbrains . research . common . j gr ap ht . Pattern Graph Ċ import Ġorg . jetbrains . research . common . py flow graph . Graph Building Exception Ċ import Ġorg . jetbrains . research . common . py flow graph . Py Flow Graph Builder Ċ import Ġjava . io . File ĊĊ Ċ fun Ġbuild Py Flow Graph For Method ( node : ĠPy Function , Ġbuilder : ĠString Ġ= Ġ" kotlin "): ĠPattern Graph Ġ= ĊĠĠĠ Ġwhen Ġ( builder ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" python " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtemp File Ġ= Ġcreate TempFile From Method Psi ( node ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġdot File Ġ= Ġbuild Py Flow Graph By Sub process ( temp File ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPattern Graph ( dot File . inputStream ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ" kotlin " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmethod Py Flow Graph Ġ= ĠPy Flow Graph Builder (). build For Py Function ( node ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPattern Graph ( method Py Flow Graph ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠIllegalArgumentException () ĊĠĠĠ Ġ} Ċ Ċ fun Ġcreate TempFile From Method Psi ( node : ĠPy Function ): ĠFile Ġ{ ĊĠĠĠ Ġval Ġcurrent Method Src : ĠString Ġ= Ġnode . original Element . text ĊĠĠĠ Ġval Ġtemp File Ġ= Ġcreate TempFile ( ĊĠĠĠĠĠĠĠ Ġprefix Ġ= Ġ" method _${ node . name }_ ", ĊĠĠĠĠĠĠĠ Ġdirectory Ġ= ĠConfig . TEMP _ DIRECTORY _ PATH . to File () ĊĠĠĠ Ġ) ĊĠĠĠ Ġtemp File . write Text ( current Method Src ) ĊĠĠĠ Ġtemp File . delete On Exit () ĊĠĠĠ Ġreturn Ġtemp File Ċ } Ċ Ċ fun Ġbuild Py Flow Graph By Sub process ( inputFile : ĠFile ): ĠFile Ġ{ ĊĠĠĠ Ġval Ġpython Exec Path Ġ= ĠConfig . PYTHON _ EXECUT ABLE _ PATH . toString () ĊĠĠĠ Ġval Ġmain Script Path Ġ= ĠConfig . CODE _ CHANGE _ MIN ER _ PATH . resolve (" main . py "). toString () ĊĠĠĠ Ġval Ġinput FilePath Ġ= Ġinput File . absolute Path ĊĠĠĠ Ġval Ġoutput FilePath Ġ= ĠConfig . TEMP _ DIRECTORY _ PATH ĊĠĠĠĠĠĠĠ Ġ. resolve (" p fg _${ inputFile . name Without Extension }. dot ") ĊĠĠĠĠĠĠĠ Ġ. toString () ĊĠĠĠ Ġval Ġbuilder Ġ= ĠProcess Builder (). also Ġ{ ĊĠĠĠĠĠĠĠ Ġit . command ( python Exec Path , Ġmain Script Path , Ġ" p fg ", Ġ"- i ", Ġinput FilePath , Ġ"- o ", Ġoutput FilePath ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġprocess Ġ= Ġbuilder . start () ĊĠĠĠ Ġval Ġexit Code Ġ= Ġprocess . waitFor () ĊĠĠĠ Ġif Ġ( exit Code Ġ!= Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthrow ĠGraph Building Exception (" Failed Ġto Ġbuild Ġp fg Ġusing ĠPython Ġsubprocess ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġdot File Ġ= ĠFile ( output FilePath ) ĊĠĠĠ Ġval Ġdot Pdf File Ġ= ĠFile ( dot File . absolute Path . plus (". pdf ")) ĊĠĠĠ Ġdot File . delete On Exit () ĊĠĠĠ Ġdot Pdf File . delete On Exit () ĊĠĠĠ Ġreturn Ġdot File Ċ }