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.costlowcorp.eriktools.wardetails.WarScanner.java

private void readJar(String name, ZipInputStream zis) throws IOException {
    final String nameLower = name.toLowerCase();
    if (nameLower.endsWith(".class")) {
        final byte[] classBytes = readBytes(zis);
        final ClassReader reader = new ClassReader(classBytes);
        final ClassFileMetaVisitor v = new ClassFileMetaVisitor(Opcodes.ASM5, null);
        reader.accept(v, ClassReader.SKIP_CODE);
        if (v.getName().contains("/")) {
            final String currentPackage = v.getName().substring(0, v.getName().lastIndexOf('/'));
            System.out.println("  Name: " + name + " __package__ " + currentPackage);
        }//ww w. j av  a 2s.co  m
    } else if (nameLower.endsWith(".jar") || nameLower.endsWith(".war")) {
        try (InputStream in = new NestedInputStream(zis); ZipInputStream zin2 = new ZipInputStream(in)) {
            for (ZipEntry entry = zin2.getNextEntry(); entry != null; entry = zin2.getNextEntry()) {
                final String entryName = entry.getName();
                readJar(name + " -> " + entryName, zin2);
            }
        }
    }
}

From source file:com.datastax.driver.mapping.SyntheticFieldsMapperTest.java

License:Apache License

private Class<?> makeTestClassWithSyntheticFields() {
    InputStream stream = null;/*from   w  ww  . j  a  v  a 2 s . com*/
    try {
        // Get class bytes
        Class<ClassWithSyntheticField> c = ClassWithSyntheticField.class;
        String classAsPath = c.getName().replace('.', '/') + ".class";
        stream = c.getClassLoader().getResourceAsStream(classAsPath);

        // Make "futureSynthetic" field actually synthetic
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new SyntheticFieldCreator(Opcodes.ASM5, cw);
        ClassReader cr = new ClassReader(stream);
        cr.accept(cv, 0);
        byte[] updatedClassBytes = cw.toByteArray();

        // Build the new class
        return new InterceptingClassLoader().defineClass(ClassWithSyntheticField.class.getName(),
                updatedClassBytes);
    } catch (IOException e) {
        throw new RuntimeException("Could not read Class bytes", e);
    } finally {
        try {
            Closeables.close(stream, true);
        } catch (IOException ignored) {
        }
    }
}

From source file:com.develorium.metracer.asm.MetracerClassVisitor.java

License:Apache License

public MetracerClassVisitor(ClassVisitor theClassVisitor, ClassLoader theLoader, Patterns thePatterns,
        ClassNode theParsedClass) {//from ww w . j a v  a  2  s.co m
    super(Opcodes.ASM5, theClassVisitor);
    loader = theLoader;
    patterns = thePatterns;
    parsedClass = theParsedClass;
}

From source file:com.diffplug.gradle.autosgi.PluginMetadataGen.java

License:Apache License

/** Loads a class by its FQN.  If it's concrete and implements a plugin, then we'll call generatePlugin. */
private void maybeGeneratePlugin(Path path)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    ClassReader reader = new ClassReader(Files.readAllBytes(path));
    String plugClassName = asmToJava(reader.getClassName());
    Box.Nullable<String> socketClassName = Box.Nullable.ofNull();
    reader.accept(new ClassVisitor(Opcodes.ASM5) {
        @Override//  w w w. ja  v a  2  s .  c o m
        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
            if (PLUG.equals(desc)) {
                return new AnnotationVisitor(Opcodes.ASM5) {
                    @Override
                    public void visit(String name, Object value) {
                        Preconditions.checkArgument(name.equals("value"),
                                "For @Plug %s, expected 'value' but was '%s'", plugClassName, name);
                        Preconditions.checkArgument(socketClassName.get() == null,
                                "For @Plug %s, multiple annotations: '%s' and '%s'", plugClassName,
                                socketClassName.get(), value);
                        socketClassName.set(((org.objectweb.asm.Type) value).getClassName());
                    }
                };
            } else {
                return null;
            }
        }
    }, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE);
    if (socketClassName.get() == null) {
        return;
    }

    Class<?> plugClass = classLoader.loadClass(plugClassName);
    Class<?> socketClass = classLoader.loadClass(socketClassName.get());
    if (Modifier.isAbstract(plugClass.getModifiers())) {
        throw new IllegalArgumentException(
                "Class " + plugClass + " has @Plug(" + socketClass + ") but it is abstract.");
    }

    String osgiInfContent = generatePlugin(plugClass, socketClass);
    osgiInf.put(plugClass.getName(), osgiInfContent);
}

From source file:com.dragome.callbackevictor.serverside.bytecode.transformation.asm.ContinuationClassAdapter.java

License:Apache License

public ContinuationClassAdapter(final ClassVisitor cv) {
    super(Opcodes.ASM5, cv);
}

From source file:com.dragome.callbackevictor.serverside.bytecode.transformation.asm.ContinuationMethodAdapter.java

License:Apache License

public ContinuationMethodAdapter(ContinuationMethodAnalyzer a) {
    super(Opcodes.ASM5, a.mv);
    this.canalyzer = a;
    this.analyzer = a.analyzer;
    this.labels = a.labels;
    this.nodes = a.nodes;
    this.stackRecorderVar = a.stackRecorderVar;
    this.isStatic = (a.access & ACC_STATIC) > 0;
    this.methodDesc = a.desc;

}

From source file:com.dragome.callbackevictor.serverside.bytecode.transformation.asm.ContinuationMethodAnalyzer.java

License:Apache License

public ContinuationMethodAnalyzer(String className, ClassVisitor cv, MethodVisitor mv, int access, String name,
        String desc, String signature, String[] exceptions, ClassLoader loader) {
    super(Opcodes.ASM5, access, name, desc, signature, exceptions);
    this.className = className;
    this.cv = cv;
    this.mv = mv;
    _useLoader = loader;/* w  w w.j a  v  a  2s  .  c  o  m*/

    //RS:
    this._variables = new ArrayList();
    _continueReflection = false;
}

From source file:com.dragome.compiler.invokedynamic.InvokeDynamicBackporter.java

License:Open Source License

public static byte[] transform(byte[] bytecode) {
    ClassNode classNode = new ClassNode(Opcodes.ASM5);
    InvokeDynamicConverter invokeDynamicConverter = new InvokeDynamicConverter(classNode);
    new ClassReader(bytecode).accept(invokeDynamicConverter, 0);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);//from   w  ww  . j a v  a 2  s. com
    return cw.toByteArray();
}

From source file:com.dragome.methodlogger.serverside.MethodLoggerAdapter.java

License:Apache License

public MethodLoggerAdapter(ClassVisitor cv) {
    super(Opcodes.ASM5, cv);
}

From source file:com.dragome.methodlogger.serverside.MethodLoggerAdapter.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv;//w w w.ja va 2 s . com
    mv = cv.visitMethod(access, name, desc, signature, exceptions);
    mv = new MethodReturnAdapter(Opcodes.ASM5, className, access, name, desc, mv);
    return mv;
}