001package io.ebean.enhance.asm.commons;
002
003import io.ebean.enhance.asm.Label;
004import io.ebean.enhance.asm.MethodVisitor;
005
006public abstract class FinallyAdapter extends AdviceAdapter {
007
008        protected Label startFinally = new Label();
009
010        public FinallyAdapter(final int api, MethodVisitor mv, int acc, String name, String desc) {
011                super(api, mv, acc, name, desc);
012        }
013
014        public void visitCode() {
015                super.visitCode();
016                mv.visitLabel(startFinally);
017        }
018
019        public void visitMaxs(int maxStack, int maxLocals) {
020
021                Label endFinally = new Label();
022                mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null);
023                mv.visitLabel(endFinally);
024                onFinally(ATHROW);
025                mv.visitInsn(ATHROW);
026                mv.visitMaxs(maxStack, maxLocals);
027        }
028
029        protected final void onMethodExit(int opcode) {
030                if (opcode != ATHROW) {
031                        onFinally(opcode);
032                }
033        }
034
035        protected abstract void onFinally(int opcode);
036        
037
038}