Simplify string transformation.

Also, check for index jumboization across the board.

Change-Id: I7a5a15f80155b7061b8bc6e15ffa315873ad1626
diff --git a/dx/src/com/android/dx/io/CodeReader.java b/dx/src/com/android/dx/io/CodeReader.java
index e6ea717..45f8ca2 100644
--- a/dx/src/com/android/dx/io/CodeReader.java
+++ b/dx/src/com/android/dx/io/CodeReader.java
@@ -297,12 +297,6 @@
      */
     public void setStringVisitor(Visitor visitor) {
         instructions[0x1a].setVisitor("const-string vAA, string@BBBB", visitor);
-    }
-
-    /**
-     * Sets {@code visitor} as the visitor for all jumbo string instructions.
-     */
-    public void setJumboStringVisitor(Visitor visitor) {
         instructions[0x1b].setVisitor("const-string/jumbo vAA, string@BBBBBBBB", visitor);
     }
 
diff --git a/dx/src/com/android/dx/merge/InstructionTransformer.java b/dx/src/com/android/dx/merge/InstructionTransformer.java
index e0dfc9f..d3499d8 100644
--- a/dx/src/com/android/dx/merge/InstructionTransformer.java
+++ b/dx/src/com/android/dx/merge/InstructionTransformer.java
@@ -32,7 +32,6 @@
         this.indexMap = indexMap;
         this.reader = new CodeReader();
         this.reader.setAllVisitors(new GenericVisitor());
-        this.reader.setJumboStringVisitor(new JumboStringVisitor());
         this.reader.setStringVisitor(new StringVisitor());
         this.reader.setTypeVisitor(new TypeVisitor());
         this.reader.setFieldVisitor(new FieldVisitor());
@@ -68,26 +67,16 @@
         public void visit(DecodedInstruction[] all, DecodedInstruction one) {
             int stringId = one.getIndex();
             int mappedId = indexMap.adjustString(stringId);
-            if (mappedId > 0xFFFF) {
-                throw new DexException("Cannot convert string to jumbo string!");
-            }
-
+            jumboCheck(stringId, mappedId);
             mappedInstructions[mappedAt++] = one.withIndex(mappedId);
         }
     }
 
-    private class JumboStringVisitor implements CodeReader.Visitor {
-        public void visit(DecodedInstruction[] all, DecodedInstruction one) {
-            throw new UnsupportedOperationException("Jumbo strings not implemented. "
-                    + "Due to a lack of dex files requiring jumbo strings, this class doesn't "
-                    + "bother to support jumbo strings!");
-        }
-    }
-
     private class FieldVisitor implements CodeReader.Visitor {
         public void visit(DecodedInstruction[] all, DecodedInstruction one) {
             int fieldId = one.getIndex();
             int mappedId = indexMap.adjustField(fieldId);
+            jumboCheck(fieldId, mappedId);
             mappedInstructions[mappedAt++] = one.withIndex(mappedId);
         }
     }
@@ -96,6 +85,7 @@
         public void visit(DecodedInstruction[] all, DecodedInstruction one) {
             int typeId = one.getIndex();
             int mappedId = indexMap.adjustType(typeId);
+            jumboCheck(typeId, mappedId);
             mappedInstructions[mappedAt++] = one.withIndex(mappedId);
         }
     }
@@ -104,7 +94,15 @@
         public void visit(DecodedInstruction[] all, DecodedInstruction one) {
             int methodId = one.getIndex();
             int mappedId = indexMap.adjustMethod(methodId);
+            jumboCheck(methodId, mappedId);
             mappedInstructions[mappedAt++] = one.withIndex(mappedId);
         }
     }
+
+    private static void jumboCheck(int oldIndex, int newIndex) {
+        if ((oldIndex <= 0xffff) && (newIndex > 0xffff)) {
+            throw new DexException("Cannot handle conversion to jumbo index!");
+        }
+    }
+
 }