< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/commons/TryCatchBlockSorter.java

Print this page
rev 47452 : imported patch jdk-new-asmv6.patch


  69 
  70 /**
  71  * A {@link MethodVisitor} adapter to sort the exception handlers. The handlers
  72  * are sorted in a method innermost-to-outermost. This allows the programmer to
  73  * add handlers without worrying about ordering them correctly with respect to
  74  * existing, in-code handlers.
  75  *
  76  * Behavior is only defined for properly-nested handlers. If any "try" blocks
  77  * overlap (something that isn't possible in Java code) then this may not do
  78  * what you want. In fact, this adapter just sorts by the length of the "try"
  79  * block, taking advantage of the fact that a given try block must be larger
  80  * than any block it contains).
  81  *
  82  * @author Adrian Sampson
  83  */
  84 public class TryCatchBlockSorter extends MethodNode {
  85 
  86     public TryCatchBlockSorter(final MethodVisitor mv, final int access,
  87             final String name, final String desc, final String signature,
  88             final String[] exceptions) {
  89         this(Opcodes.ASM5, mv, access, name, desc, signature, exceptions);
  90     }
  91 
  92     protected TryCatchBlockSorter(final int api, final MethodVisitor mv,
  93             final int access, final String name, final String desc,
  94             final String signature, final String[] exceptions) {
  95         super(api, access, name, desc, signature, exceptions);
  96         this.mv = mv;
  97     }
  98 
  99     @Override
 100     public void visitEnd() {
 101         // Compares TryCatchBlockNodes by the length of their "try" block.
 102         Comparator<TryCatchBlockNode> comp = new Comparator<TryCatchBlockNode>() {
 103 
 104             public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) {
 105                 int len1 = blockLength(t1);
 106                 int len2 = blockLength(t2);
 107                 return len1 - len2;
 108             }
 109 


  69 
  70 /**
  71  * A {@link MethodVisitor} adapter to sort the exception handlers. The handlers
  72  * are sorted in a method innermost-to-outermost. This allows the programmer to
  73  * add handlers without worrying about ordering them correctly with respect to
  74  * existing, in-code handlers.
  75  *
  76  * Behavior is only defined for properly-nested handlers. If any "try" blocks
  77  * overlap (something that isn't possible in Java code) then this may not do
  78  * what you want. In fact, this adapter just sorts by the length of the "try"
  79  * block, taking advantage of the fact that a given try block must be larger
  80  * than any block it contains).
  81  *
  82  * @author Adrian Sampson
  83  */
  84 public class TryCatchBlockSorter extends MethodNode {
  85 
  86     public TryCatchBlockSorter(final MethodVisitor mv, final int access,
  87             final String name, final String desc, final String signature,
  88             final String[] exceptions) {
  89         this(Opcodes.ASM6, mv, access, name, desc, signature, exceptions);
  90     }
  91 
  92     protected TryCatchBlockSorter(final int api, final MethodVisitor mv,
  93             final int access, final String name, final String desc,
  94             final String signature, final String[] exceptions) {
  95         super(api, access, name, desc, signature, exceptions);
  96         this.mv = mv;
  97     }
  98 
  99     @Override
 100     public void visitEnd() {
 101         // Compares TryCatchBlockNodes by the length of their "try" block.
 102         Comparator<TryCatchBlockNode> comp = new Comparator<TryCatchBlockNode>() {
 103 
 104             public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) {
 105                 int len1 = blockLength(t1);
 106                 int len2 = blockLength(t2);
 107                 return len1 - len2;
 108             }
 109 
< prev index next >