From 4cab082267918d7924798bc8cc3598efc7df682c Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 18:47:49 +0900 Subject: [PATCH 1/2] Added genAliasClass --- .../Language/MessagePack/IDL/CodeGen/Java.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index 979e2ef..444b749 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -27,6 +27,7 @@ generate config spec = do let typeAlias = map genAlias $ filter isMPType spec genTuple config + mapM_ (genAliasClass config) $ typeAlias mapM_ (genClient typeAlias config) spec mapM_ (genStruct typeAlias $ configPackage config) spec mapM_ (genException $ configPackage config) spec @@ -40,6 +41,24 @@ package #{configPackage} |] --} +genAliasClass :: Config -> (T.Text, Type) -> IO() +genAliasClass Config{..} alias = do + let typeName = formatClassNameT $ fst alias + actualType = snd alias + dirName = joinPath $ map LT.unpack $ LT.split (== '.') $ LT.pack configPackage + fileName = dirName ++ "/" ++ (T.unpack typeName) ++ ".java" + LT.writeFile fileName $ templ configFilePath [lt| +package #{configPackage}; + +import org.msgpack.MessagePack; +import org.msgpack.annotation.Message; + +@Message +public class #{typeName} { + #{genType actualType} impl; +}; +|] + genTuple :: Config -> IO() genTuple Config {..} = do LT.writeFile("Tuple.java") $ templ (configFilePath) [lt| From ae51f748319e12832fe3ffed106f53d583e1c2a3 Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 18:52:43 +0900 Subject: [PATCH 2/2] Disabled resoluation of type alias --- .../Language/MessagePack/IDL/CodeGen/Java.hs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index 444b749..baf8490 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -28,8 +28,8 @@ generate config spec = do genTuple config mapM_ (genAliasClass config) $ typeAlias - mapM_ (genClient typeAlias config) spec - mapM_ (genStruct typeAlias $ configPackage config) spec + mapM_ (genClient config) spec + mapM_ (genStruct config) spec mapM_ (genException $ configPackage config) spec {-- @@ -75,30 +75,29 @@ genImport packageName MPMessage {..} = |] genImport _ _ = "" -genStruct :: [(T.Text, Type)] -> FilePath -> Decl -> IO() -genStruct alias packageName MPMessage {..} = do +genStruct :: Config -> Decl -> IO() +genStruct Config {..} MPMessage {..} = do let params = if null msgParam then "" else [lt|<#{T.intercalate ", " msgParam}>|] - resolvedMsgFields = map (resolveFieldAlias alias) msgFields - hashMapImport | not $ null [() | TMap _ _ <- map fldType resolvedMsgFields] = [lt|import java.util.HashMap;|] + hashMapImport | not $ null [() | TMap _ _ <- map fldType msgFields] = [lt|import java.util.HashMap;|] | otherwise = "" - arrayListImport | not $ null [() | TList _ <- map fldType resolvedMsgFields] = [lt|import java.util.ArrayList;|] + arrayListImport | not $ null [() | TList _ <- map fldType msgFields] = [lt|import java.util.ArrayList;|] | otherwise = "" LT.writeFile ( (formatClassName $ T.unpack msgName) ++ ".java") [lt| -package #{packageName}; +package #{configPackage}; #{hashMapImport} #{arrayListImport} public class #{formatClassNameT msgName} #{params} { -#{LT.concat $ map genDecl resolvedMsgFields} +#{LT.concat $ map genDecl msgFields} public #{formatClassNameT msgName}() { - #{LT.concat $ map genInit resolvedMsgFields} + #{LT.concat $ map genInit msgFields} } }; |] -genStruct _ _ _ = return () +genStruct _ _ = return () resolveMethodAlias :: [(T.Text, Type)] -> Method -> Method resolveMethodAlias alias Function {..} = Function methodInherit methodName (resolveTypeAlias alias methodRetType) (map (resolveFieldAlias alias) methodArgs) @@ -154,12 +153,11 @@ public class #{formatClassNameT excName} #{params}{ Nothing -> "" genException _ _ = return () -genClient :: [(T.Text, Type)] -> Config -> Decl -> IO() -genClient alias Config {..} MPService {..} = do - let resolvedServiceMethods = map (resolveMethodAlias alias) serviceMethods - hashMapImport | not $ null [() | TMap _ _ <- map methodRetType resolvedServiceMethods ] = [lt|import java.util.HashMap;|] +genClient :: Config -> Decl -> IO() +genClient Config {..} MPService {..} = do + let hashMapImport | not $ null [() | TMap _ _ <- map methodRetType serviceMethods ] = [lt|import java.util.HashMap;|] | otherwise = "" - arrayListImport | not $ null [() | TList _ <- map methodRetType resolvedServiceMethods] = [lt|import java.util.ArrayList;|] + arrayListImport | not $ null [() | TList _ <- map methodRetType serviceMethods] = [lt|import java.util.ArrayList;|] | otherwise = "" LT.writeFile (T.unpack className ++ ".java") $ templ configFilePath [lt| @@ -178,10 +176,10 @@ public class #{className} { } public static interface RPCInterface { -#{LT.concat $ map genSignature resolvedServiceMethods} +#{LT.concat $ map genSignature serviceMethods} } -#{LT.concat $ map genMethodCall resolvedServiceMethods} +#{LT.concat $ map genMethodCall serviceMethods} private Client c_; private RPCInterface iface_; }; @@ -204,7 +202,7 @@ public class #{className} { |] genMethodCall _ = "" -genClient _ _ _ = return () +genClient _ _ = return () genSignature :: Method -> LT.Text genSignature Function {..} =