Skip to content

Commit

Permalink
Modernize a for loop
Browse files Browse the repository at this point in the history
Replace a general `for (;;)` loop with something in a more functional
style.  The restructured code also makes it more obvious that exactly
one `List` instance is *always* put into the `Exclusions` key of the
`res` `Map`.
  • Loading branch information
liblit committed May 28, 2024
1 parent a001555 commit f68c80f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Base class that represents a set of files to analyze.
Expand Down Expand Up @@ -365,19 +367,15 @@ public String toJson() {
loaders.put(loader.getName().toString(), arr);
}
res.put("Loaders", loaders);
ArrayList<String> arr2 = new ArrayList<>();
if (getExclusions() == null) {
res.put("Exclusions", arr2);
} else {
String[] exclusions = getExclusions().toString().split("\\|");
for (int i = 0; i < exclusions.length; i++) {
String word = exclusions[i];
word = word.replace("(", "");
word = word.replace(")", "");
arr2.add(word);
}
res.put("Exclusions", arr2);
}
final var exclusions = getExclusions();
res.put(
"Exclusions",
exclusions == null
? List.of()
: Pattern.compile("\\|")
.splitAsStream(exclusions.toString())
.map(exclusion -> exclusion.replace("(", "").replace(")", ""))
.collect(Collectors.toList()));
Gson gson = new Gson();
return gson.toJson(res);
}
Expand Down

0 comments on commit f68c80f

Please sign in to comment.