Skip to content
Snippets Groups Projects
Commit f56fec28 authored by Johannes Mey's avatar Johannes Mey
Browse files

add debug mode (triggered by command line flag '--debug' or not giving any...

add debug mode (triggered by command line flag '--debug' or not giving any parameters), improve output
parent 068d8f0b
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,8 @@ import java.io.IOException; ...@@ -7,9 +7,8 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ScopeAnalysis extends Frontend { public class ScopeAnalysis extends Frontend {
...@@ -26,11 +25,15 @@ public class ScopeAnalysis extends Frontend { ...@@ -26,11 +25,15 @@ public class ScopeAnalysis extends Frontend {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
if (args.length > 1 || args.length < 0) { List<String> arguments = new ArrayList<>(Arrays.asList(args));
System.out.println("usage: ScopeAnalysis <directory with java files>");
boolean debug = arguments.isEmpty() || arguments.remove("--debug");
if (arguments.size() > 1) {
System.out.println("usage: ScopeAnalysis [--debug] <directory with java files>");
System.exit(-1); System.exit(-1);
} }
String path = args.length == 1 ? args[0] : "../testprograms/simpleScope"; String path = arguments.isEmpty() ? "../testprograms/simpleScope" : arguments.get(arguments.size() - 1);
try { try {
List<String> files = Files.walk(Paths.get(path)) List<String> files = Files.walk(Paths.get(path))
...@@ -47,6 +50,7 @@ public class ScopeAnalysis extends Frontend { ...@@ -47,6 +50,7 @@ public class ScopeAnalysis extends Frontend {
ScopeTree scopeTree = program.scopeTree(); ScopeTree scopeTree = program.scopeTree();
if (debug) {
scopeTree.printAST(); scopeTree.printAST();
System.out.println("\nExtendJ found the following problems:"); System.out.println("\nExtendJ found the following problems:");
...@@ -55,15 +59,20 @@ public class ScopeAnalysis extends Frontend { ...@@ -55,15 +59,20 @@ public class ScopeAnalysis extends Frontend {
System.out.println(problem); System.out.println(problem);
} }
} }
System.out.println("\n"); System.out.println();
}
long startAnalysisTime = System.nanoTime(); long startAnalysisTime = System.nanoTime();
Set<VariableShadowFinding> findings = scopeTree.variableShadowings(); Set<VariableShadowFinding> findings = scopeTree.variableShadowings();
if (debug) {
System.out.println("\nScope4J found the following problems:");
for (VariableShadowFinding finding : findings) { for (VariableShadowFinding finding : findings) {
System.out.println(finding); System.out.println(finding);
} }
System.out.println();
}
// measure the time until here // measure the time until here
long endTime = System.nanoTime(); long endTime = System.nanoTime();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment