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:org.apache.flink.runtime.util.DependencyVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (signature == null) {
        addMethodDesc(desc);/*from   ww w  .  ja v a 2  s  .  c  om*/
    } else {
        addSignature(signature);
    }
    addInternalNames(exceptions);
    return new MethodVisitorImpl(Opcodes.ASM5);
}

From source file:org.apache.flink.runtime.util.DependencyVisitor.java

License:Apache License

private void addSignature(String signature) {
    if (signature != null) {
        new SignatureReader(signature).accept(new SignatureVisitorImpl(Opcodes.ASM5));
    }/*from   w w w.  ja va  2s .com*/
}

From source file:org.apache.flink.runtime.util.DependencyVisitor.java

License:Apache License

private void addTypeSignature(String signature) {
    if (signature != null) {
        new SignatureReader(signature).acceptType(new SignatureVisitorImpl(Opcodes.ASM5));
    }/*w  w  w.jav  a2s.  c om*/
}

From source file:org.apache.flink.runtime.util.JarFileCreator.java

License:Apache License

/**
 * Add the dependencies within the given packages automatically.
 * @throws IOException//from w  w  w  .  j  a  va2 s  .c o  m
 *          throw if an error occurs while read the class file.
 */
private synchronized void addDependencies() throws IOException {
    List<String> dependencies = new ArrayList<String>();
    for (Class clazz : classSet) {
        dependencies.add(clazz.getName());
    }
    //Traverse the dependency tree using BFS.
    int head = 0;
    while (head != dependencies.size()) {
        DependencyVisitor v = new DependencyVisitor(Opcodes.ASM5);
        v.addNameSpace(this.packages);
        InputStream classInputStream = null;
        String name = dependencies.get(head);
        try {
            Class clazz = Class.forName(name);
            int n = name.lastIndexOf('.');
            String className = null;
            if (n > -1) {
                className = name.substring(n + 1, name.length());
            }
            classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
        new ClassReader(classInputStream).accept(v, 0);
        classInputStream.close();

        //Update the BFS queue.
        Set<String> classPackages = v.getPackages();
        for (String s : classPackages) {
            if (!dependencies.contains(s.replace('/', '.'))) {
                dependencies.add(s.replace('/', '.'));
            }
        }
        head++;
    }

    for (String dependency : dependencies) {
        try {
            this.classSet.add(Class.forName(dependency));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

From source file:org.apache.maven.shared.dependency.analyzer.asm.LocalClassVisitor.java

License:Apache License

public LocalClassVisitor(SignatureVisitor signatureVisitor, AnnotationVisitor annotationVisitor,
        FieldVisitor fieldVisitor, MethodVisitor methodVisitor, ResultCollector resultCollector) {
    super(Opcodes.ASM5);
    this.signatureVisitor = signatureVisitor;
    this.annotationVisitor = annotationVisitor;
    this.fieldVisitor = fieldVisitor;
    this.methodVisitor = methodVisitor;
    this.resultCollector = resultCollector;
}

From source file:org.apache.orc.DependencyVisitor.java

License:Apache License

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

From source file:org.blockartistry.mod.DynSurround.world.WorldProviderWeatherHandle.java

License:MIT License

public WorldProviderWeatherHandle(final World world, final WorldProvider provider) {
    super(world, provider);

    if (provider.getClass() == WorldProviderSurface.class)
        return;//from   w  w w .  j av  a2  s. c o m

    ModLog.info("Processing inspection on world provider class %s for compat", provider.getClass().getName());

    try {
        ModClassLoader modClassLoader = Loader.instance().getModClassLoader();
        Field mainLoaderField = modClassLoader.getClass().getDeclaredField("mainClassLoader");
        mainLoaderField.setAccessible(true);
        LaunchClassLoader classLoader = (LaunchClassLoader) mainLoaderField.get(modClassLoader);

        new ClassReader(classLoader.getClassBytes(provider.getClass().getName()))
                .accept(new ClassVisitor(Opcodes.ASM5) {
                    @Override
                    public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                            String[] exceptions) {
                        if (name.equals("updateWeather")) {
                            ModLog.info(
                                    "Visiting method %s with description %s named updateWeather() on WorldProvider",
                                    name, desc);

                            patchWeather = false;

                            return new MethodVisitor(Opcodes.ASM5) {
                                boolean isTheMethod = true;

                                @Override
                                public void visitParameter(String name, int access) {
                                    this.isTheMethod = false;
                                }

                                @Override
                                public void visitMethodInsn(int opcode, String owner, String name, String desc,
                                        boolean itf) {
                                    if (!this.isTheMethod)
                                        return;

                                    ModLog.info(
                                            "Visiting method call %s with description %s during inspection on WorldProvider#updateWeather(), for compat",
                                            name, desc);

                                    try {
                                        if (name.equals("updateWeatherBody")
                                                && desc.equals(Type.getMethodDescriptor(
                                                        World.class.getMethod("updateWeatherBody")))) {
                                            patchWeather = true;
                                            ModLog.info(
                                                    "Found World#updateWeatherBody() from WorldProvider#updateWeather()");
                                        } else if (name.equals("updateWeather")
                                                && desc.equals(Type.getMethodDescriptor(
                                                        WorldProvider.class.getMethod("updateWeather")))) {
                                            patchWeather = true;
                                            ModLog.info(
                                                    "Found WorldProvider#updateWeather() from WorldProvider#updateWeather()");
                                        }
                                    } catch (NoSuchMethodException exc) {
                                        Throwables.propagate(exc);
                                    }
                                }
                            };
                        }
                        return null;
                    }
                }, 0);
    } catch (IOException exc) {
        Throwables.propagate(exc);
    } catch (ReflectiveOperationException exc) {
        Throwables.propagate(exc);
    }
}

From source file:org.chromium.bytecode.AssertionEnablerClassAdapter.java

License:Open Source License

AssertionEnablerClassAdapter(ClassVisitor visitor) {
    super(Opcodes.ASM5, visitor);
}

From source file:org.chromium.bytecode.AssertionEnablerClassAdapter.java

License:Open Source License

@Override
public MethodVisitor visitMethod(final int access, final String name, String desc, String signature,
        String[] exceptions) {//  w  w w  . j  av  a2s  .co m
    return new RewriteAssertMethodVisitor(Opcodes.ASM5,
            super.visitMethod(access, name, desc, signature, exceptions));
}

From source file:org.codehaus.mojo.animal_sniffer.ClassListBuilder.java

License:Open Source License

protected void process(String name, InputStream image) throws IOException {
    try {//  w ww.  j  ava  2s  . co  m
        ClassReader cr = new ClassReader(image);
        cr.accept(new ClassVisitor(Opcodes.ASM5) {
            public void visit(int version, int access, String name, String signature, String superName,
                    String[] interfaces) {
                packages.add(name.replace('/', '.'));
            }
        }, 0);
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.error("Bad class file " + name);
        // MANIMALSNIFFER-9 it is a pity that ASM does not throw a nicer error on encountering a malformed
        // class file.
        IOException ioException = new IOException("Bad class file " + name);
        ioException.initCause(e);
        throw ioException;
    }
}