From 26a60066614163eaebd4e1adf1f9aa8da9908800 Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 18:57:53 +0900 Subject: [PATCH 1/5] Added extractType, extractTypeFromMethod, and extractTypeFromType --- .../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..f8367ee 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -50,6 +50,25 @@ public class Tuple { }; |] +extractType :: Decl -> [Type] +extractType MPMessage {..} = map fldType msgFields +extractType MPException {..} = map fldType excFields +extractType MPType {..} = [tyType] +extractType MPEnum {..} = [] +extractType MPService {..} = concat $ map extractTypeFromMethod serviceMethods + +extractTypeFromMethod :: Method -> [Type] +extractTypeFromMethod Function {..} = [methodRetType] ++ map fldType methodArgs + +extractTypeFromType :: Type -> [Type] +extractTypeFromType x@(TNullable t) = [x] ++ extractTypeFromType t +extractTypeFromType x@(TList t) = [x] ++ extractTypeFromType t +extractTypeFromType x@(TMap s t) = [x] ++ extractTypeFromType s ++ extractTypeFromType t +extractTypeFromType x@(TTuple ts) = [x] ++ Prelude.concatMap extractTypeFromType ts +extractTypeFromType x@(TUserDef _ ts) = [x] ++ Prelude.concatMap extractTypeFromType ts +extractTypeFromType x = [x] + + genImport :: FilePath -> Decl -> LT.Text genImport packageName MPMessage {..} = [lt|import #{packageName}.#{formatClassNameT msgName}; From a8b7eabe68b0015663e0ecaf3996f04e94ac5735 Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 19:04:37 +0900 Subject: [PATCH 2/5] Added isTuple --- msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index f8367ee..dcbfc04 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -50,6 +50,10 @@ public class Tuple { }; |] +isTuple :: Type -> Bool +isTuple (TTuple _) = True +isTuple _ = False + extractType :: Decl -> [Type] extractType MPMessage {..} = map fldType msgFields extractType MPException {..} = map fldType excFields From 2a37d355a9f5e691cbfed6939cc7e9fb264cf2ea Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 19:04:51 +0900 Subject: [PATCH 3/5] Added formatClassNameLT --- msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index dcbfc04..dd0ad48 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -239,6 +239,9 @@ genVal :: Maybe Field -> T.Text genVal Nothing = "null" genVal (Just field) = fldName field +formatClassNameLT :: LT.Text -> LT.Text +formatClassNameLT = LT.pack . formatClassName . LT.unpack + formatClassNameT :: T.Text -> T.Text formatClassNameT = T.pack . formatClassName . T.unpack From 25eb12a8b14a3901a87bc4017fee319ee9e4cc27 Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 19:05:31 +0900 Subject: [PATCH 4/5] Fixed genTuple --- .../Language/MessagePack/IDL/CodeGen/Java.hs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index dd0ad48..5688315 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -26,7 +26,7 @@ generate :: Config -> Spec -> IO() generate config spec = do let typeAlias = map genAlias $ filter isMPType spec - genTuple config + mapM_ (genTuple config) $ filter isTuple $ concat $ map extractType spec mapM_ (genClient typeAlias config) spec mapM_ (genStruct typeAlias $ configPackage config) spec mapM_ (genException $ configPackage config) spec @@ -40,15 +40,28 @@ package #{configPackage} |] --} -genTuple :: Config -> IO() -genTuple Config {..} = do - LT.writeFile("Tuple.java") $ templ (configFilePath) [lt| + +genTuple :: Config -> Type -> IO() +genTuple Config{..} (TTuple typeList ) = do + let first = genType $ typeList!!0 + second = genType $ typeList!!1 + className = LT.unpack $ (LT.pack "Tuple") `mappend` formatClassNameLT first `mappend` formatClassNameLT second + dirName = joinPath $ map LT.unpack $ LT.split (== '.') $ LT.pack configPackage + fileName = dirName ++ "/" ++ className ++ ".java" + LT.writeFile fileName $ templ configFilePath [lt| package #{configPackage}; -public class Tuple { - public T a; - public U b; + +import org.msgpack.MessagePack; +import org.msgpack.annotation.Message; + +@Message +public class #{className} { + public #{first} first; + public #{second} second; }; -|] + |] + +genTuple _ _ = return () isTuple :: Type -> Bool isTuple (TTuple _) = True From f6306990160180060e3aa4cb04ec0d3e3705d0ee Mon Sep 17 00:00:00 2001 From: Kenta OONO Date: Wed, 20 Jun 2012 19:08:43 +0900 Subject: [PATCH 5/5] Changed result of genType and genWrapperType from Tuple to TupleT1T2 --- msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs index 5688315..b352306 100644 --- a/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs +++ b/msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs @@ -301,7 +301,7 @@ genType (TUserDef className params) = [lt|#{formatClassNameT className} #{associateBracket $ map genType params}|] genType (TTuple ts) = -- TODO: FIX - foldr1 (\t1 t2 -> [lt|Tuple<#{t1}, #{t2} >|]) $ map genWrapperType ts + foldr1 (\t1 t2 -> [lt|Tuple#{formatClassNameLT t1}#{formatClassNameLT t2}|]) $ map genWrapperType ts genType TObject = [lt|org.msgpack.type.Value|] genType TVoid = @@ -353,7 +353,7 @@ genWrapperType (TUserDef className params) = [lt|#{formatClassNameT className} #{associateBracket $ map genWrapperType params}|] genWrapperType (TTuple ts) = -- TODO: FIX - foldr1 (\t1 t2 -> [lt|Tuple<#{t1}, #{t2} >|]) $ map genWrapperType ts + foldr1 (\t1 t2 -> [lt|Tuple#{formatClassNameLT t1}#{formatClassNameLT t2}|]) $ map genWrapperType ts genWrapperType TObject = [lt|org.msgpack.type.Value|] genWrapperType TVoid =