package Ġru . hh . plugins . psi _ utils . groovy Ċ Ċ import Ġorg . jetbrains . kotlin . psi . psi Util . find Desc endant OfType Ċ import Ġorg . jetbrains . plugins . groovy . lang . psi . Gro ovy Psi Element Factory Ċ import Ġorg . jetbrains . plugins . groovy . lang . psi . api . statements . blocks . Gr C losable Block Ċ import Ġorg . jetbrains . plugins . groovy . lang . psi . api . statements . expressions . Gr MethodCall Ċ import Ġorg . jetbrains . plugins . groovy . lang . psi . impl . Gro ovy File Impl Ċ import Ġru . hh . plugins . Plugins Constants . BUILD _ GRAD LE _ DEPEND ENCI ES _ BLOCK _ NAME Ċ import Ġru . hh . plugins . Plugins Constants . BUILD _ GRAD LE _ PLUGIN S _ BLOCK _ NAME Ċ Ċ /** Ċ Ġ* ĠInvoke Ġin Ġwrite Ġcommand Ġonly . Ċ Ġ*/ Ċ fun ĠGro ovy File Impl . get OrCreate Gradle Dependencies Block (): ĠGr C losable Block Ġ{ ĊĠĠĠ Ġreturn Ġfind Block Expression ByName ( BUILD _ GRAD LE _ DEPEND ENCI ES _ BLOCK _ NAME ) ĊĠĠĠĠĠĠĠ Ġ?: Ġcreate Script Block ( BUILD _ GRAD LE _ DEPEND ENCI ES _ BLOCK _ NAME ) Ċ } Ċ Ċ /** Ċ Ġ* ĠInvoke Ġin Ġwrite Ġcommand Ġonly . Ċ Ġ*/ Ċ fun ĠGro ovy File Impl . get OrCreate Gradle Plugins Block (): ĠGr C losable Block Ġ{ ĊĠĠĠ Ġreturn Ġfind Block Expression ByName ( BUILD _ GRAD LE _ PLUGIN S _ BLOCK _ NAME ) ĊĠĠĠĠĠĠĠ Ġ?: Ġcreate Script Block ( BUILD _ GRAD LE _ PLUGIN S _ BLOCK _ NAME ) Ċ } Ċ Ċ private Ġfun ĠGro ovy File Impl . find Block Expression ByName ( block Name : ĠString ): ĠGr C losable Block ? Ġ{ ĊĠĠĠ Ġreturn Ġfind Children By Class ( Gr MethodCall :: class . java ) ĊĠĠĠĠĠĠĠ Ġ. first OrNull Ġ{ Ġit . text . startsWith ( block Name ) Ġ} ĊĠĠĠĠĠĠĠ Ġ? . find Desc endant OfType < Gr C losable Block >() Ċ } Ċ Ċ private Ġfun ĠGro ovy File Impl . create Script Block ( block Name : ĠString ): ĠGr C losable Block Ġ{ ĊĠĠĠ Ġval Ġfactory Ġ= ĠGro ovy Psi Element Factory . getInstance ( project ) ĊĊĠĠĠ Ġval Ġnew Block Expression Ġ= Ġfactory . create Expression FromText ( ĊĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠ Ġ$ block Name Ġ{ ĊĠĠĠĠĠĠĠ Ġ} ĠĠĠĠĊĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġthis . add ( factory . create NewLine ()) ĊĠĠĠ Ġval Ġadded Block Ġ= Ġthis . add ( new Block Expression ) ĊĊĠĠĠ Ġreturn Ġrequire NotNull ( added Block . find Desc endant OfType ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" Error Ġwith Ġcreating Ġnew Ġ$ block Name Ġblock Ġ| ĠGro ovy " ĊĠĠĠ Ġ} Ċ } Ċ