diff --git a/scope4j/src/main/java/org/extendj/ScopeAnalysis.java b/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
index 53b570a74295d8f4bed171ad1c7b3db3821ec9ef..9ac98896cb78232b3c06eaacd43ca5058caf8dbd 100644
--- a/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
+++ b/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
@@ -7,9 +7,8 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Collection;
import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
public class ScopeAnalysis extends Frontend {
@@ -26,11 +25,15 @@ public class ScopeAnalysis extends Frontend {
*/
public static void main(String[] args) {
- if (args.length > 1 || args.length < 0) {
- System.out.println("usage: ScopeAnalysis <directory with java files>");
+ List<String> arguments = new ArrayList<>(Arrays.asList(args));
+
+ boolean debug = arguments.isEmpty() || arguments.remove("--debug");
+
+ if (arguments.size() > 1) {
+ System.out.println("usage: ScopeAnalysis [--debug] <directory with java files>");
System.exit(-1);
}
- String path = args.length == 1 ? args[0] : "../testprograms/simpleScope";
+ String path = arguments.isEmpty() ? "../testprograms/simpleScope" : arguments.get(arguments.size() - 1);
try {
List<String> files = Files.walk(Paths.get(path))
@@ -47,22 +50,28 @@ public class ScopeAnalysis extends Frontend {
ScopeTree scopeTree = program.scopeTree();
- scopeTree.printAST();
+ if (debug) {
+ scopeTree.printAST();
- System.out.println("\nExtendJ found the following problems:");
- for (CompilationUnit unit : program.getCompilationUnitList()) {
- for (Problem problem: unit.problems()) {
- System.out.println(problem);
+ System.out.println("\nExtendJ found the following problems:");
+ for (CompilationUnit unit : program.getCompilationUnitList()) {
+ for (Problem problem : unit.problems()) {
+ System.out.println(problem);
+ }
}
+ System.out.println();
}
- System.out.println("\n");
long startAnalysisTime = System.nanoTime();
Set<VariableShadowFinding> findings = scopeTree.variableShadowings();
- for (VariableShadowFinding finding : findings) {
- System.out.println(finding);
+ if (debug) {
+ System.out.println("\nScope4J found the following problems:");
+ for (VariableShadowFinding finding : findings) {
+ System.out.println(finding);
+ }
+ System.out.println();
}
// measure the time until here