Java Code Examples for org.objectweb.asm.ClassReader#SKIP_FRAMES

The following examples show how to use org.objectweb.asm.ClassReader#SKIP_FRAMES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassEntry.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Adds in all the super classes found for the given class entries into the given map */
private static void addSuperClasses(
        @NonNull LintClient client,
        @NonNull SuperclassVisitor visitor,
        @NonNull List<ClassEntry> entries) {
    for (ClassEntry entry : entries) {
        try {
            ClassReader reader = new ClassReader(entry.bytes);
            int flags = ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG
                    | ClassReader.SKIP_FRAMES;
            reader.accept(visitor, flags);
        } catch (Throwable t) {
            client.log(null, "Error processing %1$s: broken class file?", entry.path());
        }
    }
}
 
Example 2
Source File: DirectoryReader.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void visitClass(Path relativePath, ClassVisitor cv, boolean skipCode) throws IOException {
  if (!isClass(relativePath)) {
    throw new IllegalArgumentException();
  }

  int parsingOptions = ClassReader.SKIP_FRAMES;
  if (skipCode) {
    parsingOptions |= ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE;
  }

  try (InputStream inputStream = openInputStream(relativePath)) {
    ClassReader reader = new ClassReader(inputStream);
    reader.accept(cv, parsingOptions);
  }
}
 
Example 3
Source File: Instrumentator.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the raw bytes of instrumented class with name {@code className}
 *
 * @param classLoader
 * @param className
 * @param reader
 * @return
 */
public byte[] transformBytes(ClassLoader classLoader, ClassName className, ClassReader reader) {
    Objects.requireNonNull(classLoader);
    Objects.requireNonNull(className);
    Objects.requireNonNull(reader);

    if (!canInstrumentForCoverage(className)) {
        throw new IllegalArgumentException("Cannot instrument " + className);
    }


    int asmFlags = ClassWriter.COMPUTE_FRAMES;
    ClassWriter writer = new ComputeClassWriter(asmFlags);
    ClassVisitor cv = writer;

    //this is very we hook our instrumentation
    cv = new CoverageClassVisitor(cv, className);

    //avoid reading frames, as we re-compute them
    int readFlags = ClassReader.SKIP_FRAMES;

    /*
        This is using the "Visitor Pattern".
        In a nutshell, we scan the whole class definition, and at each
        element we "print" in the "writer" buffer.
        On such buffer we also add our instrumentation.
        Then, once we are done traversing the "reader", we convert
        the buffer in the "writer" into byte[] data
     */
    reader.accept(cv, readFlags);

    return writer.toByteArray();
}
 
Example 4
Source File: Instrumentator.java    From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the raw bytes of instrumented class with name {@code className}
 *
 * @param classLoader
 * @param className
 * @param reader
 * @return
 */
public byte[] transformBytes(ClassLoader classLoader, ClassName className, ClassReader reader) {
    Objects.requireNonNull(classLoader);
    Objects.requireNonNull(className);
    Objects.requireNonNull(reader);

    if (!canInstrumentForCoverage(className)) {
        throw new IllegalArgumentException("Cannot instrument " + className);
    }


    int asmFlags = ClassWriter.COMPUTE_FRAMES;
    ClassWriter writer = new ComputeClassWriter(asmFlags);
    ClassVisitor cv = writer;

    //this is very we hook our instrumentation
    cv = new CoverageClassVisitor(cv, className);

    //avoid reading frames, as we re-compute them
    int readFlags = ClassReader.SKIP_FRAMES;

    /*
        This is using the "Visitor Pattern".
        In a nutshell, we scan the whole class definition, and at each
        element we "print" in the "writer" buffer.
        On such buffer we also add our instrumentation.
        Then, once we are done traversing the "reader", we convert
        the buffer in the "writer" into byte[] data
     */
    reader.accept(cv, readFlags);

    return writer.toByteArray();
}