cabal: bump data-default dependency to 0.5.0.
[hs-java.git] / Java / ClassPath / Types.hs
1
2 module Java.ClassPath.Types where
3
4 import Control.Monad.State
5 import Data.List
6
7 import JVM.ClassFile
8
9 -- | Directories tree
10 data Tree a =
11     Directory FilePath [Tree a]
12   | File a
13   deriving (Eq)
14
15 instance Show a => Show (Tree a) where
16   show (Directory dir forest) = dir ++ "/{" ++ intercalate ", " (map show forest) ++ "}"
17   show (File a) = show a
18
19 -- | ClassPath entry
20 data CPEntry =
21     NotLoaded FilePath                -- ^ Not loaded .class file
22   | Loaded FilePath (Class Direct)    -- ^ Class loaded from .class file
23   | NotLoadedJAR FilePath FilePath    -- ^ Not loaded .jar file
24   | LoadedJAR FilePath (Class Direct) -- ^ Class loaded from .jar file
25   deriving (Eq)
26
27 instance Show CPEntry where
28   show (NotLoaded path) = "<Not loaded file: " ++ path ++ ">"
29   show (Loaded path cls) = "<Loaded from " ++ path ++ ": " ++ toString (thisClass cls) ++ ">"
30   show (NotLoadedJAR jar path) = "<Not loaded JAR: " ++ jar ++ ": " ++ path ++ ">"
31   show (LoadedJAR path cls) = "<Read JAR: " ++ path ++ ": " ++ toString (thisClass cls) ++ ">"
32
33 -- | ClassPath monad
34 type ClassPath a = StateT [Tree CPEntry] IO a
35