Search in sources :

Example 1 with KotlinClassHeader

use of org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader in project kotlin by JetBrains.

the class FileBasedKotlinClass method create.

// TODO public to be accessible in companion object of subclass, workaround for KT-3974
@Nullable
public static <T extends FileBasedKotlinClass> T create(@NotNull byte[] fileContents, @NotNull Function4<ClassId, Integer, KotlinClassHeader, InnerClassesInfo, T> factory) {
    final ReadKotlinClassHeaderAnnotationVisitor readHeaderVisitor = new ReadKotlinClassHeaderAnnotationVisitor();
    final Ref<String> classNameRef = Ref.create();
    final Ref<Integer> classVersion = Ref.create();
    final InnerClassesInfo innerClasses = new InnerClassesInfo();
    new ClassReader(fileContents).accept(new ClassVisitor(ASM5) {

        @Override
        public void visit(int version, int access, @NotNull String name, String signature, String superName, String[] interfaces) {
            classNameRef.set(name);
            classVersion.set(version);
        }

        @Override
        public void visitInnerClass(@NotNull String name, String outerName, String innerName, int access) {
            innerClasses.add(name, outerName, innerName);
        }

        @Override
        public org.jetbrains.org.objectweb.asm.AnnotationVisitor visitAnnotation(@NotNull String desc, boolean visible) {
            return convertAnnotationVisitor(readHeaderVisitor, desc, innerClasses);
        }

        @Override
        public void visitEnd() {
            readHeaderVisitor.visitEnd();
        }
    }, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
    String className = classNameRef.get();
    if (className == null)
        return null;
    KotlinClassHeader header = readHeaderVisitor.createHeader();
    if (header == null)
        return null;
    ClassId id = resolveNameByInternalName(className, innerClasses);
    return factory.invoke(id, classVersion.get(), header, innerClasses);
}
Also used : KotlinClassHeader(org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader) ClassId(org.jetbrains.kotlin.name.ClassId) ClassVisitor(org.jetbrains.org.objectweb.asm.ClassVisitor) ReadKotlinClassHeaderAnnotationVisitor(org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor) ReadKotlinClassHeaderAnnotationVisitor(org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)1 KotlinClassHeader (org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader)1 ReadKotlinClassHeaderAnnotationVisitor (org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor)1 ClassId (org.jetbrains.kotlin.name.ClassId)1 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)1 ClassVisitor (org.jetbrains.org.objectweb.asm.ClassVisitor)1