Refactor KotlinJvmBinaryClass, VirtualFileKotlinClass, etc.

VirtualFileKotlinClass now reads its header and name on creation. This is not
lazy enough and may be slower in some circumstances, but has the following
advantage: if anything is wrong in the header, a VirtualFileKotlinClass
instance will not be created at all, making it nearly impossible for the client
code to operate on invalid data causing all kinds of exceptions
This commit is contained in:
Alexander Udalov
2014-03-12 20:41:49 +04:00
parent 9bf0d014d5
commit 307f52895a
13 changed files with 78 additions and 104 deletions
@@ -75,8 +75,8 @@ fun LazyJavaResolverContext.findClassInJava(fqName: FqName): JavaClassLookupResu
}
val kotlinClass = kotlinClassFinder.findKotlinClass(fqName)
val header = kotlinClass?.getClassHeader()
if (kotlinClass != null && header != null) {
if (kotlinClass != null) {
val header = kotlinClass.getClassHeader()
if (header.kind == KotlinClassHeader.Kind.CLASS) {
val descriptor = packageFragmentProvider.resolveKotlinBinaryClass(kotlinClass)
if (descriptor != null) {
@@ -117,8 +117,6 @@ public final class DeserializedDescriptorResolver {
@Nullable
private String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @NotNull KotlinClassHeader.Kind expectedKind) {
KotlinClassHeader header = kotlinClass.getClassHeader();
if (header == null) return null;
if (header.getKind() == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
errorReporter.reportIncompatibleAbiVersion(kotlinClass, header.getVersion());
}
@@ -30,7 +30,7 @@ public interface KotlinJvmBinaryClass {
void visitMembers(@NotNull MemberVisitor visitor);
@Nullable
@NotNull
KotlinClassHeader getClassHeader();
interface MemberVisitor {
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -53,16 +52,6 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
private KotlinClassHeader.Kind headerKind = null;
private KotlinSyntheticClass.Kind syntheticClassKind = null;
private ReadKotlinClassHeaderAnnotationVisitor() {
}
@Nullable
public static KotlinClassHeader read(@NotNull KotlinJvmBinaryClass kotlinClass) {
ReadKotlinClassHeaderAnnotationVisitor visitor = new ReadKotlinClassHeaderAnnotationVisitor();
kotlinClass.loadClassAnnotations(visitor);
return visitor.createHeader();
}
@Nullable
public KotlinClassHeader createHeader() {
if (headerKind == null) {