From 893ea594be06711902de7a484c0eecb910356f42 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Fri, 29 Oct 2010 13:01:27 -0700 Subject: [PATCH] A bunch of minor cleanups. 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 --- .../com/android/dx/command/dump/BlockDumper.java | 40 +++++++++------------- dx/src/com/android/dx/rop/code/BasicBlockList.java | 6 ++-- dx/src/com/android/dx/util/LabeledList.java | 33 +++++++++--------- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/dx/src/com/android/dx/command/dump/BlockDumper.java b/dx/src/com/android/dx/command/dump/BlockDumper.java index 7a118881d..45f85b8e9 100644 --- a/dx/src/com/android/dx/command/dump/BlockDumper.java +++ b/dx/src/com/android/dx/command/dump/BlockDumper.java @@ -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(); diff --git a/dx/src/com/android/dx/rop/code/BasicBlockList.java b/dx/src/com/android/dx/rop/code/BasicBlockList.java index ea7b497cf..ef7907501 100644 --- a/dx/src/com/android/dx/rop/code/BasicBlockList.java +++ b/dx/src/com/android/dx/rop/code/BasicBlockList.java @@ -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(); diff --git a/dx/src/com/android/dx/util/LabeledList.java b/dx/src/com/android/dx/util/LabeledList.java index 5b6e1251b..20dc8b3ed 100644 --- a/dx/src/com/android/dx/util/LabeledList.java +++ b/dx/src/com/android/dx/util/LabeledList.java @@ -16,16 +16,13 @@ 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++) { -- 2.11.0