From d1a74b41287c21390a0003a9c00254c42ca2cc46 Mon Sep 17 00:00:00 2001 From: Franco Bulgarelli Date: Sat, 25 Nov 2017 09:55:07 -0300 Subject: [PATCH] Parsing method types --- spec/JavaSpec.hs | 4 +++- src/Language/Mulang/Parsers/Java.hs | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/spec/JavaSpec.hs b/spec/JavaSpec.hs index 924deb322..a64493f58 100644 --- a/spec/JavaSpec.hs +++ b/spec/JavaSpec.hs @@ -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 diff --git a/src/Language/Mulang/Parsers/Java.hs b/src/Language/Mulang/Parsers/Java.hs index 6e0642b81..903f99282 100644 --- a/src/Language/Mulang/Parsers/Java.hs +++ b/src/Language/Mulang/Parsers/Java.hs @@ -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 @@ -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