use of org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor 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);
}
Aggregations