From ddce255c8387c2b4472d6dec8014bdde648b32be Mon Sep 17 00:00:00 2001 From: Dzhovidon Vakhidov Date: Tue, 2 Apr 2024 22:18:48 +0300 Subject: [PATCH] fixes --- .../java/org/jpeek/calculus/java/Ccm.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jpeek/calculus/java/Ccm.java b/src/main/java/org/jpeek/calculus/java/Ccm.java index 8f111c33..daf54394 100644 --- a/src/main/java/org/jpeek/calculus/java/Ccm.java +++ b/src/main/java/org/jpeek/calculus/java/Ccm.java @@ -141,23 +141,26 @@ private static Node addNccTag(final Document doc, final XML clazz, private static Integer calculateComponents(final XML clazz, final Map params) { final Map> connections = new HashMap<>(); final Map parents = new HashMap<>(); + final List allowed = new ArrayList<>(0); for (final XML method : clazz.nodes("methods/method")) { - if (!params.containsKey("include-static-methods") - && method.xpath("@static").get(0).equals("true")) { - continue; - } final String name = method.xpath("@name").get(0); - if (!params.containsKey("include-ctors") && name.equals("")) { + if (isConstructorExcluded(params, method) || isStaticMethodExcluded(params, method)) { continue; } + allowed.add(method); parents.put(name, name); + } + for (final XML method : allowed) { + final String name = method.xpath("@name").get(0); final List ops = method.nodes("ops/op"); for (final XML operation : ops) { final String code = operation.xpath("@code").get(0); if (code.equals("call")) { final String classpath = operation.nodes("name").get(0).node().getTextContent(); final List splits = Arrays.asList(classpath.split("\\.")); - parents.put(name, splits.get(splits.size() - 1)); + if (parents.keySet().contains(splits.get(splits.size() - 1))) { + parents.put(name, splits.get(splits.size() - 1)); + } } else { final String var = operation.node().getTextContent(); if (connections.containsKey(var)) { @@ -173,6 +176,29 @@ private static Integer calculateComponents(final XML clazz, final Map params, + final XML method) { + return !params.containsKey("include-static-methods") && method.xpath("@static").get(0) + .equals("true"); + } + + /** + * Checks if a constructor should be excluded based on parameters. + * @param params Parameters for filtering. + * @param method The method XML node. + * @return True if the constructor should be excluded, false otherwise. + */ + private static boolean isConstructorExcluded(final Map params, + final XML method) { + return !params.containsKey("include-ctors") && method.xpath("@ctor").get(0).equals("true"); + } + /** * Utility class implementing the Union-Find algorithm. * The UnionFind class provides methods to perform the Union-Find algorithm,