Example usage for org.objectweb.asm Opcodes ASM4

List of usage examples for org.objectweb.asm Opcodes ASM4

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ASM4.

Prototype

int ASM4

To view the source code for org.objectweb.asm Opcodes ASM4.

Click Source Link

Usage

From source file:com.infradna.tool.bridge_method_injector.ClassAnnotationInjector.java

License:Open Source License

ClassAnnotationInjector(ClassVisitor cv) {
    super(Opcodes.ASM4, cv);
}

From source file:com.jayway.maven.plugins.android.asm.DescendantFinder.java

License:Apache License

/**
 * Constructs this finder.//from  w  w  w . j a  va  2 s . c o m
 *
 * @param parentPackages Packages to find descendants of. Must be formatted with <code>/</code> (slash) instead of
 *                       <code>.</code> (dot). For example: <code>junit/framework/</code>
 */
public DescendantFinder(String... parentPackages) {
    super(Opcodes.ASM4);
    this.parentPackages = parentPackages;
}

From source file:com.jitlogic.zorka.core.spy.SpyMethodVisitor.java

License:Open Source License

/**
 * Standard constructor./*  w w  w .  j  a v a 2 s  . c  om*/
 *
 * @param matches         true if visitor should always instrument or false if it should check for annotations
 * @param access          method access flags
 * @param methodName      method name
 * @param methodSignature method descriptor
 * @param ctxs            spy contexts interested in receiving data from this visitor
 * @param mv              method visitor (next in processing chain)
 *                        TODO add explicit doTrace argument
 */
public SpyMethodVisitor(boolean matches, SymbolRegistry symbolRegistry, String className,
        List<String> classAnnotations, List<String> classInterfaces, int access, String methodName,
        String methodSignature, List<SpyContext> ctxs, MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
    this.matches = matches;
    this.symbolRegistry = symbolRegistry;
    this.className = className;
    this.classAnnotations = classAnnotations;
    this.classInterfaces = classInterfaces;
    this.access = access;
    this.methodName = methodName;
    this.methodSignature = methodSignature;
    this.ctxs = ctxs;

    argTypes = Type.getArgumentTypes(methodSignature);
    returnType = Type.getReturnType(methodSignature);

    checkReturnVals();
}

From source file:com.lodgon.parboiled.transform.AsmTestUtils.java

License:Apache License

public static String getClassDump(byte[] code) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    TraceClassVisitor traceClassVisitor = new TraceClassVisitor(printWriter);
    ClassVisitor checkClassAdapter = new ClassVisitor(Opcodes.ASM4, traceClassVisitor) {
    };//from ww w .j  a va 2  s  .  com
    //ClassAdapter checkClassAdapter = new CheckClassAdapter(traceClassVisitor);
    ClassReader classReader;
    classReader = new ClassReader(code);
    classReader.accept(checkClassAdapter, 0);
    printWriter.flush();
    return stringWriter.toString();
}

From source file:com.lodgon.parboiled.transform.AsmTestUtils.java

License:Apache License

public static void verifyIntegrity(String classInternalName, byte[] classCode) {
    checkArgNotNull(classCode, "classCode");
    ClassNode generatedClassNode = new ClassNode(Opcodes.ASM4);
    ClassReader classReader = new ClassReader(classCode);
    classReader.accept(generatedClassNode, 0);

    for (Object methodObj : generatedClassNode.methods) {
        verifyMethodIntegrity(classInternalName, (MethodNode) methodObj);
    }/*from   w  w w. j ava  2  s. c o  m*/
}

From source file:com.lodgon.parboiled.transform.ClassNodeInitializer.java

License:Open Source License

public ClassNodeInitializer() {
    super(Opcodes.ASM4);
}

From source file:com.lodgon.parboiled.transform.ParserClassNode.java

License:Open Source License

public ParserClassNode(Class<?> parentClass) {
    super(Opcodes.ASM4);
    this.parentClass = checkArgNotNull(parentClass, "parentClass");
    parentType = Type.getType(parentClass);
}

From source file:com.lsgllc.mojo.genasm.GenAsmMojo.java

License:Apache License

private String processClassFile(String fileName, String crusherPropFleName, String implSrc1)
        throws MojoExecutionException {
    if (fileName == null || fileName.isEmpty()) {
        return null;
    }/* www  .  java  2 s  .  com*/
    String fileNameMajor = getFileNameMajor(fileName);
    String canonicalPropertyFileNameMajor = getCanonicalPropertyFileNameMajor(fileNameMajor);
    getLog().info("commentOutCode is " + ((commentOutCode) ? "true" : "false"));
    getLog().info("Creating template file: " + resourceDirectory + "/" + fileNameMajor);
    getLog().info("Generating Byte-Code instructions using " + fileName);
    if (fileName == null || fileName.length() == 0) {
        getLog().info("Parameter fileName is null");
        return null;
    }

    try {
        String nameMod = outputDir + "/classes/" + fileName.replace('.', '/') + ".class";
        //            ClassPathHacker.addFile(f);
        getLog().info("attempting to load class  " + nameMod + " as a resource...");
        //            InputStream is = new FileInputStream(nameMod);
        km.clear();
        new NormGenASMifier(Opcodes.ASM4, nameMod, 0, canonicalPropertyFileNameMajor, commentOutCode,
                crusherPropFleName, implSrc1, km, true);
    } catch (Exception e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error Creating Byte Code properties file", e);
    } finally {
        return canonicalPropertyFileNameMajor;
    }
}

From source file:com.mebigfatguy.junitflood.classpath.ClassInfoCollectingVisitor.java

License:Apache License

public ClassInfoCollectingVisitor(ClassDetails info) {
    super(Opcodes.ASM4);
    details = info;
}

From source file:com.mgmtp.perfload.agent.Transformer.java

License:Apache License

@Override
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined,
        final ProtectionDomain protectionDomain, final byte[] classfileBuffer)
        throws IllegalClassFormatException {

    final String classNameWithDots = className.replace('/', '.');
    EntryPoints entryPoints = config.getEntryPoints();

    final Map<String, MethodInstrumentations> methodsConfig = config.getInstrumentations()
            .get(classNameWithDots);//from  ww w. java  2  s  . c o m
    final boolean isFilter = entryPoints.hasFilter(classNameWithDots);
    final boolean isServlet = entryPoints.hasServlet(classNameWithDots);

    if (methodsConfig == null && !isFilter && !isServlet) {
        // no instrumentation configured for this class
        // return null, so no transformation is done
        return null;
    }

    logger.writeln("Transforming class: " + classNameWithDots);

    // flag for storing if at least one hook is weaved in
    final MutableBoolean weaveFlag = new MutableBoolean();

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
    ClassVisitor cv = new ClassVisitor(Opcodes.ASM4, cw) {
        @Override
        public MethodVisitor visitMethod(final int access, final String name, final String desc,
                final String signature, final String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            if (mv != null) {
                if (isFilter && "doFilter".equals(name)
                        || isServlet && "service".equals(name) && SERVLET_SERVICE_DESC.equals(desc)) {
                    mv = createServletApiHookVisitor(access, name, desc, mv);
                }
                if (methodsConfig != null) {
                    MethodInstrumentations methodInstrumentations = methodsConfig.get(name);
                    if (methodInstrumentations != null) {
                        mv = createMeasuringHookVisitor(access, name, desc, mv, methodInstrumentations);
                    }
                }
            }
            return mv;
        }

        private MethodVisitor createMeasuringHookVisitor(final int access, final String methodName,
                final String desc, final MethodVisitor mv,
                final MethodInstrumentations methodInstrumentations) {
            boolean weave = false;
            if (methodInstrumentations.isEmpty()) {
                // no params configured, so we just weave the hook into any method with this name
                weave = true;
            } else {
                // weave if params match
                for (List<String> paramClassNames : methodInstrumentations) {
                    Type[] argumentTypes = Type.getArgumentTypes(desc);
                    List<String> classNames = newArrayListWithCapacity(argumentTypes.length);
                    for (Type argumentType : argumentTypes) {
                        classNames.add(argumentType.getClassName());
                    }
                    if (classNames.equals(paramClassNames)) {
                        weave = true;
                        break;
                    }
                }
            }
            if (weave) {
                logger.writeln("Instrumenting method: " + classNameWithDots + "." + methodName);
                weaveFlag.setValue(true);
                return new MeasuringHookMethodVisitor(access, classNameWithDots, methodName, desc, mv);
            }
            return mv;
        }

        private MethodVisitor createServletApiHookVisitor(final int access, final String methodName,
                final String desc, final MethodVisitor mv) {
            logger.writeln("Adding servlet api hook: " + classNameWithDots + "." + methodName);
            weaveFlag.setValue(true);
            return new ServletApiHookMethodVisitor(access, methodName, desc, mv);
        }
    };

    // accept the visitor in order to perform weaving
    cr.accept(cv, ClassReader.EXPAND_FRAMES);

    if (weaveFlag.isTrue()) {
        byte[] transformedclassBytes = cw.toByteArray();
        dumpTransformedClassFile(className, transformedclassBytes);
        return transformedclassBytes;
    }

    // no transformation
    return null;
}