SerializedDataHeader now always has valid annotationData
This helps to avoid errors of checking 'instanceof SerializedDataHeader' but forgetting to check if it 'isCompatibleKotlinCompiledFile'
This commit is contained in:
+2
-1
@@ -112,13 +112,14 @@ public final class DeserializedDescriptorResolver {
|
||||
@Nullable
|
||||
private String[] readData(@NotNull VirtualFile virtualFile) {
|
||||
KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(virtualFile);
|
||||
if (header instanceof SerializedDataHeader && header.isCompatibleKotlinCompiledFile()) {
|
||||
if (header instanceof SerializedDataHeader) {
|
||||
return ((SerializedDataHeader) header).getAnnotationData();
|
||||
}
|
||||
|
||||
if (header != null) {
|
||||
errorReporter.reportIncompatibleAbiVersion(header.getFqName(), virtualFile, header.getVersion());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -17,11 +17,10 @@
|
||||
package org.jetbrains.jet.lang.resolve.kotlin.header;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
public class OldAnnotationHeader extends KotlinClassFileHeader {
|
||||
protected OldAnnotationHeader(@NotNull FqName fqName) {
|
||||
super(AbiVersionUtil.INVALID_VERSION, fqName);
|
||||
public class IncompatibleAnnotationHeader extends KotlinClassFileHeader {
|
||||
protected IncompatibleAnnotationHeader(int version, @NotNull FqName fqName) {
|
||||
super(version, fqName);
|
||||
}
|
||||
}
|
||||
-8
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.jetbrains.asm4.ClassReader.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCompatible;
|
||||
|
||||
public abstract class KotlinClassFileHeader {
|
||||
@Nullable
|
||||
@@ -60,11 +59,4 @@ public abstract class KotlinClassFileHeader {
|
||||
public FqName getFqName() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this is a header for compiled Kotlin file with correct abi version which can be processed by compiler or the IDE
|
||||
*/
|
||||
public boolean isCompatibleKotlinCompiledFile() {
|
||||
return isAbiVersionCompatible(version);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-6
@@ -84,19 +84,29 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!AbiVersionUtil.isAbiVersionCompatible(version)) {
|
||||
return new IncompatibleAnnotationHeader(version, fqName);
|
||||
}
|
||||
|
||||
switch (foundType) {
|
||||
case CLASS:
|
||||
return SerializedDataHeader.create(version, annotationData, SerializedDataHeader.Kind.CLASS, fqName);
|
||||
return serializedDataHeader(SerializedDataHeader.Kind.CLASS, fqName);
|
||||
case PACKAGE:
|
||||
return SerializedDataHeader.create(version, annotationData, SerializedDataHeader.Kind.PACKAGE, fqName);
|
||||
case OLD_CLASS:
|
||||
case OLD_PACKAGE:
|
||||
return new OldAnnotationHeader(fqName);
|
||||
return serializedDataHeader(SerializedDataHeader.Kind.PACKAGE, fqName);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown HeaderType: " + foundType);
|
||||
throw new UnsupportedOperationException("Unknown compatible HeaderType: " + foundType);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private SerializedDataHeader serializedDataHeader(@NotNull SerializedDataHeader.Kind kind, @NotNull FqName fqName) {
|
||||
if (annotationData == null) {
|
||||
LOG.error("Kotlin annotation " + foundType + " is incorrect for class: " + fqName);
|
||||
return null;
|
||||
}
|
||||
return new SerializedDataHeader(version, annotationData, kind, fqName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
fqName = JvmClassName.byInternalName(name).getFqName();
|
||||
|
||||
+2
-17
@@ -16,16 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin.header;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCompatible;
|
||||
|
||||
public class SerializedDataHeader extends KotlinClassFileHeader {
|
||||
private static final Logger LOG = Logger.getInstance(SerializedDataHeader.class);
|
||||
|
||||
public enum Kind {
|
||||
CLASS,
|
||||
PACKAGE
|
||||
@@ -34,22 +28,13 @@ public class SerializedDataHeader extends KotlinClassFileHeader {
|
||||
private final String[] data;
|
||||
private final Kind kind;
|
||||
|
||||
private SerializedDataHeader(int version, @Nullable String[] annotationData, @NotNull Kind kind, @NotNull FqName fqName) {
|
||||
protected SerializedDataHeader(int version, @NotNull String[] annotationData, @NotNull Kind kind, @NotNull FqName fqName) {
|
||||
super(version, fqName);
|
||||
this.data = annotationData;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SerializedDataHeader create(int version, @Nullable String[] annotationData, @NotNull Kind kind, @NotNull FqName fqName) {
|
||||
if (isAbiVersionCompatible(version) && annotationData == null) {
|
||||
LOG.error("Kotlin annotation " + kind + " is incorrect for class: " + fqName);
|
||||
return null;
|
||||
}
|
||||
return new SerializedDataHeader(version, annotationData, kind, fqName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public String[] getAnnotationData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user