Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default values for java clients #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion msgpack-idl/Language/MessagePack/IDL/CodeGen/Java.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ genInit Field {..} = case fldDefault of

genDecl :: Field -> LT.Text
genDecl Field {..} =
[lt| public #{genType fldType} #{fldName};
[lt| public #{genType fldType} #{fldName} = #{genValue fldType};
|]

genException :: FilePath -> Decl -> IO()
Expand Down Expand Up @@ -267,6 +267,26 @@ genType TObject =
[lt|org.msgpack.type.Value|]
genType TVoid =
[lt|void|]

genValue :: Type -> LT.Text
genValue (TInt _ bits) = [lt|0|]
genValue (TFloat _) = [lt|0.0|]
genValue TBool = [lt|false|]
genValue TRaw = [lt|""|]
genValue (TList typ) =
[lt|new ArrayList<#{genWrapperType typ} >()|]
genValue (TMap typ1 typ2) =
[lt|new HashMap<#{genType typ1}, #{genType typ2} >()|]
genValue (TUserDef className params) =
[lt|new #{formatClassNameT className} #{associateBracket $ map genType params}()|]
genValue (TTuple ts) =
foldr1 (\t1 t2 -> [lt|new Tuple<#{t1}, #{t2} >()|]) $ map genWrapperType ts
genValue TObject =
[lt|org.msgpack.type.NilValue.getInstance()|]
genValue (TNullable _) =
[lt|null|]
genValue TString = [lt|""|]


genTypeWithContext :: Spec -> Type -> LT.Text
genTypeWithContext spec t = case t of
Expand Down