Search in sources :

Example 11 with ClassVisitor

use of org.jetbrains.org.objectweb.asm.ClassVisitor in project intellij-community by JetBrains.

the class DefaultOutputConsumer method readClassName.

private static String readClassName(byte[] classBytes) throws IOException {
    final Ref<String> nameRef = Ref.create(null);
    new ClassReader(classBytes).accept(new ClassVisitor(Opcodes.API_VERSION) {

        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            nameRef.set(name.replace('/', '.'));
        }
    }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    return nameRef.get();
}
Also used : ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor)

Example 12 with ClassVisitor

use of org.jetbrains.org.objectweb.asm.ClassVisitor in project kotlin by JetBrains.

the class InnerClassInfoGenTest method extractInnerClasses.

@NotNull
private List<InnerClassAttribute> extractInnerClasses(@NotNull String className) {
    OutputFile outputFile = generateClassesInFile().get(className + ".class");
    assertNotNull(outputFile);
    byte[] bytes = outputFile.asByteArray();
    ClassReader reader = new ClassReader(bytes);
    final List<InnerClassAttribute> result = new ArrayList<InnerClassAttribute>();
    reader.accept(new ClassVisitor(ASM5) {

        @Override
        public void visitInnerClass(@NotNull String name, String outerName, String innerName, int access) {
            result.add(new InnerClassAttribute(name, outerName, innerName, access));
        }
    }, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
    return result;
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) ArrayList(java.util.ArrayList) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ClassVisitor

use of org.jetbrains.org.objectweb.asm.ClassVisitor in project kotlin by JetBrains.

the class OuterClassGenTest method readOuterClassInfo.

@Nullable
private static OuterClassInfo readOuterClassInfo(@NotNull ClassReader reader) {
    final Ref<OuterClassInfo> info = Ref.create();
    reader.accept(new ClassVisitor(Opcodes.ASM5) {

        @Override
        public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) {
            info.set(new OuterClassInfo(owner, name, desc));
        }
    }, 0);
    return info.get();
}
Also used : ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with ClassVisitor

use of org.jetbrains.org.objectweb.asm.ClassVisitor in project kotlin by JetBrains.

the class SourceInfoGenTest method getProducerInfo.

private String getProducerInfo(String name) {
    OutputFile file = generateClassesInFile().get(name);
    assertNotNull(file);
    ClassReader classReader = new ClassReader(file.asByteArray());
    final String[] producer = new String[1];
    classReader.accept(new ClassVisitor(Opcodes.ASM5) {

        @Override
        public void visitSource(String source, String debug) {
            producer[0] = source;
        }
    }, 0);
    return producer[0];
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor)

Aggregations

ClassVisitor (org.jetbrains.org.objectweb.asm.ClassVisitor)14 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)12 OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)3 ReadKotlinClassHeaderAnnotationVisitor (org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor)3 ClassWriter (org.jetbrains.org.objectweb.asm.ClassWriter)3 Ref (com.intellij.openapi.util.Ref)2 File (java.io.File)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)2 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 NotNull (org.jetbrains.annotations.NotNull)1 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)1 KotlinClassHeader (org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader)1 ClassId (org.jetbrains.kotlin.name.ClassId)1 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)1 FieldVisitor (org.jetbrains.org.objectweb.asm.FieldVisitor)1