From 0f6872dda7bdcffdfedd884f794a366481dff0a0 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 20 Mar 2024 11:14:16 -0400 Subject: [PATCH] Fix bug with determining whether a module is "local." The old code didn't consider the full path of the module, which is what is contained in `localModules`. But, it still doesn't do what I think it should do, which makes me believe that the generated CAst is incorrect. --- .../ibm/wala/cast/python/parser/PythonModuleParser.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonModuleParser.java b/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonModuleParser.java index 3c35707df..a9ea2b019 100644 --- a/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonModuleParser.java +++ b/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonModuleParser.java @@ -83,14 +83,14 @@ public CAstNode visitImportFrom(ImportFrom importFrom) throws Exception { String moduleName = s.get(); LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + "."); - if (!localModules.contains(moduleName + ".py")) { + if (!isLocalModule(moduleName)) { LOGGER.finer("Module: " + moduleName + ".py" + " isn't local."); moduleName = s.get() + "/__init__"; } else LOGGER.finer("Module: " + moduleName + ".py" + " is local."); LOGGER.finer("Module name from " + importFrom + " is: " + moduleName + "."); - if (localModules.contains(moduleName + ".py")) { + if (isLocalModule(moduleName)) { LOGGER.finer("Module: " + moduleName + ".py" + " is local."); String yuck = moduleName; @@ -174,4 +174,8 @@ public static void main(String[] args) throws Exception { protected Reader getReader() throws IOException { return new InputStreamReader(fileName.getInputStream()); } + + private boolean isLocalModule(String moduleName) { + return localModules.stream().anyMatch(lm -> lm.endsWith(moduleName + ".py")); + } }