Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions Language/Java/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,22 @@ explConstrInv =
noLoc . endSemi $
try
( do
tas <- neoptList refTypeArgs
rts <- neoptList refTypeArgs
tok KW_This
ThisInvoke tas <$> noLoc args
ThisInvoke rts <$> noLoc args
)
<|> try
( do
tas <- neoptList refTypeArgs
rts <- neoptList refTypeArgs
tok KW_Super
SuperInvoke tas <$> noLoc args
SuperInvoke rts <$> noLoc args
)
<|> ( do
pri <- noLoc primary
period
tas <- neoptList refTypeArgs
rts <- neoptList refTypeArgs
tok KW_Super
PrimarySuperInvoke pri tas <$> noLoc args
PrimarySuperInvoke pri rts <$> noLoc args
)

-- TODO: This should be parsed like class bodies, and post-checked.
Expand Down Expand Up @@ -1367,9 +1367,9 @@ methodInvocationNPS = do
return (SuperMethodCall (startLoc, loc) rts i as, loc)
)
<|> ( do
(mn, i) <- qualifiedMethodName
(mn, rts, i) <- qualifiedMethodName
(as, loc) <- args
return (MethodCall (startLoc, loc) mn i as, loc)
return (MethodCall (startLoc, loc) mn rts i as, loc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich habe das Gefühl, wir sollten die Benennungen mal etwas konsistenter gestalten. Hier heißen die Argumente ja mn und rts, in Pretty heißen sie mName und tArgs und im Transformer zum Beispiel refTypes.

Kannst du für diese Änderung ein Ticket anlegen? Die Idee wäre dann, dass man in Zukunft jedes Mal, wenn man Code anfasst die Benennungen verbessert. Hast du eine Präferenz bezüglich der Benennung?

)
<|> ( do
n <- noLoc name
Expand All @@ -1382,34 +1382,34 @@ methodInvocationNPS = do
return (constr (startLoc, loc) n rts i as, loc)
)

qualifiedMethodName :: P (Maybe Name, Ident)
qualifiedMethodName :: P (Maybe Name, [RefType], Ident)
qualifiedMethodName = do
startLoc <- getLocation
mapFst
( \case
(mn, rts, i) <- go startLoc []
let mn' = case mn of
([], _) -> Nothing
(is, endLoc) -> Just (Name (startLoc, endLoc) (NonEmpty.fromList (reverse is)))
)
<$> go startLoc []
return (mn', rts, i)
where
go :: Location -> [Ident] -> P (([Ident], Location), Ident)
go :: Location -> [Ident] -> P (([Ident], Location), [RefType], Ident)
go endLoc nids = do
(i, loc) <- ident
try
( do
period
go loc (i : nids)
( do
rts <- try (period >> refTypeArgs)
i' <- noLoc ident
return ((i : nids, loc), NonEmpty.toList rts, i')
)
<|> return ((nids, endLoc), i)
<|> try (period >> go loc (i : nids))
<|> return ((nids, endLoc), [], i)

methodInvocationSuffix :: P (Exp Parsed -> MethodInvocation Parsed, Location)
methodInvocationSuffix = do
startLoc <- getLocation
period
_ <- neoptList refTypeArgs
rts <- neoptList refTypeArgs
i <- noLoc ident
(as, loc) <- args
return (\p -> PrimaryMethodCall (startLoc, loc) p [] i as, loc)
return (\p -> PrimaryMethodCall (startLoc, loc) p rts i as, loc)

methodInvocationExp :: P (Exp Parsed)
methodInvocationExp =
Expand Down
3 changes: 2 additions & 1 deletion Language/Java/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,14 @@ instance (PrettyExtension p) => Pretty (FieldAccess p) where
prettyPrec p name <> text "." <> prettyPrec p ident

instance (PrettyExtension p) => Pretty (MethodInvocation p) where
prettyPrec p (MethodCall _ mName methodId args) =
prettyPrec p (MethodCall _ mName tArgs methodId args) =
case mName of
Nothing -> prettyPrec p methodId <> ppArgs p args
Just name ->
hcat
[ prettyPrec p name,
char '.',
ppTypeParams p tArgs,
prettyPrec p methodId,
ppArgs p args
]
Expand Down
10 changes: 5 additions & 5 deletions Language/Java/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,8 @@ instance (EqualityExtension p) => Equality (LambdaExpression p) where

-- | A method invocation expression is used to invoke a class or instance method.
data MethodInvocation p
= -- | Invoking a specific named method.
MethodCall SourceSpan (Maybe (XNameClassification p)) Ident [Argument p]
= -- | Invoking a specific named method, giving arguments for any generic type parameters.
MethodCall SourceSpan (Maybe (XNameClassification p)) [RefType] Ident [Argument p]
| -- | Invoking a method of a class computed from a primary expression, giving arguments for any generic type parameters.
PrimaryMethodCall SourceSpan (Exp p) [RefType] Ident [Argument p]
| -- | Invoking a method of the super class, giving arguments for any generic type parameters.
Expand All @@ -1295,8 +1295,8 @@ deriving instance (ReadExtension p) => Read (MethodInvocation p)
deriving instance (DataExtension p) => Data (MethodInvocation p)

instance (EqualityExtension p) => Equality (MethodInvocation p) where
eq opt (MethodCall s1 mn1 i1 as1) (MethodCall s2 mn2 i2 as2) =
eq opt s1 s2 && eq opt mn1 mn2 && eq opt i1 i2 && eq opt as1 as2
eq opt (MethodCall s1 mn1 rts1 i1 as1) (MethodCall s2 mn2 rts2 i2 as2) =
eq opt s1 s2 && eq opt mn1 mn2 && eq opt rts1 rts2 && eq opt i1 i2 && eq opt as1 as2
eq opt (PrimaryMethodCall s1 e1 rts1 i1 as1) (PrimaryMethodCall s2 e2 rts2 i2 as2) =
eq opt s1 s2 && eq opt e1 e2 && eq opt rts1 rts2 && eq opt i1 i2 && eq opt as1 as2
eq opt (SuperMethodCall s1 rts1 i1 as1) (SuperMethodCall s2 rts2 i2 as2) =
Expand All @@ -1308,7 +1308,7 @@ instance (EqualityExtension p) => Equality (MethodInvocation p) where
eq _ _ _ = False

instance Located (MethodInvocation p) where
sourceSpan (MethodCall s _ _ _) = s
sourceSpan (MethodCall s _ _ _ _) = s
sourceSpan (PrimaryMethodCall s _ _ _ _) = s
sourceSpan (SuperMethodCall s _ _ _) = s
sourceSpan (ClassMethodCall s _ _ _ _) = s
Expand Down
4 changes: 2 additions & 2 deletions Language/Java/Transformer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class AnalyzedTransformer a where
transformToAnalyzed :: IdentCollection -> a Parsed -> a Analyzed

instance AnalyzedTransformer MethodInvocation where
transformToAnalyzed scope (MethodCall srcspan Nothing idnt args) = MethodCall srcspan Nothing idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (MethodCall srcspan (Just name) idnt args) = MethodCall srcspan (Just (classifyName name scope)) idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (MethodCall srcspan Nothing refTypes idnt args) = MethodCall srcspan Nothing refTypes idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (MethodCall srcspan (Just name) refTypes idnt args) = MethodCall srcspan (Just (classifyName name scope)) refTypes idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (PrimaryMethodCall srcspan expr refTypes idnt args) = PrimaryMethodCall srcspan (transformToAnalyzed scope expr) refTypes idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (SuperMethodCall srcspan refTypes idnt args) = SuperMethodCall srcspan refTypes idnt (map (transformToAnalyzed scope) args)
transformToAnalyzed scope (ClassMethodCall srcspan name refTypes idnt args) = ClassMethodCall srcspan name refTypes idnt (map (transformToAnalyzed scope) args)
Expand Down