当前位置: 首页>>代码示例>>Java>>正文


Java ClassReader类代码示例

本文整理汇总了Java中org.kohsuke.asm5.ClassReader的典型用法代码示例。如果您正苦于以下问题:Java ClassReader类的具体用法?Java ClassReader怎么用?Java ClassReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassReader类属于org.kohsuke.asm5包,在下文中一共展示了ClassReader类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import org.kohsuke.asm5.ClassReader; //导入依赖的package包/类
public byte[] transform(String className, byte[] classfileBuffer) {
        final ClassTransformSpec cs = specs.get(className);
        if(cs==null)
            return classfileBuffer;

        ClassReader cr = new ClassReader(classfileBuffer);
        ClassWriter cw = new ClassWriter(/*ClassWriter.COMPUTE_FRAMES|*/ClassWriter.COMPUTE_MAXS);
        cr.accept(new ClassVisitor(ASM5,cw) {
            @Override
            public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
                MethodVisitor base = super.visitMethod(access, name, desc, signature, exceptions);

                MethodTransformSpec ms = cs.methodSpecs.get(name + desc);
                if(ms==null)    ms = cs.methodSpecs.get(name+"*");
                if(ms==null)    return base;

                return ms.newAdapter(base,access,name,desc,signature,exceptions);
            }
        }, SKIP_FRAMES);

//        System.out.println("Transforming "+className);
        return cw.toByteArray();
    }
 
开发者ID:kohsuke,项目名称:eiie-logger,代码行数:24,代码来源:TransformerImpl.java

示例2: transform

import org.kohsuke.asm5.ClassReader; //导入依赖的package包/类
byte[] transform(String className, byte[] classfileBuffer) {
    final ClassTransformSpec cs = specs.get(className);
    if(cs==null)
        return classfileBuffer;

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
    cr.accept(new ClassVisitor(ASM5,cw) {
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor base = super.visitMethod(access, name, desc, signature, exceptions);

            MethodTransformSpec ms = cs.methodSpecs.get(name + desc);
            if (ms == null) ms = cs.methodSpecs.get(name+"*");
            if (ms == null) ms = cs.methodSpecs.get("*");
            if (ms == null) return base;

            if (ms.skip) return base;

            //System.out.println("'" + name + "' : '" + desc + "'");

            return ms.newAdapter(base,access,name,desc,signature,exceptions);
        }
    }, SKIP_FRAMES);

    return cw.toByteArray();
}
 
开发者ID:shabanovd,项目名称:aXent,代码行数:28,代码来源:TransformerImpl.java

示例3: transform

import org.kohsuke.asm5.ClassReader; //导入依赖的package包/类
private byte[] transform(String className, byte[] classfileBuffer) {
    final ClassTransformSpec cs = specs.get(className);
    if(cs==null)
        return classfileBuffer;

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
    cr.accept(new ClassVisitor(ASM5,cw) {
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor base = super.visitMethod(access, name, desc, signature, exceptions);

            MethodTransformSpec ms = cs.methodSpecs.get(name + desc);
            if (ms == null) ms = cs.methodSpecs.get(name+"*");
            if (ms == null) ms = cs.methodSpecs.get("*");
            if (ms == null) return base;

            if (ms.skip) return base;

            //System.out.println("'" + name + "' : '" + desc + "'");

            return ms.newAdapter(base,access,name,desc,signature,exceptions);
        }
    }, SKIP_FRAMES);

    return cw.toByteArray();
}
 
开发者ID:shabanovd,项目名称:aXent,代码行数:28,代码来源:TransformerImpl.java

示例4: scanInputStreamOfClassFile

import org.kohsuke.asm5.ClassReader; //导入依赖的package包/类
protected void scanInputStreamOfClassFile(final InputStream inputStream, final ClassLoader classLoader,
        final boolean strictClassLoader) throws IOException {
    try {
        final ClassReader classReader = new ClassReader(inputStream);
        final DCClassVisitor visitor = new DCClassVisitor(classLoader, _renderingFormatPredicate);
        classReader.accept(visitor, ClassReader.SKIP_CODE);

        final Class<?> beanClass = visitor.getBeanClass();
        if (beanClass == null) {
            return;
        }

        if (strictClassLoader && classLoader != null && beanClass.getClassLoader() != classLoader) {
            logger.warn("Scanned class did not belong to required classloader: " + beanClass + ", ignoring");
            return;
        }

        if (visitor.isAnalyzer()) {
            @SuppressWarnings("unchecked") final Class<? extends Analyzer<?>> analyzerClass =
                    (Class<? extends Analyzer<?>>) beanClass;
            logger.debug("Adding analyzer class: {}", beanClass);
            addAnalyzerClass(analyzerClass);
        }
        if (visitor.isTransformer()) {
            @SuppressWarnings("unchecked") final Class<? extends Transformer> transformerClass =
                    (Class<? extends Transformer>) beanClass;
            logger.debug("Adding transformer class: {}", beanClass);
            addTransformerClass(transformerClass);
        }
        if (visitor.isFilter()) {
            @SuppressWarnings("unchecked") final Class<? extends Filter<? extends Enum<?>>> filterClass =
                    (Class<? extends Filter<?>>) beanClass;
            logger.debug("Adding filter class: {}", beanClass);
            addFilterClass(filterClass);
        }
        if (visitor.isRenderer()) {
            @SuppressWarnings("unchecked") final Class<? extends Renderer<?, ?>> rendererClass =
                    (Class<? extends Renderer<?, ?>>) beanClass;
            logger.debug("Adding renderer class: {}", beanClass);
            addRendererClass(rendererClass);
        }
    } finally {
        FileHelper.safeClose(inputStream);
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:46,代码来源:ClasspathScanDescriptorProvider.java

示例5: scanInputStreamOfClassFile

import org.kohsuke.asm5.ClassReader; //导入依赖的package包/类
protected void scanInputStreamOfClassFile(final InputStream inputStream, final ClassLoader classLoader,
        final boolean strictClassLoader) throws IOException {
    try {
        final ClassReader classReader = new ClassReader(inputStream);
        final BeanClassVisitor visitor = new BeanClassVisitor(classLoader, _renderingFormatPredicate);
        classReader.accept(visitor, ClassReader.SKIP_CODE);

        Class<?> beanClass = visitor.getBeanClass();
        if (beanClass == null) {
            return;
        }

        if (strictClassLoader && classLoader != null && beanClass.getClassLoader() != classLoader) {
            logger.warn("Scanned class did not belong to required classloader: " + beanClass + ", ignoring");
            return;
        }

        if (visitor.isAnalyzer()) {
            @SuppressWarnings("unchecked")
            Class<? extends Analyzer<?>> analyzerClass = (Class<? extends Analyzer<?>>) beanClass;
            logger.info("Adding analyzer class: {}", beanClass);
            addAnalyzerClass(analyzerClass);
        }
        if (visitor.isTransformer()) {
            @SuppressWarnings("unchecked")
            Class<? extends Transformer<?>> transformerClass = (Class<? extends Transformer<?>>) beanClass;
            logger.info("Adding transformer class: {}", beanClass);
            addTransformerClass(transformerClass);
        }
        if (visitor.isFilter()) {
            @SuppressWarnings("unchecked")
            Class<? extends Filter<? extends Enum<?>>> filterClass = (Class<? extends Filter<?>>) beanClass;
            logger.info("Adding filter class: {}", beanClass);
            addFilterClass(filterClass);
        }
        if (visitor.isRenderer()) {
            @SuppressWarnings("unchecked")
            Class<? extends Renderer<?, ?>> rendererClass = (Class<? extends Renderer<?, ?>>) beanClass;
            logger.info("Adding renderer class: {}", beanClass);
            addRendererClass(rendererClass);
        }
    } finally {
        FileHelper.safeClose(inputStream);
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:46,代码来源:ClasspathScanDescriptorProvider.java


注:本文中的org.kohsuke.asm5.ClassReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。