From 074967337ab7b350184e81f1d1747136f1eb39d4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 27 Sep 2019 18:48:48 -0400 Subject: [PATCH] Define a custom ToTagBy instance for ClassDeclaration. --- semantic-java/src/Language/Java/Tags.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/semantic-java/src/Language/Java/Tags.hs b/semantic-java/src/Language/Java/Tags.hs index 07dd1ed75..11ac201ca 100644 --- a/semantic-java/src/Language/Java/Tags.hs +++ b/semantic-java/src/Language/Java/Tags.hs @@ -47,6 +47,7 @@ type family ToTagsInstance t :: Strategy where ToTagsInstance (_ :+: _) = 'Custom ToTagsInstance Java.Program = 'Custom ToTagsInstance Java.MethodDeclaration = 'Custom + ToTagsInstance Java.ClassDeclaration = 'Custom ToTagsInstance _ = 'Generic @@ -82,6 +83,17 @@ instance ToTagsBy 'Custom Java.MethodDeclaration where traverse_ tags extraChildren traverse_ tags body +instance ToTagsBy 'Custom Java.ClassDeclaration where + tags' t@Java.ClassDeclaration + { ann = Loc Range { start } span + , name = Java.Identifier { bytes = name } + , body = Java.ClassBody { ann = Loc Range { start = end } _ } + } = do + src <- ask @Source + let sliced = slice src (Range start end) + Tags.yield (Tag name Function span (firstLine sliced) Nothing) + gtags t + firstLine :: Source -> Text firstLine = Text.takeWhile (/= '\n') . toText . Source.take 180