From d79f5c2f1efb50ed35fc9a79ecdeaf0ea2158a17 Mon Sep 17 00:00:00 2001 From: Brian Huffman Date: Tue, 17 Nov 2020 18:30:39 -0800 Subject: [PATCH] Make `findMethod` report *all* method names when method is not found. Fixes #911. --- src/SAWScript/Utils.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SAWScript/Utils.hs b/src/SAWScript/Utils.hs index 8b70284a16..3e8ee78be6 100644 --- a/src/SAWScript/Utils.hs +++ b/src/SAWScript/Utils.hs @@ -121,13 +121,13 @@ lookupClass cb site nm = do -- | Returns method with given name in this class or one of its subclasses. -- Throws an ExecException if method could not be found or is ambiguous. findMethod :: JSS.Codebase -> Pos -> String -> JSS.Class -> IO (JSS.Class, JSS.Method) -findMethod cb site nm initClass = impl initClass +findMethod cb site nm initClass = impl [] initClass where javaClassName = JSS.slashesToDots (JSS.unClassName (JSS.className initClass)) methodType m = (JSS.methodParameterTypes m, JSS.methodReturnType m) baseName m = JSS.methodName m typedName m = JSS.methodName m ++ unparseMethodDescriptor (methodType m) methodMatches m = nm `elem` [baseName m, typedName m] - impl cl = + impl names cl = let candidates = filter (not . JSS.methodIsAbstract) (JSS.classMethods cl) in case filter methodMatches candidates of [] -> do @@ -136,11 +136,12 @@ findMethod cb site nm initClass = impl initClass let msg = ftext $ "Could not find method " ++ nm ++ " in class " ++ javaClassName ++ ".\n" ++ "Available methods: " - ++ unlines [ show (baseName m) | m <- candidates ] + ++ unlines names res = "Please check that the class and method are correct." in throwIOExecException site msg res Just superName -> - impl =<< lookupClass cb site superName + do super <- lookupClass cb site superName + impl (names ++ map baseName candidates) super [method] -> return (cl,method) l -> let msg = "The method " ++ show nm ++ " in class " ++ javaClassName ++ " is ambiguous. " ++ "Methods can be disambiguated by appending a type descriptor: " ++