package Ġcom . j tran sc . plugin . proxy Ċ Ċ import Ġcom . j tran sc . ast .* Ċ import Ġcom . j tran sc . error . invalid Op Ċ import Ġcom . j tran sc . plugin . J Tran sc Plugin Ċ import Ġcom . j tran sc . plugin . reflection . createClass Ċ import Ġcom . j tran sc . plugin . reflection . create Constructor Ċ import Ġcom . j tran sc . plugin . reflection . create Field Ċ import Ġcom . j tran sc . plugin . reflection . create Method Ċ import Ġj . Program Reflection Ċ import Ġjava . lang . reflect . Invocation Handler Ċ import Ġjava . lang . reflect . Method Ċ import Ġjava . lang . reflect . Proxy Ċ Ċ class ĠProxy J Tran sc Plugin Ġ: ĠJ Tran sc Plugin () Ġ{ Ċ ĉ override Ġval Ġpriority : ĠInt Ġ= Ġ 1 Ċ ĉ /* Ċ ĉ override Ġfun Ġon After All Class Dis covered ( program : ĠAst Program ) Ġ{ Ċĉ ĉ program . add Reference () Ċ ĉ } Ċ ĉ */ ĊĊ ĉ override Ġfun Ġprocess After Tree Sh aking ( program : ĠAst Program ) Ġ{ Ċĉ ĉ if Ġ( Proxy :: class . java . fq name Ġ! in Ġprogram ) Ġreturn Ġ// ĠProxy Ġnot Ġreferenced ! Ċĉ ĉ if Ġ( Program Reflection :: class . java . fq name Ġ! in Ġprogram ) Ġreturn Ġ// ĠProgram Reflection Ġnot Ġreferenced ! ĊĊĉ ĉ val Ġcl Ġ= Ġprogram [ Proxy :: class . java . fq name ] Ċĉ ĉ val ĠProxy _ new Proxy Instance Ġ= Ġcl . getMethod Without Overrides ("_ new Proxy Instance ") Ġ?: Ġreturn Ġ// ĠProxy . new Proxy Instance Ġnot Ġreferenced Ċĉ ĉ val ĠInvocation Handler _ class Ġ= Ġprogram . get OrNull ( java . lang . reflect . Invocation Handler :: class . java . name . fq name ) Ġ?: Ġreturn Ġ// ĠInvocation Handler Ġnot Ġreferenced Ċĉ ĉ val ĠInvocation Handler _ invoke Ġ= ĠInvocation Handler _ class . getMethod Without Overrides ( Invocation Handler :: invoke . name ) Ġ?: Ġreturn ĊĊĉ ĉ val ĠProgram Reflection Ġ= Ġprogram [ Program Reflection :: class . java . name . fq name ] Ċĉ ĉ val ĠProgram Reflection _ get Direct Method Ġ= ĠProgram Reflection . getMethod Without Overrides ( j . Program Reflection :: get Direct Method . name ) Ġ?: Ġreturn Ċĉ ĉ val ĠProgram Reflection _ getMethod By Info Ġ= ĠProgram Reflection . getMethod Without Overrides ( j . Program Reflection :: getMethod By Info . name ) Ġ?: Ġreturn ĊĊĊĉ ĉ val Ġinterfaces Ġ= Ġprogram . classes . toList (). filter Ġ{ Ġit . is Interface Ġ&& Ġit . visible Ġ} Ċĉ ĉ val Ġproxies Ġ= Ġhash Map Of < Ast Class , ĠAst Class >() ĊĊĉ ĉ for Ġ( inter f ase Ġin Ġinterfaces ) Ġ{ Ċĉĉ ĉ proxies [ inter f ase ] Ġ= Ġprogram . createClass ("${ inter f ase . fq name }\ $ Proxy ". fq name , Ġinterfaces Ġ= ĠlistOf ( inter f ase . name )) Ġ{ Ċĉĉĉ ĉ extra Visible Ġ= Ġfalse ĊĊĉĉĉ ĉ val Ġic Field Ġ= Ġcreate Field (" ic ", ĠInvocation Handler _ class . ref ) ĊĊĉĉĉ ĉ create Constructor ( Ast Type . METHOD ( Ast Type . VOID , ĠlistOf ( Invocation Handler _ class . ref ))) Ġ{ Ġargs Ġ-> Ċĉĉĉĉ ĉ val Ġ( ic Arg ) Ġ= Ġargs Ċĉĉĉĉ ĉ STM ( Ast St m . SET _ FIELD _ INSTANCE ( ic Field . ref , ĠTHIS , Ġic Arg . expr )) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ for Ġ( method Ref Ġin Ġinterf ase . all Methods To Implement ) Ġ{ Ċĉĉĉĉ ĉ val Ġmethod Ġ= Ġinterf ase . getMethod In An cestors And Interfaces ( method Ref ) Ġ?: Ġinvalid Op (" Can 't Ġfind Ġmethod Ġ$ method Ref ") Ċĉĉĉĉ ĉ val Ġmethod Type Ġ= Ġmethod Ref . type Ċĉĉĉĉ ĉ create Method ( method Ref . name , Ġmethod Type ) Ġ{ Ċĉĉĉĉĉ ĉ // STM ( ic Field ) Ċĉĉĉĉĉ ĉ val Ġcall Ġ= ĠTHIS [ ic Field ][ Invocation Handler _ invoke . ref ]( Ċĉĉĉĉĉĉ ĉ THIS , Ċĉĉĉĉĉĉ ĉ Program Reflection _ get Direct Method ( inter f ase . class Id . lit , Ġmethod . id . lit ), Ċĉĉĉĉĉĉ ĉ CREATE _ ARRAY ( ARRAY ( OBJECT ), Ġmethod Type . args . map Ġ{ Ġit . expr . cast To ( OBJECT ) Ġ}) Ċĉĉĉĉĉ ĉ ) Ċĉĉĉĉĉ ĉ if Ġ( method Type . ret Void ) Ġ{ Ċĉĉĉĉĉĉ ĉ STM ( call ) Ċĉĉĉĉĉĉ ĉ RETURN () Ċĉĉĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉĉĉ ĉ RETURN ( call . cast To ( method Type . ret )) Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ Proxy _ new Proxy Instance . replace Body Opt Build Ġ{ Ġargs Ġ-> Ċĉĉ ĉ val Ġ( if c Id , Ġih ) Ġ= Ġargs ĊĊĉĉ ĉ SWITCH ( if c Id . expr ) Ġ{ Ċĉĉĉ ĉ for Ġ( if c Ġin Ġinterfaces ) Ġ{ Ċĉĉĉĉ ĉ CASE ( if c . class Id ) Ġ{ Ċĉĉĉĉĉ ĉ val Ġproxy Ġ= Ġproxies [ if c ] Ċĉĉĉĉĉ ĉ val Ġconstructor Ġ= Ġproxy !!. construct ors . first () Ċĉĉĉĉĉ ĉ RETURN ( Ast Expr . NEW _ WITH _ CON STRUCTOR ( constructor . ref , ĠlistOf ( ih . expr ))) Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ } ĊĊĉĉ ĉ RETURN ( NULL ) Ċĉ ĉ } Ċ ĉ } Ċ }