@Override public void visitEnd() { // Sort the TryCatchBlockNode elements by the length of their "try" block. Collections.sort( tryCatchBlocks, new Comparator<TryCatchBlockNode>() { @Override public int compare( final TryCatchBlockNode tryCatchBlockNode1, final TryCatchBlockNode tryCatchBlockNode2) { return blockLength(tryCatchBlockNode1) - blockLength(tryCatchBlockNode2); } private int blockLength(final TryCatchBlockNode tryCatchBlockNode) { int startIndex = instructions.indexOf(tryCatchBlockNode.start); int endIndex = instructions.indexOf(tryCatchBlockNode.end); return endIndex - startIndex; } }); // Update the 'target' of each try catch block annotation. for (int i = 0; i < tryCatchBlocks.size(); ++i) { tryCatchBlocks.get(i).updateIndex(i); } if (mv != null) { accept(mv); } } }
@Override public MethodVisitor visitMethod(int access, String mname, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, mname, desc, signature, exceptions); mv = new JSRInlinerAdapter(mv, access, mname, desc, signature, exceptions); mv = new SharedVariableAccessMethodTransformer(mname, new GeneratorAdapter(mv, access, mname, desc)); // TODO add other transformers mv = new TryCatchBlockSorter(mv, access, mname, desc, signature, exceptions); return mv; }
@Override public MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, methodName, desc, signature, exceptions); mv = new JSRInlinerAdapter(mv, access, methodName, desc, signature, exceptions); mv = new SynchronizedBlockTransformer(new GeneratorAdapter(mv, access, methodName, desc), className, methodName, fileName); mv = new SynchronizedMethodTransformer(new GeneratorAdapter(mv, access, methodName, desc), className, methodName, fileName, access, classVersion); mv = new LockTransformer(new GeneratorAdapter(mv, access, methodName, desc), lockPredicates, tryLockPredicates, unlockPredicates, className, methodName, fileName); mv = new TryCatchBlockSorter(mv, access, methodName, desc, signature, exceptions); return mv; } }
@Override public void visitEnd() { // Compares TryCatchBlockNodes by the length of their "try" block. Comparator<TryCatchBlockNode> comp = new Comparator<TryCatchBlockNode>() { public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) { int len1 = blockLength(t1); int len2 = blockLength(t2); return len1 - len2; } private int blockLength(TryCatchBlockNode block) { int startidx = instructions.indexOf(block.start); int endidx = instructions.indexOf(block.end); return endidx - startidx; } }; Collections.sort(tryCatchBlocks, comp); // Updates the 'target' of each try catch block annotation. for (int i = 0; i < tryCatchBlocks.size(); ++i) { tryCatchBlocks.get(i).updateIndex(i); } if (mv != null) { accept(mv); } } }
GeneratorAdapter mv = new GeneratorAdapter(access, m, new TryCatchBlockSorter(cv.visitMethod(access, m.getName(), m.getDescriptor(), null, null), access, m.getName(), m.getDescriptor(), null, null) );
@Override public void visitEnd() { // Sort the TryCatchBlockNode elements by the length of their "try" block. Collections.sort( tryCatchBlocks, new Comparator<TryCatchBlockNode>() { @Override public int compare( final TryCatchBlockNode tryCatchBlockNode1, final TryCatchBlockNode tryCatchBlockNode2) { return blockLength(tryCatchBlockNode1) - blockLength(tryCatchBlockNode2); } private int blockLength(final TryCatchBlockNode tryCatchBlockNode) { int startIndex = instructions.indexOf(tryCatchBlockNode.start); int endIndex = instructions.indexOf(tryCatchBlockNode.end); return endIndex - startIndex; } }); // Update the 'target' of each try catch block annotation. for (int i = 0; i < tryCatchBlocks.size(); ++i) { tryCatchBlocks.get(i).updateIndex(i); } if (mv != null) { accept(mv); } } }
@Override public void visitEnd() { // Sort the TryCatchBlockNode elements by the length of their "try" block. Collections.sort( tryCatchBlocks, new Comparator<TryCatchBlockNode>() { @Override public int compare( final TryCatchBlockNode tryCatchBlockNode1, final TryCatchBlockNode tryCatchBlockNode2) { return blockLength(tryCatchBlockNode1) - blockLength(tryCatchBlockNode2); } private int blockLength(final TryCatchBlockNode tryCatchBlockNode) { int startIndex = instructions.indexOf(tryCatchBlockNode.start); int endIndex = instructions.indexOf(tryCatchBlockNode.end); return endIndex - startIndex; } }); // Update the 'target' of each try catch block annotation. for (int i = 0; i < tryCatchBlocks.size(); ++i) { tryCatchBlocks.get(i).updateIndex(i); } if (mv != null) { accept(mv); } } }