Example usage for org.objectweb.asm Opcodes ASM5

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

Introduction

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

Prototype

int ASM5

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

Click Source Link

Usage

From source file:com.mebigfatguy.inventory.cls.ClassInventoryVisitor.java

License:Apache License

public ClassInventoryVisitor(Inventory inventory) {
    super(Opcodes.ASM5);
    this.inventory = inventory;
}

From source file:com.mebigfatguy.inventory.cls.MethodInventoryVisitor.java

License:Apache License

public MethodInventoryVisitor(String clsName, Inventory inventory) {
    super(Opcodes.ASM5);
    this.owningClass = clsName;
    this.inventory = inventory;
}

From source file:com.mebigfatguy.loc4j.LocClassVisitor.java

License:Apache License

public LocClassVisitor(Counts cnts) {
    super(Opcodes.ASM5);
    counts = cnts;
    mv.setCounts(cnts);

    counts.addClassCounts(1);
}

From source file:com.mebigfatguy.loc4j.LocMethodVisitor.java

License:Apache License

public LocMethodVisitor() {
    super(Opcodes.ASM5);
    lines = new HashSet<>();
}

From source file:com.mebigfatguy.stringliterals.SLClassVisitor.java

License:Apache License

public SLClassVisitor() {
    super(Opcodes.ASM5);
}

From source file:com.mebigfatguy.stringliterals.SLMethodVisitor.java

License:Apache License

public SLMethodVisitor() {
    super(Opcodes.ASM5);
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.DefaultClassVisitor.java

License:Open Source License

public DefaultClassVisitor(ClassInstrumentationData instrumentationData, ClassWriter classWriter) {
    super(Opcodes.ASM5, classWriter);

    this.instrumentationData = instrumentationData;
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.PreparedStatementClassVisitor.java

License:Open Source License

public PreparedStatementClassVisitor(ClassInstrumentationData instrumentationData, ClassWriter classWriter,
        PreparedStatementMetaData metaData) {
    super(Opcodes.ASM5, classWriter);

    this.instrumentationData = instrumentationData;
    this.metaData = metaData;

    nameAndSignature.put("setBoolean", "(IZ)V");
    nameAndSignature.put("setInt", "(II)V");
    nameAndSignature.put("setShort", "(IS)V");
    nameAndSignature.put("setDouble", "(ID)V");
    nameAndSignature.put("setFloat", "(IF)V");
    nameAndSignature.put("setString", "(ILjava/lang/String;)V");

    nameAndSignature.put("setBigDecimal", "(ILjava/math/BigDecimal;)V");

    nameAndSignature.put("setObject", "(ILjava/lang/Object;)V");
    nameAndSignature.put("setTimestamp", "(ILjava/sql/Timestamp;)V");
    nameAndSignature.put("setTimestamp", "(ILjava/sql/Timestamp;Ljava/util/Calendar)V");
    nameAndSignature.put("setTime", "(ILjava/sql/Time;)V");
    nameAndSignature.put("setDate", "(ILjava/sql/Date;)V");

    nameAndSignature.put("setBlob", "(ILjava/sql/Blob;)V");

    nameAndSignature.put("setNull", "(II)V");
    /*/*  ww w .  j  av  a 2  s .  c  o m*/
          */
}

From source file:com.mogujie.instantrun.IncrementalVisitor.java

License:Apache License

public IncrementalVisitor(ClassNode classNode, List<ClassNode> parentNodes, ClassVisitor classVisitor) {
    super(Opcodes.ASM5, classVisitor);
    this.classNode = classNode;
    this.parentNodes = parentNodes;
    Log.v(getClass().getSimpleName() + ": Visiting " + classNode.name);
}

From source file:com.mogujie.instantrun.IncrementalVisitor.java

License:Apache License

public static boolean instrumentClass(ZipEntry entry, ZipFile zipFile, ZipOutputStream zos,
        VisitorBuilder visitorBuilder, boolean isHotfix) throws IOException {
    byte[] classBytes = FileUtils.toByteArray(zipFile.getInputStream(entry));
    ClassReader classReader = new ClassReader(classBytes);
    // override the getCommonSuperClass to use the thread context class loader instead of
    // the system classloader. This is useful as ASM needs to load classes from the project
    // which the system classloader does not have visibility upon.
    // TODO: investigate if there is not a simpler way than overriding.
    ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES) {
        @Override/*  w ww  .j  a va  2  s.c o  m*/
        protected String getCommonSuperClass(final String type1, final String type2) {
            Class<?> c, d;
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            try {
                c = Class.forName(type1.replace('/', '.'), false, classLoader);
                d = Class.forName(type2.replace('/', '.'), false, classLoader);
            } catch (ClassNotFoundException e) {
                // This may happen if we're processing class files which reference APIs not
                // available on the target device. In this case return a dummy value, since this
                // is ignored during dx compilation.
                return "instant/run/NoCommonSuperClass";
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (c.isAssignableFrom(d)) {
                return type1;
            }
            if (d.isAssignableFrom(c)) {
                return type2;
            }
            if (c.isInterface() || d.isInterface()) {
                return "java/lang/Object";
            } else {
                do {
                    c = c.getSuperclass();
                } while (!c.isAssignableFrom(d));
                return c.getName().replace('.', '/');
            }
        }
    };

    ClassNode classNode = new TransformAccessClassNode();
    classReader.accept(classNode, ClassReader.EXPAND_FRAMES);

    // when dealing with interface, we just copy the inputFile over without any changes unless
    // this is a package private interface.
    AccessRight accessRight = AccessRight.fromNodeAccess(classNode.access);
    ZipEntry nowEntry;
    if (isHotfix) {
        String name = entry.getName();
        name = name.substring(0, name.lastIndexOf(".class"));
        nowEntry = new ZipEntry(name + "$override" + ".class");
    } else {
        nowEntry = new ZipEntry(entry.getName());
    }

    if ((classNode.access & Opcodes.ACC_INTERFACE) != 0) {
        if (visitorBuilder.getOutputType() == OutputType.INSTRUMENT) {
            // don't change the name of interfaces.
            zos.putNextEntry(nowEntry);
            if (accessRight == AccessRight.PACKAGE_PRIVATE) {
                classNode.access = classNode.access | Opcodes.ACC_PUBLIC;
                classNode.accept(classWriter);
                zos.write(classWriter.toByteArray());
            } else {
                // just copy the input file over, no change.
                zos.write(classBytes);
            }
            zos.closeEntry();
            return true;
        } else {
            return false;
        }
    }

    List<ClassNode> parentsNodes = parseParents(zipFile, classNode);

    IncrementalVisitor visitor = visitorBuilder.build(classNode, parentsNodes, classWriter);
    classNode.accept(visitor);

    zos.putNextEntry(nowEntry);
    zos.write(classWriter.toByteArray());
    zos.closeEntry();

    if (isHotfix) {
        IncrementalChangeVisitor changeVisitor = (IncrementalChangeVisitor) visitor;
        if (changeVisitor.superMethods.size() > 0) {
            if (parentsNodes.size() <= 0) {
                throw new GradleException("not found " + changeVisitor.visitedClassName + " 's parents.");
            }
            SuperHelperVisitor superHelperVisitor = new SuperHelperVisitor(Opcodes.ASM5, changeVisitor,
                    parentsNodes.get(0));
            superHelperVisitor.start();
            String newName = entry.getName();
            newName = newName.substring(0, newName.lastIndexOf(".class"));
            newName += "$helper.class";
            ZipEntry zipEntry = new ZipEntry(newName);
            zos.putNextEntry(zipEntry);
            zos.write(superHelperVisitor.toByteArray());
            zos.closeEntry();
        }

    }
    return true;
}