當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassReader類代碼示例

本文整理匯總了Java中org.mvel2.asm.ClassReader的典型用法代碼示例。如果您正苦於以下問題:Java ClassReader類的具體用法?Java ClassReader怎麽用?Java ClassReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassReader類屬於org.mvel2.asm包,在下文中一共展示了ClassReader類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processEntry

import org.mvel2.asm.ClassReader; //導入依賴的package包/類
private void processEntry(final ZipInputStream zis, final ZipEntry ze,
        final ContentHandlerFactory handlerFactory) {
    ContentHandler handler = handlerFactory.createContentHandler();
    try {

        // if (CODE2ASM.equals(command)) { // read bytecode and process it
        // // with TraceClassVisitor
        // ClassReader cr = new ClassReader(readEntry(zis, ze));
        // cr.accept(new TraceClassVisitor(null, new PrintWriter(os)),
        // false);
        // }

        boolean singleInputDocument = inRepresentation == SINGLE_XML;
        if (inRepresentation == BYTECODE) { // read bytecode and process it
            // with handler
            ClassReader cr = new ClassReader(readEntry(zis, ze));
            cr.accept(new SAXClassAdapter(handler, singleInputDocument), 0);

        } else { // read XML and process it with handler
            XMLReader reader = XMLReaderFactory.createXMLReader();
            reader.setContentHandler(handler);
            reader.parse(new InputSource(
                    singleInputDocument ? (InputStream) new ProtectedInputStream(
                            zis) : new ByteArrayInputStream(readEntry(zis,
                            ze))));

        }
    } catch (Exception ex) {
        update(ze.getName(), 0);
        update(ex, 0);
    }
}
 
開發者ID:osswangxining,項目名稱:mvel-jsr223,代碼行數:33,代碼來源:Processor.java

示例2: verify

import org.mvel2.asm.ClassReader; //導入依賴的package包/類
/**
 * Checks a given class.
 * 
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null ? null : Type
            .getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
開發者ID:osswangxining,項目名稱:mvel-jsr223,代碼行數:52,代碼來源:CheckClassAdapter.java


注:本文中的org.mvel2.asm.ClassReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。