JAL-4026 update the viewport’s wrapped width after calculating it
[jalview.git] / utils / MessageBundleChecker.java
index 5b48226..b1927e1 100644 (file)
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
@@ -130,15 +131,6 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
   {
     System.out.println(
             "Scanning " + srcPath + " for calls to MessageManager\n");
-    System.out.println("Please note this is not a perfect check:");
-    System.out.println(
-            "- message keys constructed dynamically can't be checked");
-    System.out
-            .println("- message keys passed as variables can't be checked");
-    System.out.println(
-            "- references in commented out code are not filtered out");
-    System.out.println(
-            "Verify 'missing' keys manually by a source code search\n");
 
     sourcePath = srcPath;
     loadMessages();
@@ -168,13 +160,14 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
    */
   private void reportResults()
   {
-    System.out.println("\nScanned " + javaCount + " source files");
     System.out.println(
-            "Messages.properties has " + messages.size() + " keys");
+            "\nMessages.properties has " + messages.size() + " keys");
+    System.out.println("Scanned " + javaCount + " source files\n");
+
     if (!invalidKeys.isEmpty())
     {
       System.out.println("Found " + invalidKeys.size()
-              + " possibly invalid unmatched keys in source code"
+              + " possibly invalid unmatched key(s) in source code"
               + (invalidKeys.size() > 1 ? "s" : ""));
     }
 
@@ -193,7 +186,7 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
     if (dynamicCount < messageKeys.size())
     {
       System.out.println((messageKeys.size() - dynamicCount)
-              + " keys not found, possibly unused, or used indirectly (check code manually!)");
+              + " key(s) not found, possibly unused, or used indirectly (check code manually!)");
       for (String key : messageKeys)
       {
         if (!isDynamic(key))
@@ -203,7 +196,7 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
       }
     }
     System.out
-            .println("(Run i18nAnt.xml to compare other message bundles)");
+            .println("\nRun i18nAnt.xml to compare other message bundles");
   }
 
   /**
@@ -295,7 +288,8 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
    * @param lineNo
    * @param line
    */
-  private void inspectSourceLines(String path, int lineNo, String line)
+  private void inspectSourceLines(String path, int lineNo,
+          final String line)
   {
     String lineNos = String.format("%d-%d", lineNo,
             lineNo + bufferSize - 1);
@@ -341,9 +335,9 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
         String key = messageKey.substring(1, messageKey.length() - 1);
         if (!dynamicKeys.contains(key))
         {
-          System.out.println(String.format(
-                  "Dynamic key \"" + key + "\" at %s line %s %s",
-                  path.substring(sourcePath.length()), lineNos, line));
+//          System.out.println(String.format(
+//                  "Dynamic key \"" + key + "\" at %s line %s %s",
+//                  path.substring(sourcePath.length()), lineNos, line));
           dynamicKeys.add(key);
         }
         continue;
@@ -358,8 +352,8 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
 
       if (!(STRING_PATTERN.matcher(messageKey).matches()))
       {
-        System.out.println(String.format("Dynamic key at %s line %s %s",
-                path.substring(sourcePath.length()), lineNos, line));
+//        System.out.println(String.format("Dynamic key at %s line %s %s",
+//                path.substring(sourcePath.length()), lineNos, line));
         continue;
       }
 
@@ -381,6 +375,22 @@ public class MessageBundleChecker implements BufferedLineReader.LineCleaner
       }
       messageKeys.remove(messageKey);
     }
+
+    /*
+     * and a brute force scan for _any_ as yet unseen message key, to catch the
+     * cases where it is in a variable or a condition
+     */
+    if (line.contains("\""))
+    {
+      Iterator<String> it = messageKeys.iterator();
+      while (it.hasNext())
+      {
+        if (line.contains(it.next()))
+        {
+          it.remove(); // remove as 'seen'
+        }
+      }
+    }
   }
 
   /**