JAL-1424 streamlined message checker, corrected applet lookup keys
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 7 Jul 2020 07:50:54 +0000 (08:50 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 7 Jul 2020 07:50:54 +0000 (08:50 +0100)
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AppletJmol.java
src/mc_view/AppletPDBViewer.java
utils/MessageBundleChecker.java

index e1bfbde..80db11d 100644 (file)
@@ -1056,7 +1056,7 @@ public class APopupMenu extends java.awt.PopupMenu
     BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
     BLOSUM62Colour.addItemListener(this);
     PIDColour.setLabel(
-            MessageManager.getString("label.colourScheme_%_identity"));
+            MessageManager.getString("label.colourScheme_%identity"));
     PIDColour.setName(JalviewColourScheme.PID.toString());
     PIDColour.addItemListener(this);
     zappoColour
@@ -1073,19 +1073,19 @@ public class APopupMenu extends java.awt.PopupMenu
             .setName(JalviewColourScheme.Hydrophobic.toString());
     hydrophobicityColour.addItemListener(this);
     helixColour.setLabel(MessageManager
-            .getString("label.colourScheme_helix_propensity"));
+            .getString("label.colourScheme_helixpropensity"));
     helixColour.setName(JalviewColourScheme.Helix.toString());
     helixColour.addItemListener(this);
     strandColour.setLabel(MessageManager
-            .getString("label.colourScheme_strand_propensity"));
+            .getString("label.colourScheme_strandpropensity"));
     strandColour.setName(JalviewColourScheme.Strand.toString());
     strandColour.addItemListener(this);
     turnColour.setLabel(
-            MessageManager.getString("label.colourScheme_turn_propensity"));
+            MessageManager.getString("label.colourScheme_turnpropensity"));
     turnColour.setName(JalviewColourScheme.Turn.toString());
     turnColour.addItemListener(this);
     buriedColour.setLabel(
-            MessageManager.getString("label.colourScheme_buried_index"));
+            MessageManager.getString("label.colourScheme_buriedindex"));
     buriedColour.setName(JalviewColourScheme.Buried.toString());
     buriedColour.addItemListener(this);
     nucleotideColour.setLabel(
index 0fd0945..b6f8929 100644 (file)
@@ -3522,16 +3522,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             MessageManager.getString("label.colourScheme_hydrophobic"));
     hydrophobicityColour.addActionListener(this);
     helixColour.setLabel(MessageManager
-            .getString("label.colourScheme_helix_propensity"));
+            .getString("label.colourScheme_helixpropensity"));
     helixColour.addActionListener(this);
     strandColour.setLabel(MessageManager
-            .getString("label.colourScheme_strand_propensity"));
+            .getString("label.colourScheme_strandpropensity"));
     strandColour.addActionListener(this);
     turnColour.setLabel(
-            MessageManager.getString("label.colourScheme_turn_propensity"));
+            MessageManager.getString("label.colourScheme_turnpropensity"));
     turnColour.addActionListener(this);
     buriedColour.setLabel(
-            MessageManager.getString("label.colourScheme_buried_index"));
+            MessageManager.getString("label.colourScheme_buriedindex"));
     buriedColour.addActionListener(this);
     purinePyrimidineColour.setLabel(MessageManager
             .getString("label.colourScheme_purine/pyrimidine"));
@@ -3540,19 +3540,19 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // .getString("label.rna_interaction"));
     // RNAInteractionColour.addActionListener(this);
     RNAHelixColour.setLabel(
-            MessageManager.getString("label.colourScheme_rna_helices"));
+            MessageManager.getString("label.colourScheme_rnahelices"));
     RNAHelixColour.addActionListener(this);
     userDefinedColour
             .setLabel(MessageManager.getString("action.user_defined"));
     userDefinedColour.addActionListener(this);
     PIDColour.setLabel(
-            MessageManager.getString("label.colourScheme_%_identity"));
+            MessageManager.getString("label.colourScheme_%identity"));
     PIDColour.addActionListener(this);
     BLOSUM62Colour.setLabel(
             MessageManager.getString("label.colourScheme_blosum62"));
     BLOSUM62Colour.addActionListener(this);
     tcoffeeColour.setLabel(
-            MessageManager.getString("label.colourScheme_t-coffee_scores"));
+            MessageManager.getString("label.colourScheme_t-coffeescores"));
     // it will be enabled only if a score file is provided
     tcoffeeColour.setEnabled(false);
     tcoffeeColour.addActionListener(this);
index 6665ec8..380ec25 100644 (file)
@@ -104,16 +104,16 @@ public class AppletJmol extends EmbmenuFrame implements
           MessageManager.getString("label.colourScheme_hydrophobic"));
 
   MenuItem helix = new MenuItem(
-          MessageManager.getString("label.colourScheme_helix_propensity"));
+          MessageManager.getString("label.colourScheme_helixpropensity"));
 
   MenuItem strand = new MenuItem(
-          MessageManager.getString("label.colourScheme_strand_propensity"));
+          MessageManager.getString("label.colourScheme_strandpropensity"));
 
   MenuItem turn = new MenuItem(
-          MessageManager.getString("label.colourScheme_turn_propensity"));
+          MessageManager.getString("label.colourScheme_turnpropensity"));
 
   MenuItem buried = new MenuItem(
-          MessageManager.getString("label.colourScheme_buried_index"));
+          MessageManager.getString("label.colourScheme_buriedindex"));
 
   MenuItem purinepyrimidine = new MenuItem(
           MessageManager.getString("label.colourScheme_purine/pyrimidine"));
index fa30021..3ae81d2 100644 (file)
@@ -201,16 +201,16 @@ public class AppletPDBViewer extends EmbmenuFrame
     taylor.setLabel(MessageManager.getString("label.colourScheme_taylor"));
     taylor.addActionListener(this);
     helix.setLabel(MessageManager
-            .getString("label.colourScheme_helix_propensity"));
+            .getString("label.colourScheme_helixpropensity"));
     helix.addActionListener(this);
     strand.setLabel(MessageManager
-            .getString("label.colourScheme_strand_propensity"));
+            .getString("label.colourScheme_strandpropensity"));
     strand.addActionListener(this);
     turn.setLabel(
-            MessageManager.getString("label.colourScheme_turn_propensity"));
+            MessageManager.getString("label.colourScheme_turnpropensity"));
     turn.addActionListener(this);
     buried.setLabel(
-            MessageManager.getString("label.colourScheme_buried_index"));
+            MessageManager.getString("label.colourScheme_buriedindex"));
     buried.addActionListener(this);
     user.setLabel(MessageManager.getString("action.user_defined"));
     user.addActionListener(this);
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'
+        }
+      }
+    }
   }
 
   /**