Skip to content

Commit

Permalink
Parsing method types
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Nov 25, 2017
1 parent 982a0f0 commit d1a74b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion spec/JavaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ spec = do
it "parses Simple Interface With Messages" $ do
run "public interface Foo { void foo(); }" `shouldBe` Interface "Foo" [] (TypeSignature "foo" [] "void")

it "parses Simple Interface With Non-Void Messages" $ do
run "public interface Foo { int foo(); }" `shouldBe` Interface "Foo" [] (TypeSignature "foo" [] "int")

it "parses Simple Interface With Messages With Params" $ do
run "public interface Foo { void foo(String x, int y); }" `shouldBe` Interface "Foo" [] (TypeSignature "foo" ["String", "int"] "void")


it "parses Interface with superinterfaces" $ do
run "public interface Foo extends Bar, Baz {}" `shouldBe` Interface "Foo" ["Bar", "Baz"] MuNull

Expand Down
22 changes: 13 additions & 9 deletions src/Language/Mulang/Parsers/Java.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ muDecl (MemberDecl memberDecl) = muMemberDecl memberDecl
muDecl (InitDecl _ _) = return Other

muMemberDecl :: MemberDecl -> [Expression]
muMemberDecl (FieldDecl _ _type varDecls) = map (variableToAttribute.muVarDecl) varDecls
muMemberDecl (MethodDecl _ _ _ name params _ (MethodBody Nothing)) = return $ TypeSignature (i name) (map muFormalParamType params) "void"
muMemberDecl (MethodDecl (elem Static -> True) _ _ (Ident "main") [_] _ body) = return $ EntryPoint "main" (muMethodBody body)
muMemberDecl (MethodDecl _ _ _ (Ident "equals") params _ body) = return $ EqualMethod [SimpleEquation (map muFormalParam params) (muMethodBody body)]
muMemberDecl (MethodDecl _ _ _ (Ident "hashCode") params _ body) = return $ HashMethod [SimpleEquation (map muFormalParam params) (muMethodBody body)]
muMemberDecl (MethodDecl _ _ _ name params _ body) = return $ SimpleMethod (i name) (map muFormalParam params) (muMethodBody body)
muMemberDecl (ConstructorDecl _ _ _ _params _ _constructorBody) = return $ Other
muMemberDecl (MemberClassDecl decl) = return $ muClassTypeDecl decl
muMemberDecl (MemberInterfaceDecl decl) = return $ muInterfaceTypeDecl decl
muMemberDecl (FieldDecl _ _type varDecls) = map (variableToAttribute.muVarDecl) varDecls
muMemberDecl (MethodDecl _ _ typ name params _ (MethodBody Nothing)) = return $ TypeSignature (i name) (map muFormalParamType params) (muMaybeType typ)
muMemberDecl (MethodDecl (elem Static -> True) _ Nothing (Ident "main") [_] _ body)
= return $ EntryPoint "main" (muMethodBody body)
muMemberDecl (MethodDecl _ _ _ (Ident "equals") params _ body) = return $ EqualMethod [SimpleEquation (map muFormalParam params) (muMethodBody body)]
muMemberDecl (MethodDecl _ _ _ (Ident "hashCode") params _ body) = return $ HashMethod [SimpleEquation (map muFormalParam params) (muMethodBody body)]
muMemberDecl (MethodDecl _ _ _ name params _ body) = return $ SimpleMethod (i name) (map muFormalParam params) (muMethodBody body)
muMemberDecl (ConstructorDecl _ _ _ _params _ _constructorBody) = return $ Other
muMemberDecl (MemberClassDecl decl) = return $ muClassTypeDecl decl
muMemberDecl (MemberInterfaceDecl decl) = return $ muInterfaceTypeDecl decl

muEnumConstant (EnumConstant name _ _) = i name

Expand All @@ -66,6 +67,9 @@ muBlockStmt (BlockStmt stmt) = [muStmt stmt]
muBlockStmt (LocalClass decl) = [muClassTypeDecl decl]
muBlockStmt (LocalVars _ _type vars) = map muVarDecl vars

muMaybeType Nothing = "void"
muMaybeType (Just typ) = muType typ

muType (PrimType t) = muPrimType t
muType (RefType t) = muRefType t

Expand Down

0 comments on commit d1a74b4

Please sign in to comment.