KotlinJvmBinaryClass now has a getClassHeader() method
This commit is contained in:
+47
-16
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import jet.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.ClassReader;
|
||||
@@ -24,7 +26,11 @@ import org.jetbrains.asm4.ClassVisitor;
|
||||
import org.jetbrains.asm4.FieldVisitor;
|
||||
import org.jetbrains.asm4.MethodVisitor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.NullableLazyValue;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -34,10 +40,27 @@ import static org.jetbrains.asm4.Opcodes.ASM4;
|
||||
|
||||
public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
|
||||
private final VirtualFile file;
|
||||
private JvmClassName className;
|
||||
private final NotNullLazyValue<JvmClassName> className;
|
||||
private final NullableLazyValue<KotlinClassHeader> classHeader;
|
||||
|
||||
public VirtualFileKotlinClass(@NotNull VirtualFile file) {
|
||||
public VirtualFileKotlinClass(@NotNull StorageManager storageManager, @NotNull VirtualFile file) {
|
||||
this.file = file;
|
||||
this.className = storageManager.createLazyValue(
|
||||
new Function0<JvmClassName>() {
|
||||
@Override
|
||||
public JvmClassName invoke() {
|
||||
return computeClassName();
|
||||
}
|
||||
}
|
||||
);
|
||||
this.classHeader = storageManager.createNullableLazyValue(
|
||||
new Function0<KotlinClassHeader>() {
|
||||
@Override
|
||||
public KotlinClassHeader invoke() {
|
||||
return KotlinClassHeader.read(VirtualFileKotlinClass.this);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -45,24 +68,32 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JvmClassName computeClassName() {
|
||||
final Ref<JvmClassName> classNameRef = Ref.create();
|
||||
try {
|
||||
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM4) {
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
classNameRef.set(JvmClassName.byInternalName(name));
|
||||
}
|
||||
}, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
return classNameRef.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JvmClassName getClassName() {
|
||||
if (className == null) {
|
||||
try {
|
||||
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM4) {
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
className = JvmClassName.byInternalName(name);
|
||||
}
|
||||
}, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
return className.invoke();
|
||||
}
|
||||
|
||||
return className;
|
||||
@Override
|
||||
public KotlinClassHeader getClassHeader() {
|
||||
return classHeader.invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -21,6 +21,7 @@ import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
public abstract class VirtualFileKotlinClassFinder implements VirtualFileFinder {
|
||||
|
||||
@@ -29,7 +30,8 @@ public abstract class VirtualFileKotlinClassFinder implements VirtualFileFinder
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinJvmBinaryClass createValue(VirtualFile virtualFile) {
|
||||
return new VirtualFileKotlinClass(virtualFile);
|
||||
// Operations under this lock are not supposed to involve other locks
|
||||
return new VirtualFileKotlinClass(new LockBasedStorageManager(), virtualFile);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user