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,