public MethodGen()

in src/main/java/org/apache/bcel/generic/MethodGen.java [313:373]


    public MethodGen(final Method method, final String className, final ConstantPoolGen cp) {
        this(method.getAccessFlags(), Type.getReturnType(method.getSignature()), Type.getArgumentTypes(method.getSignature()),
            null /* may be overridden anyway */
            , method.getName(), className,
            (method.getAccessFlags() & (Const.ACC_ABSTRACT | Const.ACC_NATIVE)) == 0 ? new InstructionList(getByteCodes(method)) : null, cp);
        final Attribute[] attributes = method.getAttributes();
        for (final Attribute attribute : attributes) {
            Attribute a = attribute;
            if (a instanceof Code) {
                final Code c = (Code) a;
                setMaxStack(c.getMaxStack());
                setMaxLocals(c.getMaxLocals());
                final CodeException[] ces = c.getExceptionTable();
                if (ces != null) {
                    for (final CodeException ce : ces) {
                        final int type = ce.getCatchType();
                        ObjectType cType = null;
                        if (type > 0) {
                            final String cen = method.getConstantPool().getConstantString(type, Const.CONSTANT_Class);
                            cType = ObjectType.getInstance(cen);
                        }
                        final int endPc = ce.getEndPC();
                        final int length = getByteCodes(method).length;
                        InstructionHandle end;
                        if (length == endPc) { // May happen, because end_pc is exclusive
                            end = il.getEnd();
                        } else {
                            end = il.findHandle(endPc);
                            end = end.getPrev(); // Make it inclusive
                        }
                        addExceptionHandler(il.findHandle(ce.getStartPC()), end, il.findHandle(ce.getHandlerPC()), cType);
                    }
                }
                final Attribute[] cAttributes = c.getAttributes();
                for (final Attribute cAttribute : cAttributes) {
                    a = cAttribute;
                    if (a instanceof LineNumberTable) {
                        ((LineNumberTable) a).forEach(l -> {
                            final InstructionHandle ih = il.findHandle(l.getStartPC());
                            if (ih != null) {
                                addLineNumber(ih, l.getLineNumber());
                            }
                        });
                    } else if (a instanceof LocalVariableTable) {
                        updateLocalVariableTable((LocalVariableTable) a);
                    } else if (a instanceof LocalVariableTypeTable) {
                        this.localVariableTypeTable = (LocalVariableTypeTable) a.copy(cp.getConstantPool());
                    } else {
                        addCodeAttribute(a);
                    }
                }
            } else if (a instanceof ExceptionTable) {
                Collections.addAll(throwsList, ((ExceptionTable) a).getExceptionNames());
            } else if (a instanceof Annotations) {
                final Annotations runtimeAnnotations = (Annotations) a;
                runtimeAnnotations.forEach(element -> addAnnotationEntry(new AnnotationEntryGen(element, cp, false)));
            } else {
                addAttribute(a);
            }
        }
    }