package Ġpl . to uk . kr ush . env Ċ Ċ import Ġcom . squareup . kotlin po et . metadata . Immutable Km Class Ċ import Ġcom . squareup . kotlin po et . metadata . Kotlin Po et Metadata Preview Ċ import Ġcom . squareup . kotlin po et . metadata . to Immutable Km Class Ċ import Ġjavax . annotation . processing . Processing Environment Ċ import Ġjavax . annotation . processing . Round Environment Ċ import Ġjavax . lang . model . element . Element Ċ import Ġjavax . lang . model . element . Element Kind Ċ import Ġjavax . lang . model . element . Type Element Ċ import Ġjavax . lang . model . element . Variable Element Ċ import Ġjavax . lang . model . type . Declared Type Ċ import Ġjavax . lang . model . type . Type Mirror Ċ import Ġjavax . lang . model . util . Elements Ċ import Ġjavax . lang . model . util . Types Ċ import Ġjavax . persistence .* Ċ Ċ data Ġclass ĠType Environment ( ĊĠĠĠ Ġval Ġtype Utils : ĠTypes , ĊĠĠĠ Ġval Ġelement Utils : ĠElements Ċ ) Ġ{ ĊĠĠĠ Ġfun Ġis SubType ( type : ĠType Mirror , Ġqualified Name : ĠCharSequence ) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtype Utils . is Subtype ( type , Ġelement Utils . getType Element ( qualified Name ). as Type ()) ĊĊĠĠĠ Ġfun Ġis Same Type ( type : ĠType Mirror , Ġqualified Name : ĠCharSequence ) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtype Utils . is Same Type ( type , Ġelement Utils . getType Element ( qualified Name ). as Type ()) Ċ } Ċ Ċ data Ġclass ĠAnnotation Environment ( ĊĠĠĠ Ġval Ġentities : ĠList < Type Element >, ĊĠĠĠ Ġval Ġids : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġembedded Ids : ĠList < Variable Element > Ġ= Ġempty List (), ĊĠĠĠ Ġval Ġcolumns : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġone ToMany : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġmany ToOne : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġmany ToMany : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġone ToOne : ĠList < Variable Element >, ĊĠĠĠ Ġval Ġembedded : ĠList < Variable Element > Ġ= Ġempty List (), ĊĠĠĠ Ġval Ġembedded Column : ĠList < Variable Element > Ġ= Ġempty List () Ċ ) Ċ Ċ fun ĠElement . enc lo sing Type Element () Ġ= Ġthis . enc lo sing Element . to Type Element () Ċ Ċ fun ĠElement . to Type Element (): ĠType Element Ġ{ ĊĠĠĠ Ġrequire ( this Ġis ĠType Element ) Ġ{ Ġ" Invalid Ġelement Ġtype Ġ${ this . kind }, Ġtype Ġexpected " Ġ} ĊĠĠĠ Ġreturn Ġthis Ċ } ĊĊ Ġfun ĠElement . to Variable Element (): ĠVariable Element Ġ{ ĊĠĠĠ Ġrequire ( this Ġis ĠVariable Element ) Ġ{ Ġ" Invalid Ġelement Ġtype Ġ${ this . kind }, Ġvar Ġexpected " Ġ} ĊĠĠĠ Ġreturn Ġthis Ċ } Ċ Ċ @ Kotlin Po et Metadata Preview Ċ class ĠEnvironment Builder ( private Ġval Ġround Env : ĠRound Environment , Ġprivate Ġval Ġprocessing Env : ĠProcessing Environment ) Ġ{ ĊĊĠĠĠ Ġfun Ġbuild Annotation Env (): ĠAnnotation Environment Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġentities Ġ= Ġround Env . getElement s Annotated With ( Entity :: class . java ). to Type Elements () ĊĠĠĠĠĠĠĠ Ġval Ġids Ġ= Ġround Env . getElement s Annotated With ( Id :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġembedded Ids Ġ= Ġround Env . getElement s Annotated With ( Embedded Id :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġone ToMany Ġ= Ġround Env . getElement s Annotated With ( OneToMany :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġmany ToOne Ġ= Ġround Env . getElement s Annotated With ( ManyToOne :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġmany ToMany Ġ= Ġround Env . getElement s Annotated With ( ManyToMany :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġone ToOne Ġ= Ġround Env . getElement s Annotated With ( One ToOne :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġcolumns Ġ= Ġ( round Env . root Elements . as Sequence (). map ( this :: to Column Elements ). flatten () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. minus ( ids Ġ+ Ġembedded Ids Ġ+ Ġone ToOne Ġ+ Ġone ToMany Ġ+ Ġmany ToOne Ġ+ Ġmany ToMany )). toList () ĊĠĠĠĠĠĠĠ Ġval Ġembedded Ġ= Ġround Env . getElement s Annotated With ( Embedded :: class . java ). to Variable Elements () ĊĠĠĠĠĠĠĠ Ġval Ġembedded Column Ġ= Ġround Env . getElement s Annotated With ( Embed d able :: class . java ). map ( this :: to Embedded Elements ). flatten (). toList () ĊĊĠĠĠĠĠĠĠ Ġreturn ĠAnnotation Environment ( entities Ġ= Ġentities , Ġids Ġ= Ġids , Ġembedded Ids Ġ= Ġembedded Ids , Ġcolumns Ġ= Ġcolumns , Ġone ToMany Ġ= Ġone ToMany , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmany ToOne Ġ= Ġmany ToOne , Ġmany ToMany Ġ= Ġmany ToMany , Ġone ToOne Ġ= Ġone ToOne , Ġembedded Ġ= Ġembedded , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġembedded Column Ġ= Ġembedded Column ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġto Column Elements ( entity : ĠElement ) Ġ= Ġentity . enc losed Elements . filter ( this :: is Column ). map ( Element :: to Variable Element ) ĊĊĠĠĠ Ġprivate Ġfun Ġis Column ( element : ĠElement ) Ġ= Ġelement . kind Ġ== ĠElement Kind . FIELD Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelement . enc lo sing Element . getAnnotation ( Entity :: class . java ) Ġ!= Ġnull Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelement . getAnnotation ( Transient :: class . java ) Ġ== Ġnull Ġ&& Ġelement . getAnnotation ( Embedded :: class . java ) Ġ== Ġnull ĊĊĠĠĠ Ġprivate Ġfun Ġto Embedded Elements ( embed d able : ĠElement ): ĠList < Variable Element > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġen closing Km Class Ġ= Ġembed d able . to Type Element (). to Immutable Km Class () ĊĠĠĠĠĠĠĠ Ġval Ġproperty Names Ġ= Ġen closing Km Class . properties . map Ġ{ Ġit . name Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġ( embed d able . as Type () Ġas ĠDecl ared Type ). as Element (). enc losed Elements ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġproperty Names . contains ( it . simple Name . toString ()) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter ( this :: is Embedded ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map ( Element :: to Variable Element ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġis Embedded ( element : ĠElement ) Ġ= Ġelement . kind Ġ== ĠElement Kind . FIELD Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelement . enc lo sing Element . getAnnotation ( Embed d able :: class . java ) Ġ!= Ġnull Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelement . getAnnotation ( Transient :: class . java ) Ġ== Ġnull Ġ&& Ġelement . getAnnotation ( Embedded :: class . java ) Ġ== Ġnull ĊĊĊĠĠĠ Ġfun Ġbuild Type Env () Ġ= ĠType Environment ( processing Env . type Utils , Ġprocessing Env . element Utils ) ĊĊĠĠĠ Ġprivate Ġfun ĠCollection < Element >. to Type Elements () Ġ= Ġthis . map ( Element :: to Type Element ) ĊĠĠĠ Ġprivate Ġfun ĠCollection < Element >. to Variable Elements () Ġ= Ġthis . map ( Element :: to Variable Element ) Ċ Ċ } Ċ