diff --git a/src/Data/Functor/Listable.hs b/src/Data/Functor/Listable.hs index 2ff37f8ab..2f64e93f2 100644 --- a/src/Data/Functor/Listable.hs +++ b/src/Data/Functor/Listable.hs @@ -18,6 +18,7 @@ module Data.Functor.Listable , liftCons2 , liftCons3 , liftCons4 +, liftCons5 , ListableF(..) ) where @@ -74,6 +75,13 @@ liftCons4 :: [Tier a] -> [Tier b] -> [Tier c] -> [Tier d] -> (a -> b -> c -> d - liftCons4 tiers1 tiers2 tiers3 tiers4 f = mapT (uncurry4 f) (productWith (\ x (y, z, w) -> (x, y, z, w)) tiers1 (liftCons3 tiers2 tiers3 tiers4 (,,)) ) `addWeight` 1 where uncurry4 f (a, b, c, d) = f a b c d +-- | Lifts a quinary constructor to a list of tiers, given lists of tiers for its arguments. +-- +-- Commonly used in the definition of 'Listable1' and 'Listable2' instances. +liftCons5 :: [Tier a] -> [Tier b] -> [Tier c] -> [Tier d] -> [Tier e] -> (a -> b -> c -> d -> e -> f) -> [Tier f] +liftCons5 tiers1 tiers2 tiers3 tiers4 tiers5 f = mapT (uncurry5 f) (productWith (\ x (y, z, w, u) -> (x, y, z, w, u)) tiers1 (liftCons4 tiers2 tiers3 tiers4 tiers5 (,,,)) ) `addWeight` 1 + where uncurry5 f (a, b, c, d, e) = f a b c d e + -- | Convenient wrapper for 'Listable1' type constructors and 'Listable' types, where a 'Listable' instance would necessarily be orphaned. newtype ListableF f a = ListableF { unListableF :: f a } deriving Show diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 58761ca4b..be800102c 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -251,7 +251,8 @@ toTermName source term = case unwrap term of S.Select clauses -> termNameFromChildren term clauses S.Array ty _ -> maybe (termNameFromSource term) termNameFromSource ty S.Class identifier _ _ -> toTermName' identifier - S.Method identifier _ args _ -> toTermName' identifier <> paramsToArgNames args + S.Method identifier (Just receiver) _ args _ -> termNameFromSource receiver <> "." <> toTermName' identifier <> paramsToArgNames args + S.Method identifier Nothing _ args _ -> toTermName' identifier <> paramsToArgNames args S.Comment a -> toS a S.Commented _ _ -> termNameFromChildren term (toList $ unwrap term) S.Module identifier _ -> toTermName' identifier diff --git a/src/Interpreter.hs b/src/Interpreter.hs index f48f7fa2a..8d4f5ccf0 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -78,8 +78,9 @@ algorithmWithTerms construct t1 t2 = maybe (recursively t1 t2) (fmap annotate) $ S.Class <$> recursively identifierA identifierB <*> maybeRecursively paramsA paramsB <*> bySimilarity expressionsA expressionsB - (S.Method identifierA tyA paramsA expressionsA, S.Method identifierB tyB paramsB expressionsB) -> Just $ + (S.Method identifierA receiverA tyA paramsA expressionsA, S.Method identifierB receiverB tyB paramsB expressionsB) -> Just $ S.Method <$> recursively identifierA identifierB + <*> maybeRecursively receiverA receiverB <*> maybeRecursively tyA tyB <*> bySimilarity paramsA paramsB <*> bySimilarity expressionsA expressionsB diff --git a/src/Language/Go.hs b/src/Language/Go.hs index 609b7518f..462917a98 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -65,12 +65,14 @@ termAssignment source category children = case (category, children) of (Send, [channel, expr]) -> Just $ S.Send channel expr (Operator, _) -> Just $ S.Operator children (FunctionTy, _) -> Just $ S.Ty children - (IncrementStatement, _) -> Just $ S.Leaf $ toText source - (DecrementStatement, _) -> Just $ S.Leaf $ toText source - (QualifiedIdentifier, _) -> Just $ S.Leaf $ toText source - (Method, [params, name, fun]) -> Just (S.Method name Nothing (toList (unwrap params)) (toList (unwrap fun))) - (Method, [params, name, outParams, fun]) -> Just (S.Method name Nothing (toList (unwrap params) <> toList (unwrap outParams)) (toList (unwrap fun))) - (Method, [params, name, outParams, ty, fun]) -> Just (S.Method name (Just ty) (toList (unwrap params) <> toList (unwrap outParams)) (toList (unwrap fun))) + (IncrementStatement, _) -> Just $ S.Leaf (toText source) + (DecrementStatement, _) -> Just $ S.Leaf (toText source) + (QualifiedIdentifier, _) -> Just $ S.Leaf (toText source) + (Method, [params, name, fun]) -> Just (S.Method name Nothing Nothing (toList (unwrap params)) (toList (unwrap fun))) + (Method, [params, name, outParams, fun]) + -> Just (S.Method name (Just outParams) Nothing (toList (unwrap params)) (toList (unwrap fun))) + (Method, [params, name, outParams, ty, fun]) + -> Just (S.Method name (Just outParams) (Just ty) (toList (unwrap params)) (toList (unwrap fun))) _ -> Nothing categoryForGoName :: Text -> Category diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index 0f253ee43..9eef03bd0 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -44,8 +44,8 @@ termAssignment _ category children , Finally <- Info.category (extract finally) -> Just $ S.Try [body] [catch] Nothing (Just finally) (ArrayLiteral, _) -> Just $ S.Array Nothing children - (Method, [ identifier, params, exprs ]) -> Just $ S.Method identifier Nothing (toList (unwrap params)) (toList (unwrap exprs)) - (Method, [ identifier, exprs ]) -> Just $ S.Method identifier Nothing [] (toList (unwrap exprs)) + (Method, [ identifier, params, exprs ]) -> Just $ S.Method identifier Nothing Nothing (toList (unwrap params)) (toList (unwrap exprs)) + (Method, [ identifier, exprs ]) -> Just $ S.Method identifier Nothing Nothing [] (toList (unwrap exprs)) (Class, [ identifier, superclass, definitions ]) -> Just $ S.Class identifier (Just superclass) (toList (unwrap definitions)) (Class, [ identifier, definitions ]) -> Just $ S.Class identifier Nothing (toList (unwrap definitions)) (Import, [ statements, identifier ] ) -> Just $ S.Import identifier (toList (unwrap statements)) diff --git a/src/Language/Ruby.hs b/src/Language/Ruby.hs index 437f46345..14f148813 100644 --- a/src/Language/Ruby.hs +++ b/src/Language/Ruby.hs @@ -68,15 +68,15 @@ termAssignment _ category children (Method, expr : methodName : rest) | params : body <- rest , Params <- Info.category (extract params) - -> Just $ S.Method (withRecord (setCategory (extract expr) MemberAccess) (S.MemberAccess expr methodName)) Nothing (toList (unwrap params)) body + -> Just $ S.Method methodName (Just expr) Nothing (toList (unwrap params)) body | Identifier <- Info.category (extract methodName) - -> Just $ S.Method (withRecord (setCategory (extract expr) MemberAccess) (S.MemberAccess expr methodName)) Nothing [] rest + -> Just $ S.Method methodName (Just expr) Nothing [] rest (Method, identifier : rest) | params : body <- rest , Params <- Info.category (extract params) - -> Just $ S.Method identifier Nothing (toList (unwrap params)) body + -> Just $ S.Method identifier Nothing Nothing (toList (unwrap params)) body | otherwise - -> Just $ S.Method identifier Nothing [] rest + -> Just $ S.Method identifier Nothing Nothing [] rest (Module, constant : body ) -> Just $ S.Module constant body (Modifier Rescue, [lhs, rhs] ) -> Just $ S.Rescue [lhs] [rhs] (Rescue, exceptions : exceptionVar : rest) diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index 22bf8830e..9e5b6a9f4 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -129,7 +129,7 @@ syntaxToTermField syntax = case syntax of S.Try body catchExpression elseExpression finallyExpression -> [ "body" .= body ] <> [ "catchExpression" .= catchExpression ] <> [ "elseExpression" .= elseExpression ] <> [ "finallyExpression" .= finallyExpression ] S.Array ty c -> [ "type" .= ty ] <> childrenFields c S.Class identifier superclass definitions -> [ "identifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ] - S.Method identifier ty parameters definitions -> [ "identifier" .= identifier ] <> [ "type" .= ty ] <> [ "parameters" .= parameters ] <> [ "definitions" .= definitions ] + S.Method identifier receiver ty parameters definitions -> [ "identifier" .= identifier ] <> [ "receiver" .= receiver ] <> [ "type" .= ty ] <> [ "parameters" .= parameters ] <> [ "definitions" .= definitions ] S.If expression clauses -> [ "expression" .= expression ] <> childrenFields clauses S.Module identifier definitions-> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ] S.Import identifier statements -> [ "identifier" .= identifier ] <> [ "statements" .= statements ] diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index c0f41b816..f5bb7ba58 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -152,8 +152,8 @@ termToDiffInfo blob term = case unwrap term of toTermName :: forall leaf fields. DefaultFields fields => Source Char -> SyntaxTerm leaf fields -> Text toTermName source term = case unwrap term of S.Function identifier _ _ _ -> toTermName' identifier - S.Method identifier _ _ _ -> toTermName' identifier - S.MemberAccess base property -> toTermName' base <> "." <> toTermName' property + S.Method identifier Nothing _ _ _ -> toTermName' identifier + S.Method identifier (Just receiver) _ _ _ -> toTermName' receiver <> "." <> toTermName' identifier _ -> termNameFromSource term where toTermName' = toTermName source diff --git a/src/Syntax.hs b/src/Syntax.hs index 1a85263e9..385d4994f 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -71,8 +71,8 @@ data Syntax a f | Array (Maybe f) [f] -- | A class with an identifier, superclass, and a list of definitions. | Class f (Maybe f) [f] - -- | A method definition with an identifier, optional return type, params, and a list of expressions. - | Method f (Maybe f) [f] [f] + -- | A method definition with an identifier, optional receiver, optional return type, params, and a list of expressions. + | Method f (Maybe f) (Maybe f) [f] [f] -- | An if statement with an expression and maybe more expression clauses. | If f [f] -- | A module with an identifier, and a list of syntaxes. @@ -143,7 +143,7 @@ instance Listable2 Syntax where \/ liftCons4 (liftTiers recur) (liftTiers recur) (liftTiers recur) (liftTiers recur) Try \/ liftCons2 (liftTiers recur) (liftTiers recur) Syntax.Array \/ liftCons3 recur (liftTiers recur) (liftTiers recur) Class - \/ liftCons4 recur (liftTiers recur) (liftTiers recur) (liftTiers recur) Method + \/ liftCons5 recur (liftTiers recur) (liftTiers recur) (liftTiers recur) (liftTiers recur) Method \/ liftCons2 recur (liftTiers recur) If \/ liftCons2 recur (liftTiers recur) Module \/ liftCons2 recur (liftTiers recur) Import diff --git a/test/corpus/diff-summaries/go/method-declarations.json b/test/corpus/diff-summaries/go/method-declarations.json index b076405d2..7018a2bf6 100644 --- a/test/corpus/diff-summaries/go/method-declarations.json +++ b/test/corpus/diff-summaries/go/method-declarations.json @@ -53,7 +53,7 @@ "+" ], "gitDir": "test/corpus/repos/go", - "shas": "d6222a7346773adfd0929112bedb22129a3519ea..e6c36e250ec3b19c41f32961ccebf3d87daedda7" + "shas": "177fb35939c02b4bc6067142eab57a6cc2237513..2f023a586a3c306c01e1fbf646c7bffc5a6428b3" } ,{ "testCaseDescription": "go-method-declarations-insert-test", @@ -73,7 +73,7 @@ ] } }, - "summary": "Added the 'Equals(…, …)' method" + "summary": "Added the '(other Person).Equals(…)' method" } ] }, @@ -95,40 +95,13 @@ "+func (self Person) Equals(other Person) bool {}" ], "gitDir": "test/corpus/repos/go", - "shas": "e6c36e250ec3b19c41f32961ccebf3d87daedda7..8997e3526ed2c41b2dcdda92e804efb3877995b7" + "shas": "2f023a586a3c306c01e1fbf646c7bffc5a6428b3..d79d8d6400fbf0ee98ec1c1de105b35653bc6abf" } ,{ "testCaseDescription": "go-method-declarations-replacement-test", "expectedResult": { "changes": { "method-declarations.go": [ - { - "span": { - "replace": [ - { - "start": [ - 5, - 12 - ], - "end": [ - 5, - 18 - ] - }, - { - "start": [ - 5, - 12 - ], - "end": [ - 5, - 15 - ] - } - ] - }, - "summary": "Replaced the 'Person' identifier with the 'Num' identifier in the 'Equals(…, …)' method" - }, { "span": { "replace": [ @@ -154,7 +127,34 @@ } ] }, - "summary": "Replaced the 'Person' identifier with the 'Num' identifier in the 'Equals(…, …)' method" + "summary": "Replaced the 'Person' identifier with the 'Num' identifier in the '(other Num).Equals(…)' method" + }, + { + "span": { + "replace": [ + { + "start": [ + 5, + 12 + ], + "end": [ + 5, + 18 + ] + }, + { + "start": [ + 5, + 12 + ], + "end": [ + 5, + 15 + ] + } + ] + }, + "summary": "Replaced the 'Person' identifier with the 'Num' identifier in the '(other Num).Equals(…)' method" } ] }, @@ -176,40 +176,13 @@ "+func (self Num) Equals(other Num) bool {}" ], "gitDir": "test/corpus/repos/go", - "shas": "8997e3526ed2c41b2dcdda92e804efb3877995b7..f08fde8bdfc53bd37c4432795460d589a75095aa" + "shas": "d79d8d6400fbf0ee98ec1c1de105b35653bc6abf..4984840b9c1f873e4f0283f9aa56578524bc318a" } ,{ "testCaseDescription": "go-method-declarations-delete-replacement-test", "expectedResult": { "changes": { "method-declarations.go": [ - { - "span": { - "replace": [ - { - "start": [ - 5, - 12 - ], - "end": [ - 5, - 15 - ] - }, - { - "start": [ - 5, - 12 - ], - "end": [ - 5, - 18 - ] - } - ] - }, - "summary": "Replaced the 'Num' identifier with the 'Person' identifier in the 'Equals(…, …)' method" - }, { "span": { "replace": [ @@ -235,7 +208,34 @@ } ] }, - "summary": "Replaced the 'Num' identifier with the 'Person' identifier in the 'Equals(…, …)' method" + "summary": "Replaced the 'Num' identifier with the 'Person' identifier in the '(other Person).Equals(…)' method" + }, + { + "span": { + "replace": [ + { + "start": [ + 5, + 12 + ], + "end": [ + 5, + 15 + ] + }, + { + "start": [ + 5, + 12 + ], + "end": [ + 5, + 18 + ] + } + ] + }, + "summary": "Replaced the 'Num' identifier with the 'Person' identifier in the '(other Person).Equals(…)' method" } ] }, @@ -257,7 +257,7 @@ "+func (self Person) Equals(other Person) bool {}" ], "gitDir": "test/corpus/repos/go", - "shas": "f08fde8bdfc53bd37c4432795460d589a75095aa..6894b07b35002c287e007ee22d368fc3ae5de4f3" + "shas": "4984840b9c1f873e4f0283f9aa56578524bc318a..5d97f8471206dc97ee31629ea3a5513e44182603" } ,{ "testCaseDescription": "go-method-declarations-delete-insert-test", @@ -277,7 +277,7 @@ ] } }, - "summary": "Deleted the 'Equals(…, …)' method" + "summary": "Deleted the '(other Person).Equals(…)' method" } ] }, @@ -299,7 +299,7 @@ "+" ], "gitDir": "test/corpus/repos/go", - "shas": "6894b07b35002c287e007ee22d368fc3ae5de4f3..36a54e70abf58b31b21f318fe98685a08ef1949f" + "shas": "5d97f8471206dc97ee31629ea3a5513e44182603..e3c6f620532caea3d241a47bbaa17701dba91928" } ,{ "testCaseDescription": "go-method-declarations-teardown-test", @@ -356,5 +356,5 @@ "-" ], "gitDir": "test/corpus/repos/go", - "shas": "36a54e70abf58b31b21f318fe98685a08ef1949f..957e7a284d3bbaebd707764ceac202343581ccdb" + "shas": "e3c6f620532caea3d241a47bbaa17701dba91928..852d29d2b9a695875dd0e15454330bbf7c5e49ff" }] diff --git a/test/corpus/generated/new_ruby.json b/test/corpus/generated/new_ruby.json deleted file mode 100644 index 052f0e8d1..000000000 --- a/test/corpus/generated/new_ruby.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "language": "ruby", - "fileExt": ".rb", - "repoUrl": "https://github.com/diff-fixtures/ruby.git", - "syntaxes": [ - { - "syntax": "singleton-method-declaration", - "insert": "def self.foo\nend", - "replacement": "def self.bar(a)\n baz\nend" - } - ] - } -] diff --git a/test/corpus/repos/go b/test/corpus/repos/go index 177fb3593..852d29d2b 160000 --- a/test/corpus/repos/go +++ b/test/corpus/repos/go @@ -1 +1 @@ -Subproject commit 177fb35939c02b4bc6067142eab57a6cc2237513 +Subproject commit 852d29d2b9a695875dd0e15454330bbf7c5e49ff