From 61c1fdd8dd0e2b65acc55774380b5954b35abbbf Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Thu, 11 Apr 2024 16:02:13 -0300 Subject: [PATCH 01/11] FEAT: Adding the new MethodInvocationCount.java Metric File --- .../ck/metric/MethodInvocationCount.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java new file mode 100644 index 00000000..705993fb --- /dev/null +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java @@ -0,0 +1,25 @@ +package com.github.mauricioaniche.ck.metric; + +import com.github.mauricioaniche.ck.CKClassResult; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.MethodInvocation; + +import java.util.HashMap; +import java.util.Map; + +public class MethodInvocationCount extends ASTVisitor implements CKASTVisitor, ClassLevelMetric { + + private Map methodInvocationCounts = new HashMap<>(); + + @Override + public boolean visit(MethodInvocation node) { + String methodName = node.getName().getIdentifier(); + methodInvocationCounts.merge(methodName, 1, Integer::sum); + return super.visit(node); + } + + @Override + public void setResult(CKClassResult result) { + result.addMethodInvocation(methodName); + } +} From 8d041759774bb93387b1f66b2849b0df6364240e Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Thu, 11 Apr 2024 16:21:32 -0300 Subject: [PATCH 02/11] REFACTOR: Adding the Private Hashmap and Methods in the CKClassResult to handle the new MethodInvocationCount Metric --- .../com/github/mauricioaniche/ck/CKClassResult.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java b/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java index 9d8b2714..e3069d66 100644 --- a/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java +++ b/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java @@ -66,6 +66,8 @@ public class CKClassResult { private float tightClassCohesion; private float looseClassCohesion; + private Map methodInvocations = new HashMap<>(); + public CKClassResult(String file, String className, String type, int modifiers) { this.file = file; this.className = className; @@ -539,4 +541,12 @@ public int hashCode() { return Objects.hash(file, className, type); } + public void addMethodInvocation(String methodName) { + this.methodInvocations.merge(methodName, 1, Integer::sum); + } + + public Map getMethodInvocations() { + return methodInvocations; + } + } From 4082a288a73b6824e81204e4ae8ecf38e1a70bc9 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Fri, 12 Apr 2024 13:50:28 -0300 Subject: [PATCH 03/11] FIX: Fixing the MethodInvocationCounter Metric --- .../mauricioaniche/ck/CKClassResult.java | 10 +++---- .../mauricioaniche/ck/ResultWriter.java | 2 ++ .../ck/metric/MethodInvocationCount.java | 25 ---------------- .../ck/metric/MethodInvocationCounter.java | 25 ++++++++++++++++ .../mauricioaniche/ck/util/MethodCounter.java | 30 +++++++++++++++++++ 5 files changed, 62 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java create mode 100644 src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java create mode 100644 src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java diff --git a/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java b/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java index e3069d66..024c6b75 100644 --- a/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java +++ b/src/main/java/com/github/mauricioaniche/ck/CKClassResult.java @@ -66,7 +66,7 @@ public class CKClassResult { private float tightClassCohesion; private float looseClassCohesion; - private Map methodInvocations = new HashMap<>(); + private String methodInvocations; public CKClassResult(String file, String className, String type, int modifiers) { this.file = file; @@ -541,12 +541,12 @@ public int hashCode() { return Objects.hash(file, className, type); } - public void addMethodInvocation(String methodName) { - this.methodInvocations.merge(methodName, 1, Integer::sum); + public void setMethodInvocation(String methodInvocations) { + this.methodInvocations = methodInvocations; } - public Map getMethodInvocations() { - return methodInvocations; + public String getMethodInvocations() { + return this.methodInvocations; } } diff --git a/src/main/java/com/github/mauricioaniche/ck/ResultWriter.java b/src/main/java/com/github/mauricioaniche/ck/ResultWriter.java index e294c530..a9bca398 100644 --- a/src/main/java/com/github/mauricioaniche/ck/ResultWriter.java +++ b/src/main/java/com/github/mauricioaniche/ck/ResultWriter.java @@ -39,6 +39,7 @@ public class ResultWriter { "abstractMethodsQty", "finalMethodsQty", "synchronizedMethodsQty", + "methodInvocations", /* Field Counting */ "totalFieldsQty", @@ -178,6 +179,7 @@ public void printResult(CKClassResult result) throws IOException { result.getNumberOfAbstractMethods(), result.getNumberOfFinalMethods(), result.getNumberOfSynchronizedMethods(), + result.getMethodInvocations(), /* Field Counting */ result.getNumberOfFields(), diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java deleted file mode 100644 index 705993fb..00000000 --- a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCount.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.mauricioaniche.ck.metric; - -import com.github.mauricioaniche.ck.CKClassResult; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.MethodInvocation; - -import java.util.HashMap; -import java.util.Map; - -public class MethodInvocationCount extends ASTVisitor implements CKASTVisitor, ClassLevelMetric { - - private Map methodInvocationCounts = new HashMap<>(); - - @Override - public boolean visit(MethodInvocation node) { - String methodName = node.getName().getIdentifier(); - methodInvocationCounts.merge(methodName, 1, Integer::sum); - return super.visit(node); - } - - @Override - public void setResult(CKClassResult result) { - result.addMethodInvocation(methodName); - } -} diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java new file mode 100644 index 00000000..2e4cc88b --- /dev/null +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java @@ -0,0 +1,25 @@ +package com.github.mauricioaniche.ck.metric; + +import com.github.mauricioaniche.ck.CKClassResult; +import com.github.mauricioaniche.ck.util.MethodCounter; +import org.eclipse.jdt.core.dom.MethodInvocation; + +public class MethodInvocationCounter implements CKASTVisitor, ClassLevelMetric { + private String methodList; + + @Override + public void visit(MethodInvocation node) { + if (methodList == null) { + this.methodList = ""; + } + String methodName = node.toString(); + this.methodList += methodName.substring(0, methodName.indexOf("(")) + ";"; + System.currentTimeMillis(); + } + + @Override + public void setResult(CKClassResult result) { + String methodList = MethodCounter.formatResult(MethodCounter.sort(MethodCounter.count(this.methodList))); + result.setMethodInvocation(methodList); + } +} diff --git a/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java b/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java new file mode 100644 index 00000000..0ef9e6db --- /dev/null +++ b/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java @@ -0,0 +1,30 @@ +package com.github.mauricioaniche.ck.util; + +import java.util.*; +import java.util.stream.Collectors; + +public class MethodCounter { + public static Map count(String methodList) { + Map methodInvocation = new HashMap<>(); + + String[] methodNames = methodList.split(";"); + for (String name : methodNames) { + methodInvocation.put(name, methodInvocation.getOrDefault(name, 0) + 1); + } + + return methodInvocation; + } + + public static Map sort(Map methodInvocation) { + return methodInvocation.entrySet().stream() + .sorted((Map.Entry.comparingByValue().reversed())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, HashMap::new)); + } + + public static String formatResult(Map methodInvocation) { + return methodInvocation.entrySet().stream() + .map(entry -> entry.getKey() + ": " + entry.getValue()) + .collect(Collectors.joining(", ")); + } + +} From 0b897a9e2bacea6ffb361c547b658bfc1acf0b07 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Mon, 15 Apr 2024 16:19:49 -0300 Subject: [PATCH 04/11] REFACTOR: Updating the methodName Format --- .../ck/metric/MethodInvocationCounter.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java index 2e4cc88b..22fa017a 100644 --- a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java @@ -12,9 +12,14 @@ public void visit(MethodInvocation node) { if (methodList == null) { this.methodList = ""; } + String methodName = node.toString(); - this.methodList += methodName.substring(0, methodName.indexOf("(")) + ";"; - System.currentTimeMillis(); + + if (methodName.contains("(")) { + methodName = methodName.substring(0, methodName.indexOf("(")); + } + + this.methodList += methodName + ";"; } @Override From 9fb521ec29b27647a8bd3ac7d70147a345bcef10 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Tue, 16 Apr 2024 16:03:36 -0300 Subject: [PATCH 05/11] FEAT: Adding the MethodInvocationCounter Class Metric --- .../ck/metric/MethodInvocationCounter.java | 36 +++++++++++-------- .../mauricioaniche/ck/util/MethodCounter.java | 30 ---------------- 2 files changed, 22 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java index 22fa017a..6b7d808b 100644 --- a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java @@ -2,29 +2,37 @@ import com.github.mauricioaniche.ck.CKClassResult; import com.github.mauricioaniche.ck.util.MethodCounter; -import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.*; + +import java.util.*; public class MethodInvocationCounter implements CKASTVisitor, ClassLevelMetric { - private String methodList; + private Map methodInvocations = new HashMap<>(); + private String currentMethod = null; @Override - public void visit(MethodInvocation node) { - if (methodList == null) { - this.methodList = ""; - } - - String methodName = node.toString(); + public void visit(MethodDeclaration node) { + // Set the current method context + this.currentMethod = node.getName().getIdentifier(); + methodInvocations.putIfAbsent(currentMethod, new MethodCounter().new MethodInformation(currentMethod)); + } - if (methodName.contains("(")) { - methodName = methodName.substring(0, methodName.indexOf("(")); + @Override + public void visit(MethodInvocation node) { + if (currentMethod != null) { + // Retrieve or create the MethodInformation for the current method + MethodCounter.MethodInformation info = methodInvocations.get(currentMethod); + String methodName = node.getName().getIdentifier(); + Map counts = info.getMethodInvocations(); + counts.put(methodName, counts.getOrDefault(methodName, 0) + 1); } - - this.methodList += methodName + ";"; } @Override public void setResult(CKClassResult result) { - String methodList = MethodCounter.formatResult(MethodCounter.sort(MethodCounter.count(this.methodList))); - result.setMethodInvocation(methodList); + // Process all collected method invocation information into the desired format + List infos = new ArrayList<>(methodInvocations.values()); + String formattedResult = MethodCounter.formatResult(infos); + result.setMethodInvocation(formattedResult); } } diff --git a/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java b/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java deleted file mode 100644 index 0ef9e6db..00000000 --- a/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.mauricioaniche.ck.util; - -import java.util.*; -import java.util.stream.Collectors; - -public class MethodCounter { - public static Map count(String methodList) { - Map methodInvocation = new HashMap<>(); - - String[] methodNames = methodList.split(";"); - for (String name : methodNames) { - methodInvocation.put(name, methodInvocation.getOrDefault(name, 0) + 1); - } - - return methodInvocation; - } - - public static Map sort(Map methodInvocation) { - return methodInvocation.entrySet().stream() - .sorted((Map.Entry.comparingByValue().reversed())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, HashMap::new)); - } - - public static String formatResult(Map methodInvocation) { - return methodInvocation.entrySet().stream() - .map(entry -> entry.getKey() + ": " + entry.getValue()) - .collect(Collectors.joining(", ")); - } - -} From b791b4aa55f187781d169da35f0a019dc9514617 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Tue, 16 Apr 2024 16:05:21 -0300 Subject: [PATCH 06/11] FEAT: Adding the MethodCounter Util Class for the MethodInvocationCounter Metric --- .../mauricioaniche/ck/util/MethodCounter.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java diff --git a/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java b/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java new file mode 100644 index 00000000..d1af583e --- /dev/null +++ b/src/main/java/com/github/mauricioaniche/ck/util/MethodCounter.java @@ -0,0 +1,77 @@ +package com.github.mauricioaniche.ck.util; + +import java.util.*; +import java.util.stream.Collectors; + +public class MethodCounter { + public class MethodInformation { + private String parentName; + private Map methodInvocations = new HashMap<>(); + + public MethodInformation(String parentName) { + this.parentName = parentName; + } + + public String getParentName() { + return parentName; + } + + public Map getMethodInvocations() { + return methodInvocations; + } + + @Override + public String toString() { + return "MethodInformation{" + + "parentName='" + parentName + '\'' + + ", methodInvocation=" + methodInvocations + + '}'; + } + + public String toFormattedString() { + return parentName + "[ " + formatMethods(sortMethods(methodInvocations)) + " ] "; + } + + private Map sortMethods(Map methodInvocation) { + return methodInvocation.entrySet().stream() + .sorted((Map.Entry.comparingByValue().reversed())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + } + + private String formatMethods(Map methodInvocation) { + return methodInvocation.entrySet().stream() + .map(entry -> entry.getKey() + "()" + ":" + entry.getValue()) + .collect(Collectors.joining(" ")); + } + + } + + public static String formatResult(List methodInformations) { + return methodInformations.stream().map(MethodInformation::toFormattedString).collect(Collectors.joining()); + } + public static List count(String methodList) { + List methodInformationList = new ArrayList<>(); + + String[] methodNames = methodList.split(";"); + for (String name : methodNames) { + String[] parts = name.split("/"); + String methodName = parts[0]; + String parentName = parts[1]; + + MethodInformation methodInformation = new MethodCounter().new MethodInformation(parentName); + if (methodInformationList.contains(methodInformation)) { + methodInformation = methodInformationList.get(methodInformationList.indexOf(methodInformation)); + } else { + methodInformationList.add(methodInformation); + } + + if (methodInformation.getMethodInvocations().containsKey(methodName)) { + methodInformation.getMethodInvocations().put(methodName, methodInformation.getMethodInvocations().get(methodName) + 1); + } else { + methodInformation.getMethodInvocations().put(methodName, 1); + } + } + + return methodInformationList; + } +} From e615a7c99717b4d7bb4c3524e99326af6b140437 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Wed, 24 Apr 2024 11:19:12 -0300 Subject: [PATCH 07/11] REFACTOR: Adding the verbose boolean execution argument to the CK and Runner Java Files --- src/main/java/com/github/mauricioaniche/ck/CK.java | 6 +++--- src/main/java/com/github/mauricioaniche/ck/Runner.java | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/mauricioaniche/ck/CK.java b/src/main/java/com/github/mauricioaniche/ck/CK.java index 803e07cc..6bde74e4 100644 --- a/src/main/java/com/github/mauricioaniche/ck/CK.java +++ b/src/main/java/com/github/mauricioaniche/ck/CK.java @@ -36,9 +36,9 @@ public CK(Callable> classLevelMetrics, Callable finder.allClassLevelMetrics(); + this.classLevelMetrics = () -> finder.allClassLevelMetrics(verbose); this.methodLevelMetrics = () -> finder.allMethodLevelMetrics(variablesAndFields); this.useJars = useJars; @@ -49,7 +49,7 @@ public CK(boolean useJars, int maxAtOnce, boolean variablesAndFields) { } public CK() { - this(false, 0, true); + this(false, 0, true, false); } public void calculate(String path, CKNotifier notifier) { diff --git a/src/main/java/com/github/mauricioaniche/ck/Runner.java b/src/main/java/com/github/mauricioaniche/ck/Runner.java index e0cab409..4b63a2ca 100644 --- a/src/main/java/com/github/mauricioaniche/ck/Runner.java +++ b/src/main/java/com/github/mauricioaniche/ck/Runner.java @@ -31,12 +31,16 @@ public static void main(String[] args) throws IOException { boolean variablesAndFields = true; if(args.length >= 4) variablesAndFields = Boolean.parseBoolean(args[3]); - + // path where the output csv files will be exported String outputDir = ""; if(args.length >= 5) outputDir = args[4]; + boolean isVerbose = false; + if(args.length >= 6) + isVerbose = Boolean.parseBoolean(args[5]); + // load possible additional ignored directories //noinspection ManualArrayToCollectionCopy for (int i = 5; i < args.length; i++) { @@ -47,7 +51,7 @@ public static void main(String[] args) throws IOException { Map results = new HashMap<>(); - new CK(useJars, maxAtOnce, variablesAndFields).calculate(path, new CKNotifier() { + new CK(useJars, maxAtOnce, variablesAndFields, isVerbose).calculate(path, new CKNotifier() { @Override public void notify(CKClassResult result) { From 8ce9a3291529f98f7c8b9cf16782e58a8a328093 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Wed, 24 Apr 2024 11:23:15 -0300 Subject: [PATCH 08/11] REFACTOR: Modifying the allClassLevelMetrics method to process metrics according to the verbose execution modifier --- .../mauricioaniche/ck/util/MetricsFinder.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java b/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java index 7734e2f1..29d8fdd9 100644 --- a/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java +++ b/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java @@ -2,11 +2,12 @@ import com.github.mauricioaniche.ck.metric.ClassLevelMetric; import com.github.mauricioaniche.ck.metric.MethodLevelMetric; -import com.github.mauricioaniche.ck.metric.RunAfter; import com.github.mauricioaniche.ck.metric.VariableOrFieldMetric; import org.reflections.Reflections; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.stream.Collectors; public class MetricsFinder { @@ -39,7 +40,7 @@ public List allMethodLevelMetrics(boolean variablesAndFields) } } - public List allClassLevelMetrics() { + public List allClassLevelMetrics(boolean verbose) { if(classLevelClasses == null) loadClassLevelClasses(); @@ -47,7 +48,17 @@ public List allClassLevelMetrics() { try { ArrayList metrics = new ArrayList<>(); for (Class aClass : classLevelClasses) { - metrics.add(aClass.getDeclaredConstructor().newInstance()); + boolean isVerbose = Arrays.stream(aClass.getFields()) + .anyMatch(f -> f.getName().equals("IS_VERBOSE")) ? aClass.getField("IS_VERBOSE").getBoolean(null) : false; + + if (verbose) { + metrics.add(aClass.getDeclaredConstructor().newInstance()); + } + else { + if (!isVerbose) { + metrics.add(aClass.getDeclaredConstructor().newInstance()); + } + } } return metrics; From 937804d2d9e3609f8cbb278d72ee14733e8166e6 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Wed, 24 Apr 2024 11:25:04 -0300 Subject: [PATCH 09/11] REFACTOR: Adding the IS_VERBOSE boolean variable to recognize the output of this class metric as verbose/large --- .../github/mauricioaniche/ck/metric/MethodInvocationCounter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java index 6b7d808b..04dcaa4b 100644 --- a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java @@ -9,6 +9,7 @@ public class MethodInvocationCounter implements CKASTVisitor, ClassLevelMetric { private Map methodInvocations = new HashMap<>(); private String currentMethod = null; + public static final boolean IS_VERBOSE = true; @Override public void visit(MethodDeclaration node) { From efaf9246f9c785a553beb0e6a93b872e1c4cac88 Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Wed, 24 Apr 2024 11:38:21 -0300 Subject: [PATCH 10/11] IMPROVE: Removing the IS_VERBOSE constant from the MethodInvocationCounter Metric and defining a standard isVerbose method to the ClassLevelMetric Interface File --- .../github/mauricioaniche/ck/metric/ClassLevelMetric.java | 4 +++- .../mauricioaniche/ck/metric/MethodInvocationCounter.java | 6 +++++- .../com/github/mauricioaniche/ck/util/MetricsFinder.java | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/ClassLevelMetric.java b/src/main/java/com/github/mauricioaniche/ck/metric/ClassLevelMetric.java index 66d15a2e..34e5bdef 100644 --- a/src/main/java/com/github/mauricioaniche/ck/metric/ClassLevelMetric.java +++ b/src/main/java/com/github/mauricioaniche/ck/metric/ClassLevelMetric.java @@ -1,9 +1,11 @@ package com.github.mauricioaniche.ck.metric; import com.github.mauricioaniche.ck.CKClassResult; -import org.eclipse.jdt.core.dom.CompilationUnit; public interface ClassLevelMetric { + default boolean isVerbose() { + return false; + } void setResult(CKClassResult result); default void setClassName(String className) { diff --git a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java index 04dcaa4b..3324c13c 100644 --- a/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java +++ b/src/main/java/com/github/mauricioaniche/ck/metric/MethodInvocationCounter.java @@ -9,7 +9,6 @@ public class MethodInvocationCounter implements CKASTVisitor, ClassLevelMetric { private Map methodInvocations = new HashMap<>(); private String currentMethod = null; - public static final boolean IS_VERBOSE = true; @Override public void visit(MethodDeclaration node) { @@ -36,4 +35,9 @@ public void setResult(CKClassResult result) { String formattedResult = MethodCounter.formatResult(infos); result.setMethodInvocation(formattedResult); } + + @Override + public boolean isVerbose() { + return true; + } } diff --git a/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java b/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java index 29d8fdd9..fb99920a 100644 --- a/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java +++ b/src/main/java/com/github/mauricioaniche/ck/util/MetricsFinder.java @@ -48,8 +48,7 @@ public List allClassLevelMetrics(boolean verbose) { try { ArrayList metrics = new ArrayList<>(); for (Class aClass : classLevelClasses) { - boolean isVerbose = Arrays.stream(aClass.getFields()) - .anyMatch(f -> f.getName().equals("IS_VERBOSE")) ? aClass.getField("IS_VERBOSE").getBoolean(null) : false; + boolean isVerbose = aClass.getDeclaredConstructor().newInstance().isVerbose(); if (verbose) { metrics.add(aClass.getDeclaredConstructor().newInstance()); From 8a0d5c62e0786ac1bfad68c47e3a417f85eb608a Mon Sep 17 00:00:00 2001 From: Breno Farias da Silva Date: Wed, 24 Apr 2024 12:02:54 -0300 Subject: [PATCH 11/11] DOCS: Updating the Documentation to mention the new execution argument (VERBOSE) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 837d14ee..880e2522 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ To use the _latest version_ (which you should), clone the project and generate a Then, just run: ``` -java -jar ck-x.x.x-SNAPSHOT-jar-with-dependencies.jar [ignored directories...] +java -jar ck-x.x.x-SNAPSHOT-jar-with-dependencies.jar [ignored directories...] ``` `Project dir` refers to the directory where CK can find all the source code to be parsed. @@ -150,10 +150,10 @@ in the directory and use them to better resolve types. `Max files per partition` of the batch to process. Let us decide that for you and start with 0; if problems happen (i.e., out of memory) you think of tuning it. `Variables and field metrics` indicates to CK whether you want metrics at variable- and field-levels too. They are highly fine-grained and produce a lot of output; -you should skip it if you only need metrics at class or method level. Finally, `output dir` refer to the +you should skip it if you only need metrics at class or method level. Aditionally, `output dir` refer to the directory where CK will export the csv file with metrics from the analyzed project. Optionally, you can specify any number ignored directories, separated by spaces (for example, `build/`). -By default, `.git` and all other hidden folders are ignored. +By default, `.git` and all other hidden folders are ignored. Finally, the `verbose flag` tells CK if it must process metrics tagged as large outputs. If you are not interested in the detailed output of the metrics, you can set it to false. The tool will generate three csv files: class, method, and variable levels.