⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asmcontenthandler.java

📁 asm的源码包 并且包含英文的文档
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            if (s.indexOf("private") != -1) {
                access |= Opcodes.ACC_PRIVATE;
            }
            if (s.indexOf("protected") != -1) {
                access |= Opcodes.ACC_PROTECTED;
            }
            if (s.indexOf("static") != -1) {
                access |= Opcodes.ACC_STATIC;
            }
            if (s.indexOf("final") != -1) {
                access |= Opcodes.ACC_FINAL;
            }
            if (s.indexOf("super") != -1) {
                access |= Opcodes.ACC_SUPER;
            }
            if (s.indexOf("synchronized") != -1) {
                access |= Opcodes.ACC_SYNCHRONIZED;
            }
            if (s.indexOf("volatile") != -1) {
                access |= Opcodes.ACC_VOLATILE;
            }
            if (s.indexOf("bridge") != -1) {
                access |= Opcodes.ACC_BRIDGE;
            }
            if (s.indexOf("varargs") != -1) {
                access |= Opcodes.ACC_VARARGS;
            }
            if (s.indexOf("transient") != -1) {
                access |= Opcodes.ACC_TRANSIENT;
            }
            if (s.indexOf("native") != -1) {
                access |= Opcodes.ACC_NATIVE;
            }
            if (s.indexOf("interface") != -1) {
                access |= Opcodes.ACC_INTERFACE;
            }
            if (s.indexOf("abstract") != -1) {
                access |= Opcodes.ACC_ABSTRACT;
            }
            if (s.indexOf("strict") != -1) {
                access |= Opcodes.ACC_STRICT;
            }
            if (s.indexOf("synthetic") != -1) {
                access |= Opcodes.ACC_SYNTHETIC;
            }
            if (s.indexOf("annotation") != -1) {
                access |= Opcodes.ACC_ANNOTATION;
            }
            if (s.indexOf("enum") != -1) {
                access |= Opcodes.ACC_ENUM;
            }
            if (s.indexOf("deprecated") != -1) {
                access |= Opcodes.ACC_DEPRECATED;
            }
            return access;
        }
    }

    /**
     * ClassRule
     */
    private final class ClassRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            int major = Integer.parseInt(attrs.getValue("major"));
            int minor = Integer.parseInt(attrs.getValue("minor"));
            cw = new ClassWriter(computeMax ? ClassWriter.COMPUTE_MAXS : 0);
            HashMap vals = new HashMap();
            vals.put("version", new Integer(minor << 16 | major));
            vals.put("access", attrs.getValue("access"));
            vals.put("name", attrs.getValue("name"));
            vals.put("parent", attrs.getValue("parent"));
            vals.put("source", attrs.getValue("source"));
            vals.put("signature", attrs.getValue("signature"));
            vals.put("interfaces", new ArrayList());
            push(vals);
            // values will be extracted in InterfacesRule.end();
        }
    }

    private final class SourceRule extends Rule {

        public void begin(final String name, final Attributes attrs) {
            String file = attrs.getValue("file");
            String debug = attrs.getValue("debug");
            cw.visitSource(file, debug);
        }
    }

    /**
     * InterfaceRule
     */
    private final class InterfaceRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            ((List) ((HashMap) peek()).get("interfaces")).add(attrs.getValue("name"));
        }
    }

    /**
     * InterfacesRule
     */
    private final class InterfacesRule extends Rule {

        public final void end(final String element) {
            HashMap vals = (HashMap) pop();
            int version = ((Integer) vals.get("version")).intValue();
            int access = getAccess((String) vals.get("access"));
            String name = (String) vals.get("name");
            String signature = (String) vals.get("signature");
            String parent = (String) vals.get("parent");
            List infs = (List) vals.get("interfaces");
            String[] interfaces = (String[]) infs.toArray(new String[infs.size()]);
            cw.visit(version, access, name, signature, parent, interfaces);
            push(cw);
        }
    }

    /**
     * OuterClassRule
     */
    private final class OuterClassRule extends Rule {

        public final void begin(final String element, final Attributes attrs) {
            String owner = attrs.getValue("owner");
            String name = attrs.getValue("name");
            String desc = attrs.getValue("desc");
            cw.visitOuterClass(owner, name, desc);
        }
    }

    /**
     * InnerClassRule
     */
    private final class InnerClassRule extends Rule {

        public final void begin(final String element, final Attributes attrs) {
            int access = getAccess(attrs.getValue("access"));
            String name = attrs.getValue("name");
            String outerName = attrs.getValue("outerName");
            String innerName = attrs.getValue("innerName");
            cw.visitInnerClass(name, outerName, innerName, access);
        }
    }

    /**
     * FieldRule
     */
    private final class FieldRule extends Rule {

        public final void begin(final String element, final Attributes attrs)
                throws SAXException
        {
            int access = getAccess(attrs.getValue("access"));
            String name = attrs.getValue("name");
            String signature = attrs.getValue("signature");
            String desc = attrs.getValue("desc");
            Object value = getValue(desc, attrs.getValue("value"));
            push(cw.visitField(access, name, desc, signature, value));
        }

        public void end(final String name) {
            ((FieldVisitor) pop()).visitEnd();
        }
    }

    /**
     * MethodRule
     */
    private final class MethodRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            labels = new HashMap();
            HashMap vals = new HashMap();
            vals.put("access", attrs.getValue("access"));
            vals.put("name", attrs.getValue("name"));
            vals.put("desc", attrs.getValue("desc"));
            vals.put("signature", attrs.getValue("signature"));
            vals.put("exceptions", new ArrayList());
            push(vals);
            // values will be extracted in ExceptionsRule.end();
        }

        public final void end(final String name) {
            ((MethodVisitor) pop()).visitEnd();
            labels = null;
        }
    }

    /**
     * ExceptionRule
     */
    private final class ExceptionRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            ((List) ((HashMap) peek()).get("exceptions")).add(attrs.getValue("name"));
        }
    }

    /**
     * ExceptionsRule
     */
    private final class ExceptionsRule extends Rule {

        public final void end(final String element) {
            HashMap vals = (HashMap) pop();
            int access = getAccess((String) vals.get("access"));
            String name = (String) vals.get("name");
            String desc = (String) vals.get("desc");
            String signature = (String) vals.get("signature");
            List excs = (List) vals.get("exceptions");
            String[] exceptions = (String[]) excs.toArray(new String[excs.size()]);

            push(cw.visitMethod(access, name, desc, signature, exceptions));
        }
    }

    /**
     * TableSwitchRule
     */
    private class TableSwitchRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            HashMap vals = new HashMap();
            vals.put("min", attrs.getValue("min"));
            vals.put("max", attrs.getValue("max"));
            vals.put("dflt", attrs.getValue("dflt"));
            vals.put("labels", new ArrayList());
            push(vals);
        }

        public final void end(final String name) {
            HashMap vals = (HashMap) pop();
            int min = Integer.parseInt((String) vals.get("min"));
            int max = Integer.parseInt((String) vals.get("max"));
            Label dflt = getLabel(vals.get("dflt"));
            List lbls = (List) vals.get("labels");
            Label[] labels = (Label[]) lbls.toArray(new Label[lbls.size()]);
            getCodeVisitor().visitTableSwitchInsn(min, max, dflt, labels);
        }
    }

    /**
     * TableSwitchLabelRule
     */
    private final class TableSwitchLabelRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            ((List) ((HashMap) peek()).get("labels")).add(getLabel(attrs.getValue("name")));
        }
    }

    /**
     * LookupSwitchRule
     */
    private final class LookupSwitchRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            HashMap vals = new HashMap();
            vals.put("dflt", attrs.getValue("dflt"));
            vals.put("labels", new ArrayList());
            vals.put("keys", new ArrayList());
            push(vals);
        }

        public final void end(final String name) {
            HashMap vals = (HashMap) pop();
            Label dflt = getLabel(vals.get("dflt"));
            List keyList = (List) vals.get("keys");
            List lbls = (List) vals.get("labels");
            Label[] labels = (Label[]) lbls.toArray(new Label[lbls.size()]);
            int[] keys = new int[keyList.size()];
            for (int i = 0; i < keys.length; i++) {
                keys[i] = Integer.parseInt((String) keyList.get(i));
            }
            getCodeVisitor().visitLookupSwitchInsn(dflt, keys, labels);
        }
    }

    /**
     * LookupSwitchLabelRule
     */
    private final class LookupSwitchLabelRule extends Rule {

        public final void begin(final String name, final Attributes attrs) {
            HashMap vals = (HashMap) peek();
            ((List) vals.get("labels")).add(getLabel(attrs.getValue("name")));
            ((List) vals.get("keys")).add(attrs.getValue("key"));
        }
    }

    /**
     * FrameRule
     */
    private final class FrameRule extends Rule {

        public void begin(final String name, final Attributes attrs) {
            HashMap typeLists = new HashMap();
            typeLists.put("local", new ArrayList());
            typeLists.put("stack", new ArrayList());
            push(attrs.getValue("type"));
            push(attrs.getValue("count") == null
                    ? "0"
                    : attrs.getValue("count"));
            push(typeLists);
        }

        public void end(final String name) {
            HashMap typeLists = (HashMap) pop();
            List locals = (List) typeLists.get("local");
            int nLocal = locals.size();
            Object[] local = locals.toArray();
            List stacks = (List) typeLists.get("stack");
            int nStack = stacks.size();
            Object[] stack = stacks.toArray();
            String count = (String) pop();
            String type = (String) pop();
            if (type.equals("NEW")) {
                getCodeVisitor().visitFrame(Opcodes.F_NEW,
                        nLocal,
                        local,
                        nStack,
                        stack);
            } else if (type.equals("FULL")) {
                getCodeVisitor().visitFrame(Opcodes.F_FULL,
                        nLocal,
                        local,
                        nStack,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -