Commit de2eb659 authored by Eric Bruneton's avatar Eric Bruneton

Improve the code quality of TryCatchBlockSorter.

parent 3224adf0
Pipeline #1222 passed with stage
in 6 minutes and 12 seconds
......@@ -51,13 +51,13 @@ import org.objectweb.asm.tree.TryCatchBlockNode;
public class TryCatchBlockSorter extends MethodNode {
public TryCatchBlockSorter(
final MethodVisitor mv,
final MethodVisitor methodVisitor,
final int access,
final String name,
final String desc,
final String descriptor,
final String signature,
final String[] exceptions) {
this(Opcodes.ASM6, mv, access, name, desc, signature, exceptions);
this(Opcodes.ASM6, methodVisitor, access, name, descriptor, signature, exceptions);
if (getClass() != TryCatchBlockSorter.class) {
throw new IllegalStateException();
}
......@@ -65,36 +65,36 @@ public class TryCatchBlockSorter extends MethodNode {
protected TryCatchBlockSorter(
final int api,
final MethodVisitor mv,
final MethodVisitor methodVisitor,
final int access,
final String name,
final String desc,
final String descriptor,
final String signature,
final String[] exceptions) {
super(api, access, name, desc, signature, exceptions);
this.mv = mv;
super(api, access, name, descriptor, signature, exceptions);
this.mv = methodVisitor;
}
@Override
public void visitEnd() {
// Compares TryCatchBlockNodes by the length of their "try" block.
Comparator<TryCatchBlockNode> comp =
// Sort the TryCatchBlockNode elements by the length of their "try" block.
Collections.sort(
tryCatchBlocks,
new Comparator<TryCatchBlockNode>() {
public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) {
int len1 = blockLength(t1);
int len2 = blockLength(t2);
return len1 - len2;
public int compare(
final TryCatchBlockNode tryCatchBlockNode1,
final TryCatchBlockNode tryCatchBlockNode2) {
return blockLength(tryCatchBlockNode1) - blockLength(tryCatchBlockNode2);
}
private int blockLength(TryCatchBlockNode block) {
int startidx = instructions.indexOf(block.start);
int endidx = instructions.indexOf(block.end);
return endidx - startidx;
private int blockLength(final TryCatchBlockNode tryCatchBlockNode) {
int startIndex = instructions.indexOf(tryCatchBlockNode.start);
int endIndex = instructions.indexOf(tryCatchBlockNode.end);
return endIndex - startIndex;
}
};
Collections.sort(tryCatchBlocks, comp);
// Updates the 'target' of each try catch block annotation.
});
// Update the 'target' of each try catch block annotation.
for (int i = 0; i < tryCatchBlocks.size(); ++i) {
tryCatchBlocks.get(i).updateIndex(i);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment