OSDN Git Service

A bunch of minor cleanups.
authorDan Bornstein <danfuzz@android.com>
Fri, 29 Oct 2010 20:01:27 +0000 (13:01 -0700)
committerDan Bornstein <danfuzz@android.com>
Fri, 29 Oct 2010 20:01:27 +0000 (13:01 -0700)
I'm reacquainting myself with this code, and figured I might as well
do some of that nit-picky code convention tweakage while I was there.
The only non-whitespace non-comment changes I made were to change the
scope of a couple of methods to be more appropriate.

Change-Id: I550978ed0f5b9ccec938faef7c00d09532832ee4

dx/src/com/android/dx/command/dump/BlockDumper.java
dx/src/com/android/dx/rop/code/BasicBlockList.java
dx/src/com/android/dx/util/LabeledList.java

index 7a11888..45f85b8 100644 (file)
@@ -80,10 +80,9 @@ public class BlockDumper
      * @param args commandline parsedArgs
      */
     public static void dump(byte[] bytes, PrintStream out,
-                            String filePath, boolean rop, Args args) {
-        BlockDumper bd =
-            new BlockDumper(bytes, out, filePath,
-                            rop, args);
+            String filePath, boolean rop, Args args) {
+        BlockDumper bd = new BlockDumper(bytes, out, filePath,
+                rop, args);
         bd.dump();
     }
 
@@ -91,9 +90,8 @@ public class BlockDumper
      * Constructs an instance. This class is not publicly instantiable.
      * Use {@link #dump}.
      */
-    BlockDumper(byte[] bytes, PrintStream out,
-                        String filePath,
-                        boolean rop, Args args) {
+    BlockDumper(byte[] bytes, PrintStream out, String filePath,
+            boolean rop, Args args) {
         super(bytes, out, filePath, args);
 
         this.rop = rop;
@@ -153,7 +151,7 @@ public class BlockDumper
     /** {@inheritDoc} */
     @Override
     public void startParsingMember(ByteArray bytes, int offset, String name,
-                                   String descriptor) {
+            String descriptor) {
         if (descriptor.indexOf('(') < 0) {
             // It's a field, not a method
             return;
@@ -181,7 +179,7 @@ public class BlockDumper
     /** {@inheritDoc} */
     @Override
     public void endParsingMember(ByteArray bytes, int offset, String name,
-                                 String descriptor, Member member) {
+            String descriptor, Member member) {
         if (!(member instanceof Method)) {
             return;
         }
@@ -190,8 +188,8 @@ public class BlockDumper
             return;
         }
 
-        ConcreteMethod meth = new ConcreteMethod((Method) member, classFile,
-                                                 true, true);
+        ConcreteMethod meth =
+            new ConcreteMethod((Method) member, classFile, true, true);
 
         if (rop) {
             ropDump(meth);
@@ -212,7 +210,7 @@ public class BlockDumper
         int sz = list.size();
         CodeObserver codeObserver = new CodeObserver(bytes, BlockDumper.this);
 
-        // Reset the dump cursor to the start of the bytecode
+        // Reset the dump cursor to the start of the bytecode.
         setAt(bytes, 0);
 
         suppressDump = false;
@@ -229,8 +227,8 @@ public class BlockDumper
             }
 
             parsed(bytes, start, 0,
-                   "block " + Hex.u2(bb.getLabel()) + ": " +
-                   Hex.u2(start) + ".." + Hex.u2(end));
+                    "block " + Hex.u2(bb.getLabel()) + ": " +
+                    Hex.u2(start) + ".." + Hex.u2(end));
             changeIndent(1);
 
             int len;
@@ -269,7 +267,7 @@ public class BlockDumper
         int end = bytes.size();
         if (byteAt < end) {
             parsed(bytes, byteAt, end - byteAt,
-                   "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
+                    "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
         }
 
         suppressDump = true;
@@ -281,21 +279,17 @@ public class BlockDumper
      * @param meth {@code non-null;} method data to dump
      */
     private void ropDump(ConcreteMethod meth) {
+        TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
         BytecodeArray code = meth.getCode();
         ByteArray bytes = code.getBytes();
-
-        TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
-
-        RopMethod rmeth =
-            Ropper.convert(meth, advice);
+        RopMethod rmeth = Ropper.convert(meth, advice);
         StringBuffer sb = new StringBuffer(2000);
 
         if (optimize) {
             boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags());
-
             int paramWidth = computeParamWidth(meth, isStatic);
-            rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true,
-                    advice);
+            rmeth =
+                Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice);
         }
 
         BasicBlockList blocks = rmeth.getBlocks();
index ea7b497..ef79075 100644 (file)
@@ -49,7 +49,7 @@ public final class BasicBlockList extends LabeledList {
      *
      * @param old block to copy
      */
-    private BasicBlockList (BasicBlockList old) {
+    private BasicBlockList(BasicBlockList old) {
         super(old);
         regCount = old.regCount;
     }
@@ -147,7 +147,6 @@ public final class BasicBlockList extends LabeledList {
         return result;
     }
 
-
     /**
      * Gets the first block in the list with the given label, if any.
      *
@@ -257,8 +256,7 @@ public final class BasicBlockList extends LabeledList {
      * @return {@code true} if the two blocks' non-primary successors
      * are identical
      */
-    public boolean catchesEqual(BasicBlock block1,
-            BasicBlock block2) {
+    public boolean catchesEqual(BasicBlock block1, BasicBlock block2) {
         TypeList catches1 = block1.getExceptionHandlerTypes();
         TypeList catches2 = block2.getExceptionHandlerTypes();
 
index 5b6e125..20dc8b3 100644 (file)
 
 package com.android.dx.util;
 
-import com.android.dx.cf.code.ByteBlock;
-
 /**
  * A list of labeled items, allowing easy lookup by label.
  */
 public class LabeledList extends FixedSizeList {
-
     /**
-     * Sparse array indexed by label to FixedSizeList index.
-     * -1 = invalid label.
+     * Sparse array indexed by label to FixedSizeList index;
+     * {@code -1} for an invalid label.
      */
     private final IntList labelToIndex;
 
@@ -41,7 +38,7 @@ public class LabeledList extends FixedSizeList {
      *
      * @param old instance to copy
      */
-    protected LabeledList(LabeledList old) {
+    public LabeledList(LabeledList old) {
         super(old.size());
         labelToIndex = old.labelToIndex.mutableCopy();
 
@@ -63,12 +60,12 @@ public class LabeledList extends FixedSizeList {
     public int getMaxLabel() {
         int sz = labelToIndex.size();
 
-        // Gobble any deleted labels that may be at the end...
+        // Gobble any deleted labels that may be at the end.
         int i;
         for (i = sz - 1; (i >= 0) && (labelToIndex.get(i) < 0); i--)
-            ;
+            /*empty*/ ;
 
-        int newSize = i+1;
+        int newSize = i + 1;
 
         labelToIndex.shrink(newSize);
 
@@ -76,19 +73,21 @@ public class LabeledList extends FixedSizeList {
     }
 
     /**
-     * Removes a label from the label-to-index mapping
+     * Removes a label from the label-to-index mapping.
+     *
      * @param oldLabel label to remove
      */
-    protected void removeLabel(int oldLabel) {
+    private void removeLabel(int oldLabel) {
         labelToIndex.set(oldLabel, -1);
     }
 
     /**
-     * Adds a label and index to the label-to-index mapping
+     * Adds a label and index to the label-to-index mapping.
+     *
      * @param label new label
      * @param index index of block.
      */
-    protected void addLabelIndex(int label, int index) {
+    private void addLabelIndex(int label, int index) {
         int origSz = labelToIndex.size();
 
         for (int i = 0; i <= (label - origSz); i++) {
@@ -123,11 +122,11 @@ public class LabeledList extends FixedSizeList {
     }
 
     /**
-     * Rebuilds the label-to-index mapping after a shrinkToFit().
-     * Note: assumes that the labels that are in the list are the same
-     * although the indicies may have changed.
+     * Rebuilds the label-to-index mapping after a {@code shrinkToFit()}.
+     * Note: This assumes that the labels that are in the list are the
+     * same, although the indicies may have changed.
      */
-    protected void rebuildLabelToIndex() {
+    private void rebuildLabelToIndex() {
         int szItems = size();
 
         for (int i = 0; i < szItems; i++) {