Search in sources :

Example 96 with ClassReader

use of org.objectweb.asm.ClassReader in project bazel by bazelbuild.

the class JavacTurbine method processBytecode.

/**
   * Remove code attributes and private members.
   *
   * <p>Most code will already have been removed after parsing, but the bytecode will still contain
   * e.g. lowered class and instance initializers.
   */
private static byte[] processBytecode(byte[] bytes) {
    ClassWriter cw = new ClassWriter(0);
    new ClassReader(bytes).accept(new PrivateMemberPruner(cw), ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
    return cw.toByteArray();
}
Also used : ClassReader(org.objectweb.asm.ClassReader) ClassWriter(org.objectweb.asm.ClassWriter)

Example 97 with ClassReader

use of org.objectweb.asm.ClassReader in project auto by google.

the class AbstractMethodLister method abstractNoArgMethodsX.

private ImmutableList<String> abstractNoArgMethodsX() throws IOException {
    ClassReader classReader = new ClassReader(inputStream);
    RecordingClassVisitor classVisitor = new RecordingClassVisitor();
    classReader.accept(classVisitor, 0);
    return classVisitor.abstractNoArgMethods.build();
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Example 98 with ClassReader

use of org.objectweb.asm.ClassReader in project gradle by gradle.

the class AbstractTestFrameworkDetector method classVisitor.

protected TestClassVisitor classVisitor(final File testClassFile) {
    final TestClassVisitor classVisitor = createClassVisitor();
    InputStream classStream = null;
    try {
        classStream = new BufferedInputStream(new FileInputStream(testClassFile));
        final ClassReader classReader = new Java9ClassReader(IOUtils.toByteArray(classStream));
        classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
    } catch (Throwable e) {
        throw new GradleException("failed to read class file " + testClassFile.getAbsolutePath(), e);
    } finally {
        IOUtils.closeQuietly(classStream);
    }
    return classVisitor;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GradleException(org.gradle.api.GradleException) ClassReader(org.objectweb.asm.ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) FileInputStream(java.io.FileInputStream)

Example 99 with ClassReader

use of org.objectweb.asm.ClassReader in project gradle by gradle.

the class MixInLegacyTypesClassLoader method transform.

@Override
protected byte[] transform(String className, byte[] bytes) {
    ClassReader classReader = new Java9ClassReader(bytes);
    ClassWriter classWriter = new ClassWriter(0);
    classReader.accept(new TransformingAdapter(classWriter), 0);
    bytes = classWriter.toByteArray();
    return bytes;
}
Also used : ClassReader(org.objectweb.asm.ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) ClassWriter(org.objectweb.asm.ClassWriter)

Example 100 with ClassReader

use of org.objectweb.asm.ClassReader in project gradle by gradle.

the class ClassChangeProcessor method processChange.

public void processChange(final InputFileDetails input, final RecompilationSpec spec) {
    if (input.isRemoved()) {
        // this is a really heavyweight way of getting the dependencies of a file which was removed
        // hopefully this is not going to happen too often
        String className = previousCompilation.getClassName(input.getFile().getAbsolutePath());
        update(input, spec, className, Collections.<Integer>emptySet());
        return;
    }
    final ClassReader classReader;
    try {
        classReader = new Java9ClassReader(Files.toByteArray(input.getFile()));
        String className = classReader.getClassName().replaceAll("/", ".");
        Set<Integer> constants = ClassDependenciesVisitor.retrieveConstants(classReader);
        update(input, spec, className, constants);
    } catch (IOException e) {
        throw new IllegalArgumentException(String.format("Unable to read class file: '%s'", input.getFile()));
    }
}
Also used : ClassReader(org.objectweb.asm.ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) Java9ClassReader(org.gradle.util.internal.Java9ClassReader) IOException(java.io.IOException)

Aggregations

ClassReader (org.objectweb.asm.ClassReader)437 ClassWriter (org.objectweb.asm.ClassWriter)182 Test (org.junit.Test)134 IOException (java.io.IOException)77 InputStream (java.io.InputStream)75 TreeMap (java.util.TreeMap)59 ClassNode (org.objectweb.asm.tree.ClassNode)58 SemanticVersioningClassVisitor (org.apache.aries.versioning.utils.SemanticVersioningClassVisitor)53 ClassVisitor (org.objectweb.asm.ClassVisitor)48 HashSet (java.util.HashSet)39 ZipEntry (java.util.zip.ZipEntry)34 BinaryCompatibilityStatus (org.apache.aries.versioning.utils.BinaryCompatibilityStatus)32 ZipFile (java.util.zip.ZipFile)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)26 Method (java.lang.reflect.Method)25 OuterClass (com.android.tools.layoutlib.create.dataclass.OuterClass)23 InnerClass (com.android.tools.layoutlib.create.dataclass.OuterClass.InnerClass)23 PrintWriter (java.io.PrintWriter)23 MethodVisitor (org.objectweb.asm.MethodVisitor)23 MethodNode (org.objectweb.asm.tree.MethodNode)21