{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
module Language.JVM.Attribute.EnclosingMethod
( EnclosingMethod (..)
) where
import Language.JVM.Attribute.Base
import Language.JVM.Constant
import Language.JVM.Staged
instance IsAttribute (EnclosingMethod Low) where
attrName = Const "EnclosingMethod"
data EnclosingMethod r = EnclosingMethod
{ enclosingClassName :: !(Ref ClassName r)
, enclosingMethodName :: !(Ref (Maybe MethodId) r)
}
instance Staged EnclosingMethod where
evolve (EnclosingMethod cn mn) = label "EnclosingMethod" $ do
EnclosingMethod
<$> link cn
<*> if mn == 0 then return Nothing else Just <$> link mn
devolve (EnclosingMethod cn mn) = label "EnclosingMethod" $ do
EnclosingMethod
<$> unlink cn
<*> case mn of
Nothing -> return 0
Just mn' -> unlink mn'
$(deriveBaseWithBinary ''EnclosingMethod)