src/share/classes/com/sun/tools/javac/comp/Lower.java

Print this page

        

@@ -3115,11 +3115,10 @@
             (stringSwitch? syms.stringType : syms.intType);
         tree.selector = translate(tree.selector, target);
         tree.cases = translateCases(tree.cases);
         if (enumSwitch) {
             result = visitEnumSwitch(tree);
-            patchTargets(result, tree, result);
         } else if (stringSwitch) {
             result = visitStringSwitch(tree);
         } else {
             result = tree;
         }

@@ -3144,11 +3143,13 @@
                 cases.append(make.Case(pat, c.stats));
             } else {
                 cases.append(c);
             }
         }
-        return make.Switch(selector, cases.toList());
+        JCSwitch enumSwitch = make.Switch(selector, cases.toList());
+        patchTargets(enumSwitch, tree, enumSwitch);
+        return enumSwitch;
     }
 
     public JCTree visitStringSwitch(JCSwitch tree) {
         List<JCCase> caseList = tree.getCases();
         int alternatives = caseList.size();

@@ -3185,11 +3186,18 @@
              *
              * The generated code assumes that the hashing algorithm
              * of String is the same in the compilation environment as
              * in the environment the code will run in.  The string
              * hashing algorithm in the SE JDK has been unchanged
-             * since at least JDK 1.2.
+             * since at least JDK 1.2.  Since the algorithm has been
+             * specified since that release as well, it is very
+             * unlikely to be changed in the future.
+             *
+             * Different hashing algorithms, such as the length of the
+             * strings or a perfect hashing algorithm over the
+             * particular set of case labels, could potentially be
+             * used instead of String.hashCode.
              */
 
             ListBuffer<JCStatement> stmtList = new ListBuffer<JCStatement>();
 
             // Map from String case labels to their original position in