{-|
Module      : Language.JVM.Method
Copyright   : (c) Christian Gram Kalhauge, 2017
License     : MIT
Maintainer  : kalhuage@cs.ucla.edu
-}
{-# LANGUAGE ScopedTypeVariables  #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# LANGUAGE TemplateHaskell      #-}
{-# LANGUAGE DeriveAnyClass       #-}
{-# LANGUAGE DeriveGeneric        #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE StandaloneDeriving   #-}
{-# LANGUAGE RecordWildCards   #-}
module Language.JVM.Method
  ( Method(..)
  , mAccessFlags

  -- * Attributes
  , MethodAttributes(..)
  , emptyMethodAttributes
  , mCode
  , mExceptions'
  , mExceptions
  , mSignature
  )
where

-- base
import           Data.Monoid

-- containers
import           Data.Set                       ( Set )

-- text
import qualified Data.Text                     as Text

import           Language.JVM.AccessFlag
import           Language.JVM.Attribute
import           Language.JVM.Attribute.Exceptions
                                                ( exceptions )
import           Language.JVM.Constant
import           Language.JVM.Staged
import           Language.JVM.Type
import           Language.JVM.Utils

-- | A Method in the class-file, as described
-- [here](http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6).
data Method r = Method
  { Method r -> BitSet16 MAccessFlag
mAccessFlags' :: !(BitSet16 MAccessFlag)
  , Method r -> Ref Text r
mName         :: !(Ref Text.Text r)
  , Method r -> Ref MethodDescriptor r
mDescriptor   :: !(Ref MethodDescriptor r)
  , Method r -> Attributes MethodAttributes r
mAttributes   :: !(Attributes MethodAttributes r)
  }

-- | Unpack the BitSet and get the AccessFlags as a Set.
mAccessFlags :: Method r -> Set MAccessFlag
mAccessFlags :: Method r -> Set MAccessFlag
mAccessFlags = BitSet16 MAccessFlag -> Set MAccessFlag
forall w a. BitSet w a -> Set a
toSet (BitSet16 MAccessFlag -> Set MAccessFlag)
-> (Method r -> BitSet16 MAccessFlag)
-> Method r
-> Set MAccessFlag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method r -> BitSet16 MAccessFlag
forall r. Method r -> BitSet16 MAccessFlag
mAccessFlags'

data MethodAttributes r = MethodAttributes
  { MethodAttributes r -> [Code r]
maCode                          :: [Code r]
  , MethodAttributes r -> [Exceptions r]
maExceptions                    :: [Exceptions r]
  , MethodAttributes r -> [Signature r]
maSignatures                    :: [Signature r]
  , MethodAttributes r -> [AnnotationDefault r]
maAnnotationDefault             :: [AnnotationDefault r]
  , MethodAttributes r -> [MethodParameters r]
maMethodParameters              :: [MethodParameters r]
  , MethodAttributes r -> [RuntimeVisibleAnnotations r]
maVisibleAnnotations            :: [RuntimeVisibleAnnotations r]
  , MethodAttributes r -> [RuntimeInvisibleAnnotations r]
maInvisibleAnnotations          :: [RuntimeInvisibleAnnotations r]
  , MethodAttributes r -> [RuntimeVisibleParameterAnnotations r]
maVisibleParameterAnnotations   :: [RuntimeVisibleParameterAnnotations r]
  , MethodAttributes r -> [RuntimeInvisibleParameterAnnotations r]
maInvisibleParameterAnnotations  :: [RuntimeInvisibleParameterAnnotations r]
  , MethodAttributes r
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation r]
maVisibleTypeAnnotations            ::
      [RuntimeVisibleTypeAnnotations MethodTypeAnnotation r]
  , MethodAttributes r
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation r]
maInvisibleTypeAnnotations          ::
      [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation r]
  , MethodAttributes r -> [Attribute r]
maOthers               :: [Attribute r]
  }

emptyMethodAttributes :: MethodAttributes High
emptyMethodAttributes :: MethodAttributes High
emptyMethodAttributes = [Code High]
-> [Exceptions High]
-> [Signature High]
-> [AnnotationDefault High]
-> [MethodParameters High]
-> [RuntimeVisibleAnnotations High]
-> [RuntimeInvisibleAnnotations High]
-> [RuntimeVisibleParameterAnnotations High]
-> [RuntimeInvisibleParameterAnnotations High]
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
-> [Attribute High]
-> MethodAttributes High
forall r.
[Code r]
-> [Exceptions r]
-> [Signature r]
-> [AnnotationDefault r]
-> [MethodParameters r]
-> [RuntimeVisibleAnnotations r]
-> [RuntimeInvisibleAnnotations r]
-> [RuntimeVisibleParameterAnnotations r]
-> [RuntimeInvisibleParameterAnnotations r]
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation r]
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation r]
-> [Attribute r]
-> MethodAttributes r
MethodAttributes [] [] [] [] [] [] [] [] [] [] [] []

-- | Fetch the 'Code' attribute, if any.
-- There can only be one code attribute in a method.
mCode :: Method High -> Maybe (Code High)
mCode :: Method High -> Maybe (Code High)
mCode = [Code High] -> Maybe (Code High)
forall a. [a] -> Maybe a
firstOne ([Code High] -> Maybe (Code High))
-> (Method High -> [Code High]) -> Method High -> Maybe (Code High)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodAttributes High -> [Code High]
forall r. MethodAttributes r -> [Code r]
maCode (MethodAttributes High -> [Code High])
-> (Method High -> MethodAttributes High)
-> Method High
-> [Code High]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method High -> MethodAttributes High
forall r. Method r -> Attributes MethodAttributes r
mAttributes

-- | Fetch the 'Exceptions' attribute.
-- There can only be one exceptions attribute in a method.
mExceptions' :: Method High -> Maybe (Exceptions High)
mExceptions' :: Method High -> Maybe (Exceptions High)
mExceptions' = [Exceptions High] -> Maybe (Exceptions High)
forall a. [a] -> Maybe a
firstOne ([Exceptions High] -> Maybe (Exceptions High))
-> (Method High -> [Exceptions High])
-> Method High
-> Maybe (Exceptions High)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodAttributes High -> [Exceptions High]
forall r. MethodAttributes r -> [Exceptions r]
maExceptions (MethodAttributes High -> [Exceptions High])
-> (Method High -> MethodAttributes High)
-> Method High
-> [Exceptions High]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method High -> MethodAttributes High
forall r. Method r -> Attributes MethodAttributes r
mAttributes

-- | Fetches the 'Exceptions' attribute, but turns it into an list of exceptions.
-- If no exceptions field where found the empty list is returned
mExceptions :: Method High -> [ClassName]
mExceptions :: Method High -> [ClassName]
mExceptions = [ClassName]
-> (Exceptions High -> [ClassName])
-> Maybe (Exceptions High)
-> [ClassName]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (SizedList Word16 ClassName -> [ClassName]
forall w a. SizedList w a -> [a]
unSizedList (SizedList Word16 ClassName -> [ClassName])
-> (Exceptions High -> SizedList Word16 ClassName)
-> Exceptions High
-> [ClassName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Exceptions High -> SizedList Word16 ClassName
forall r. Exceptions r -> SizedList16 (Ref ClassName r)
exceptions) (Maybe (Exceptions High) -> [ClassName])
-> (Method High -> Maybe (Exceptions High))
-> Method High
-> [ClassName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method High -> Maybe (Exceptions High)
mExceptions'

-- | Fetches the 'Signature' attribute, if any.
mSignature :: Method High -> Maybe (Signature High)
mSignature :: Method High -> Maybe (Signature High)
mSignature = [Signature High] -> Maybe (Signature High)
forall a. [a] -> Maybe a
firstOne ([Signature High] -> Maybe (Signature High))
-> (Method High -> [Signature High])
-> Method High
-> Maybe (Signature High)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodAttributes High -> [Signature High]
forall r. MethodAttributes r -> [Signature r]
maSignatures (MethodAttributes High -> [Signature High])
-> (Method High -> MethodAttributes High)
-> Method High
-> [Signature High]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method High -> MethodAttributes High
forall r. Method r -> Attributes MethodAttributes r
mAttributes

instance Staged Method where
  evolve :: Method Low -> m (Method High)
evolve (Method BitSet16 MAccessFlag
mf Ref Text Low
mn Ref MethodDescriptor Low
md Attributes MethodAttributes Low
mattr) = String -> m (Method High) -> m (Method High)
forall (m :: * -> *) a. LabelM m => String -> m a -> m a
label String
"Method" (m (Method High) -> m (Method High))
-> m (Method High) -> m (Method High)
forall a b. (a -> b) -> a -> b
$ do
    Text
mn' <- Word16 -> m Text
forall (m :: * -> *) r.
(EvolveM m, Referenceable r) =>
Word16 -> m r
link Word16
Ref Text Low
mn
    MethodDescriptor
md' <- Word16 -> m MethodDescriptor
forall (m :: * -> *) r.
(EvolveM m, Referenceable r) =>
Word16 -> m r
link Word16
Ref MethodDescriptor Low
md
    String -> m (Method High) -> m (Method High)
forall (m :: * -> *) a. LabelM m => String -> m a -> m a
label (Text -> String
Text.unpack (Text -> String) -> (MethodId -> Text) -> MethodId -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MethodId -> Text
forall a. TextSerializable a => a -> Text
serialize (MethodId -> String) -> MethodId -> String
forall a b. (a -> b) -> a -> b
$ Text
mn' Text -> MethodDescriptor -> WithNameId MethodDescriptor
forall n. WithName n => Text -> n -> WithNameId n
<:> MethodDescriptor
md') (m (Method High) -> m (Method High))
-> m (Method High) -> m (Method High)
forall a b. (a -> b) -> a -> b
$ do
      MethodAttributes High
mattr' <-
        (Endo (MethodAttributes High) -> MethodAttributes High)
-> m (Endo (MethodAttributes High)) -> m (MethodAttributes High)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Endo (MethodAttributes High)
-> MethodAttributes High -> MethodAttributes High
forall a. Endo a -> a -> a
`appEndo` MethodAttributes High
emptyMethodAttributes)
        (m (Endo (MethodAttributes High)) -> m (MethodAttributes High))
-> ((Attribute High -> m (Endo (MethodAttributes High)))
    -> m (Endo (MethodAttributes High)))
-> (Attribute High -> m (Endo (MethodAttributes High)))
-> m (MethodAttributes High)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AttributeLocation
-> SizedList Word16 (Attribute Low)
-> (Attribute High -> m (Endo (MethodAttributes High)))
-> m (Endo (MethodAttributes High))
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, EvolveM m, Monoid a) =>
AttributeLocation
-> f (Attribute Low) -> (Attribute High -> m a) -> m a
fromAttributes AttributeLocation
MethodAttribute Attributes MethodAttributes Low
SizedList Word16 (Attribute Low)
mattr
        ((Attribute High -> m (Endo (MethodAttributes High)))
 -> m (MethodAttributes High))
-> (Attribute High -> m (Endo (MethodAttributes High)))
-> m (MethodAttributes High)
forall a b. (a -> b) -> a -> b
$ [AttributeCollector (MethodAttributes High)]
-> (Attribute High
    -> MethodAttributes High -> MethodAttributes High)
-> Attribute High
-> m (Endo (MethodAttributes High))
forall c (m :: * -> *).
EvolveM m =>
[AttributeCollector c]
-> (Attribute High -> c -> c) -> Attribute High -> m (Endo c)
collect
            [ (Code High -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr (\Code High
e MethodAttributes High
a -> MethodAttributes High
a { maCode :: [Code High]
maCode = Code High
e Code High -> [Code High] -> [Code High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [Code High]
forall r. MethodAttributes r -> [Code r]
maCode MethodAttributes High
a })
            , (Exceptions High -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr (\Exceptions High
e MethodAttributes High
a -> MethodAttributes High
a { maExceptions :: [Exceptions High]
maExceptions = Exceptions High
e Exceptions High -> [Exceptions High] -> [Exceptions High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [Exceptions High]
forall r. MethodAttributes r -> [Exceptions r]
maExceptions MethodAttributes High
a })
            , (Signature High -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr (\Signature High
e MethodAttributes High
a -> MethodAttributes High
a { maSignatures :: [Signature High]
maSignatures = Signature High
e Signature High -> [Signature High] -> [Signature High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [Signature High]
forall r. MethodAttributes r -> [Signature r]
maSignatures MethodAttributes High
a })
            , (AnnotationDefault High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\AnnotationDefault High
e MethodAttributes High
a -> MethodAttributes High
a { maAnnotationDefault :: [AnnotationDefault High]
maAnnotationDefault = AnnotationDefault High
e AnnotationDefault High
-> [AnnotationDefault High] -> [AnnotationDefault High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [AnnotationDefault High]
forall r. MethodAttributes r -> [AnnotationDefault r]
maAnnotationDefault MethodAttributes High
a })
            , (RuntimeVisibleAnnotations High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeVisibleAnnotations High
e MethodAttributes High
a -> MethodAttributes High
a { maVisibleAnnotations :: [RuntimeVisibleAnnotations High]
maVisibleAnnotations = RuntimeVisibleAnnotations High
e RuntimeVisibleAnnotations High
-> [RuntimeVisibleAnnotations High]
-> [RuntimeVisibleAnnotations High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [RuntimeVisibleAnnotations High]
forall r. MethodAttributes r -> [RuntimeVisibleAnnotations r]
maVisibleAnnotations MethodAttributes High
a })
            , (RuntimeInvisibleAnnotations High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeInvisibleAnnotations High
e MethodAttributes High
a ->
                MethodAttributes High
a { maInvisibleAnnotations :: [RuntimeInvisibleAnnotations High]
maInvisibleAnnotations = RuntimeInvisibleAnnotations High
e RuntimeInvisibleAnnotations High
-> [RuntimeInvisibleAnnotations High]
-> [RuntimeInvisibleAnnotations High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [RuntimeInvisibleAnnotations High]
forall r. MethodAttributes r -> [RuntimeInvisibleAnnotations r]
maInvisibleAnnotations MethodAttributes High
a }
              )
            , (RuntimeVisibleParameterAnnotations High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeVisibleParameterAnnotations High
e MethodAttributes High
a -> MethodAttributes High
a
                { maVisibleParameterAnnotations :: [RuntimeVisibleParameterAnnotations High]
maVisibleParameterAnnotations =
                  RuntimeVisibleParameterAnnotations High
e RuntimeVisibleParameterAnnotations High
-> [RuntimeVisibleParameterAnnotations High]
-> [RuntimeVisibleParameterAnnotations High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [RuntimeVisibleParameterAnnotations High]
forall r.
MethodAttributes r -> [RuntimeVisibleParameterAnnotations r]
maVisibleParameterAnnotations MethodAttributes High
a
                }
              )
            , (RuntimeInvisibleParameterAnnotations High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeInvisibleParameterAnnotations High
e MethodAttributes High
a -> MethodAttributes High
a
                { maInvisibleParameterAnnotations :: [RuntimeInvisibleParameterAnnotations High]
maInvisibleParameterAnnotations =
                  RuntimeInvisibleParameterAnnotations High
e RuntimeInvisibleParameterAnnotations High
-> [RuntimeInvisibleParameterAnnotations High]
-> [RuntimeInvisibleParameterAnnotations High]
forall a. a -> [a] -> [a]
: MethodAttributes High
-> [RuntimeInvisibleParameterAnnotations High]
forall r.
MethodAttributes r -> [RuntimeInvisibleParameterAnnotations r]
maInvisibleParameterAnnotations MethodAttributes High
a
                }
              )
            , (RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
e MethodAttributes High
a -> MethodAttributes High
a
                { maVisibleTypeAnnotations :: [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
maVisibleTypeAnnotations = RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
e RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
forall a. a -> [a] -> [a]
: MethodAttributes High
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
forall r.
MethodAttributes r
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation r]
maVisibleTypeAnnotations MethodAttributes High
a
                }
              )
            , (RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr
              (\RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
e MethodAttributes High
a -> MethodAttributes High
a
                { maInvisibleTypeAnnotations :: [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
maInvisibleTypeAnnotations = RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
e RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
forall a. a -> [a] -> [a]
: MethodAttributes High
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
forall r.
MethodAttributes r
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation r]
maInvisibleTypeAnnotations MethodAttributes High
a
                }
              )
            , (MethodParameters High
 -> MethodAttributes High -> MethodAttributes High)
-> AttributeCollector (MethodAttributes High)
forall c (a :: * -> *).
(IsAttribute (a Low), Staged a) =>
(a High -> c -> c) -> AttributeCollector c
Attr (\MethodParameters High
e MethodAttributes High
a -> MethodAttributes High
a { maMethodParameters :: [MethodParameters High]
maMethodParameters = MethodParameters High
e MethodParameters High
-> [MethodParameters High] -> [MethodParameters High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [MethodParameters High]
forall r. MethodAttributes r -> [MethodParameters r]
maMethodParameters MethodAttributes High
a })
            ]
            (\Attribute High
e MethodAttributes High
a -> MethodAttributes High
a { maOthers :: [Attribute High]
maOthers = Attribute High
e Attribute High -> [Attribute High] -> [Attribute High]
forall a. a -> [a] -> [a]
: MethodAttributes High -> [Attribute High]
forall r. MethodAttributes r -> [Attribute r]
maOthers MethodAttributes High
a })
      Method High -> m (Method High)
forall (m :: * -> *) a. Monad m => a -> m a
return (Method High -> m (Method High)) -> Method High -> m (Method High)
forall a b. (a -> b) -> a -> b
$ BitSet16 MAccessFlag
-> Ref Text High
-> Ref MethodDescriptor High
-> Attributes MethodAttributes High
-> Method High
forall r.
BitSet16 MAccessFlag
-> Ref Text r
-> Ref MethodDescriptor r
-> Attributes MethodAttributes r
-> Method r
Method BitSet16 MAccessFlag
mf Text
Ref Text High
mn' Ref MethodDescriptor High
MethodDescriptor
md' Attributes MethodAttributes High
MethodAttributes High
mattr'

  devolve :: Method High -> m (Method Low)
devolve (Method BitSet16 MAccessFlag
mf Ref Text High
mn Ref MethodDescriptor High
md Attributes MethodAttributes High
mattr) = do
    Word16
mn'    <- Text -> m Word16
forall (m :: * -> *) r.
(DevolveM m, Referenceable r) =>
r -> m Word16
unlink Text
Ref Text High
mn
    Word16
md'    <- MethodDescriptor -> m Word16
forall (m :: * -> *) r.
(DevolveM m, Referenceable r) =>
r -> m Word16
unlink Ref MethodDescriptor High
MethodDescriptor
md
    [Attribute Low]
mattr' <- MethodAttributes High -> m [Attribute Low]
forall (f :: * -> *).
DevolveM f =>
MethodAttributes High -> f [Attribute Low]
fromMethodAttributes Attributes MethodAttributes High
MethodAttributes High
mattr
    Method Low -> m (Method Low)
forall (m :: * -> *) a. Monad m => a -> m a
return (Method Low -> m (Method Low)) -> Method Low -> m (Method Low)
forall a b. (a -> b) -> a -> b
$ BitSet16 MAccessFlag
-> Ref Text Low
-> Ref MethodDescriptor Low
-> Attributes MethodAttributes Low
-> Method Low
forall r.
BitSet16 MAccessFlag
-> Ref Text r
-> Ref MethodDescriptor r
-> Attributes MethodAttributes r
-> Method r
Method BitSet16 MAccessFlag
mf Word16
Ref Text Low
mn' Word16
Ref MethodDescriptor Low
md' ([Attribute Low] -> SizedList Word16 (Attribute Low)
forall w a. [a] -> SizedList w a
SizedList [Attribute Low]
mattr')
   where
    fromMethodAttributes :: MethodAttributes High -> f [Attribute Low]
fromMethodAttributes MethodAttributes {[Attribute High]
[Signature High]
[Exceptions High]
[AnnotationDefault High]
[RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
[RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
[RuntimeInvisibleParameterAnnotations High]
[RuntimeVisibleParameterAnnotations High]
[RuntimeInvisibleAnnotations High]
[RuntimeVisibleAnnotations High]
[Code High]
[MethodParameters High]
maOthers :: [Attribute High]
maInvisibleTypeAnnotations :: [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
maVisibleTypeAnnotations :: [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
maInvisibleParameterAnnotations :: [RuntimeInvisibleParameterAnnotations High]
maVisibleParameterAnnotations :: [RuntimeVisibleParameterAnnotations High]
maInvisibleAnnotations :: [RuntimeInvisibleAnnotations High]
maVisibleAnnotations :: [RuntimeVisibleAnnotations High]
maMethodParameters :: [MethodParameters High]
maAnnotationDefault :: [AnnotationDefault High]
maSignatures :: [Signature High]
maExceptions :: [Exceptions High]
maCode :: [Code High]
maOthers :: forall r. MethodAttributes r -> [Attribute r]
maInvisibleTypeAnnotations :: forall r.
MethodAttributes r
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation r]
maVisibleTypeAnnotations :: forall r.
MethodAttributes r
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation r]
maInvisibleParameterAnnotations :: forall r.
MethodAttributes r -> [RuntimeInvisibleParameterAnnotations r]
maVisibleParameterAnnotations :: forall r.
MethodAttributes r -> [RuntimeVisibleParameterAnnotations r]
maInvisibleAnnotations :: forall r. MethodAttributes r -> [RuntimeInvisibleAnnotations r]
maVisibleAnnotations :: forall r. MethodAttributes r -> [RuntimeVisibleAnnotations r]
maMethodParameters :: forall r. MethodAttributes r -> [MethodParameters r]
maAnnotationDefault :: forall r. MethodAttributes r -> [AnnotationDefault r]
maSignatures :: forall r. MethodAttributes r -> [Signature r]
maExceptions :: forall r. MethodAttributes r -> [Exceptions r]
maCode :: forall r. MethodAttributes r -> [Code r]
..} = [[Attribute Low]] -> [Attribute Low]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Attribute Low]] -> [Attribute Low])
-> f [[Attribute Low]] -> f [Attribute Low]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [f [Attribute Low]] -> f [[Attribute Low]]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
      [ (Code High -> f (Attribute Low))
-> [Code High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Code High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [Code High]
maCode
      , (Exceptions High -> f (Attribute Low))
-> [Exceptions High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Exceptions High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [Exceptions High]
maExceptions
      , (Signature High -> f (Attribute Low))
-> [Signature High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Signature High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [Signature High]
maSignatures
      , (AnnotationDefault High -> f (Attribute Low))
-> [AnnotationDefault High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM AnnotationDefault High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [AnnotationDefault High]
maAnnotationDefault
      , (RuntimeVisibleAnnotations High -> f (Attribute Low))
-> [RuntimeVisibleAnnotations High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeVisibleAnnotations High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeVisibleAnnotations High]
maVisibleAnnotations
      , (RuntimeInvisibleAnnotations High -> f (Attribute Low))
-> [RuntimeInvisibleAnnotations High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeInvisibleAnnotations High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeInvisibleAnnotations High]
maInvisibleAnnotations
      , (RuntimeVisibleParameterAnnotations High -> f (Attribute Low))
-> [RuntimeVisibleParameterAnnotations High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeVisibleParameterAnnotations High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeVisibleParameterAnnotations High]
maVisibleParameterAnnotations
      , (RuntimeInvisibleParameterAnnotations High -> f (Attribute Low))
-> [RuntimeInvisibleParameterAnnotations High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeInvisibleParameterAnnotations High -> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeInvisibleParameterAnnotations High]
maInvisibleParameterAnnotations
      , (RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
 -> f (Attribute Low))
-> [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
-> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeVisibleTypeAnnotations MethodTypeAnnotation High
-> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeVisibleTypeAnnotations MethodTypeAnnotation High]
maVisibleTypeAnnotations
      , (RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
 -> f (Attribute Low))
-> [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
-> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High
-> f (Attribute Low)
forall (a :: * -> *) (m :: * -> *).
(IsAttribute (a Low), Staged a, DevolveM m) =>
a High -> m (Attribute Low)
toAttribute [RuntimeInvisibleTypeAnnotations MethodTypeAnnotation High]
maInvisibleTypeAnnotations
      , (Attribute High -> f (Attribute Low))
-> [Attribute High] -> f [Attribute Low]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Attribute High -> f (Attribute Low)
forall (s :: * -> *) (m :: * -> *).
(Staged s, DevolveM m) =>
s High -> m (s Low)
devolve     [Attribute High]
maOthers
      ]

$(deriveBase ''MethodAttributes)
$(deriveBaseWithBinary ''Method)