From f00aa0eca757d52c433ffe2c36e4a191a8bfcdc6 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 5 Apr 2026 13:15:33 -0700 Subject: [PATCH 1/2] Simplify --- .claude/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.claude/settings.json b/.claude/settings.json index 2626b61..75f4599 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -17,7 +17,7 @@ "Bash(ls:*)", "Bash(mkdir:*)", "Bash(mkdir:*)", - "Bash(python3 -m json.tool)" + "Bash(python3 -m json.tool)", "Bash(timeout 300 ./gradlew:*)", "Bash(wc:*)", "Edit(./**)", From e2ed2978e67f2f684c9b7e2cec2216d8b15e2f69 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 5 Apr 2026 14:56:27 -0700 Subject: [PATCH 2/2] Simplify --- src/main/java/org/plumelib/lookup/Lookup.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/plumelib/lookup/Lookup.java b/src/main/java/org/plumelib/lookup/Lookup.java index a8f01b1..5bcc944 100644 --- a/src/main/java/org/plumelib/lookup/Lookup.java +++ b/src/main/java/org/plumelib/lookup/Lookup.java @@ -71,7 +71,7 @@ * --regular-expressions=boolean. Specifies that keywords are regular * expressions. If false, keywords are text matches. [default: false] *
  • -c --case-sensitive=boolean. If true, - * keywords matching is case sensistive. By default, both regular expressions and text + * keywords matching is case sensitive. By default, both regular expressions and text * keywords are case-insensitive. [default: false] *
  • -w --word-match=boolean. If true, match a * text keyword only as a separate word, not as a substring of a word. This option may @@ -160,10 +160,10 @@ private Lookup() { public static boolean regular_expressions = false; /** - * If true, keywords matching is case sensistive. By default, both regular expressions and text + * If true, keywords matching is case sensitive. By default, both regular expressions and text * keywords are case-insensitive. */ - @Option("-c Keywords are case sensistive") + @Option("-c Keywords are case sensitive") public static boolean case_sensitive = false; /** @@ -270,9 +270,7 @@ public static void main(String[] args) throws IOException { System.err.println("Error: --comment-re is not a regex: " + comment_re); System.exit(254); } - if (multiline_comment_start_re == null && multiline_comment_end_re == null) { - // Nothing to validate - } else if (multiline_comment_start_re != null && multiline_comment_end_re != null) { + if (multiline_comment_start_re != null && multiline_comment_end_re != null) { if (!RegexUtil.isRegex(multiline_comment_start_re)) { System.err.println( "Error: --multiline-comment-start-re is not a regex: " + multiline_comment_start_re); @@ -283,7 +281,7 @@ public static void main(String[] args) throws IOException { "Error: --multiline-comment-end-re is not a regex: " + multiline_comment_end_re); System.exit(254); } - } else { + } else if (multiline_comment_start_re != null || multiline_comment_end_re != null) { System.err.println( "Error: supply both or neither of --multiline-comment-start-re and" + " --multiline-comment-end-re, not just one."); @@ -365,6 +363,7 @@ public static void main(String[] args) throws IOException { try { // Process each entry looking for matches int entryCnt = 0; + boolean usePatterns = !patterns.isEmpty(); EntryReader.Entry entry = reader.getEntry(); while (entry != null) { @@ -375,7 +374,7 @@ public static void main(String[] args) throws IOException { String toSearch = (search_body || entry.shortEntry) ? entry.body : entry.getDescription(description_re); boolean found = true; - if (!patterns.isEmpty()) { + if (usePatterns) { for (Pattern pattern : patterns) { if (!pattern.matcher(toSearch).find()) { found = false; @@ -432,7 +431,6 @@ public static void main(String[] args) throws IOException { } System.out.print(e.body); } else { - int i = 0; if (print_all) { System.out.printf("%d matches found (separated by dashes below)%n", numMatchingEntries); } else { @@ -441,8 +439,8 @@ public static void main(String[] args) throws IOException { numMatchingEntries); } - for (EntryReader.Entry e : matchingEntries) { - i++; + for (int i = 0; i < numMatchingEntries; i++) { + EntryReader.Entry e = matchingEntries.get(i); if (print_all) { if (show_location) { System.out.printf( @@ -453,9 +451,10 @@ public static void main(String[] args) throws IOException { System.out.print(e.body); } else { if (show_location) { - System.out.printf(" -i=%d %s:%d: %s%n", i, e.filename, e.lineNumber, e.firstLine); + System.out.printf( + " -i=%d %s:%d: %s%n", i + 1, e.filename, e.lineNumber, e.firstLine); } else { - System.out.printf(" -i=%d %s%n", i, e.getDescription(description_re)); + System.out.printf(" -i=%d %s%n", i + 1, e.getDescription(description_re)); } } }