KotlinClassFileHeader is now nullable everywhere

'null' means there's no header. This makes all of KotlinClassFileHeader's
fields non-null
This commit is contained in:
Alexander Udalov
2013-09-19 18:50:07 +04:00
parent 9e9b3c7284
commit 92cc0ddd1f
7 changed files with 55 additions and 30 deletions
@@ -126,8 +126,11 @@ public final class DeserializedDescriptorResolver {
@Nullable
private String[] readData(@NotNull VirtualFile virtualFile) {
KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(virtualFile);
if (header == null) {
return null;
}
int version = header.getVersion();
if (!isAbiVersionCompatible(version) && header.getType() != null) {
if (!isAbiVersionCompatible(version)) {
errorReporter.reportIncompatibleAbiVersion(header.getFqName(), virtualFile, version);
return null;
}
@@ -23,12 +23,19 @@ import static org.jetbrains.jet.lang.resolve.java.AbiVersionUtil.isAbiVersionCom
public final class KotlinClassFileHeader {
private static final Logger LOG = Logger.getInstance(KotlinClassFileHeader.class);
@NotNull
@Nullable
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull VirtualFile virtualFile) {
try {
ClassReader reader = new ClassReader(virtualFile.contentsToByteArray());
ReadDataFromAnnotationVisitor visitor = new ReadDataFromAnnotationVisitor();
reader.accept(visitor, SKIP_CODE | SKIP_FRAMES | SKIP_DEBUG);
if (visitor.type == null) {
return null;
}
if (visitor.fqName == null) {
LOG.error("File doesn't have a class name: " + virtualFile);
return null;
}
return new KotlinClassFileHeader(visitor.version, visitor.annotationData, visitor.type, visitor.fqName);
}
catch (IOException e) {
@@ -70,14 +77,11 @@ public final class KotlinClassFileHeader {
}
private final int version;
@Nullable
private final String[] annotationData;
@Nullable
private final HeaderType type;
@Nullable
private final FqName fqName;
private KotlinClassFileHeader(int version, @Nullable String[] annotationData, @Nullable HeaderType type, @Nullable FqName fqName) {
private KotlinClassFileHeader(int version, @Nullable String[] annotationData, @NotNull HeaderType type, @NotNull FqName fqName) {
this.version = version;
this.annotationData = annotationData;
this.type = type;
@@ -89,15 +93,17 @@ public final class KotlinClassFileHeader {
}
@Nullable
public HeaderType getType() {
return type;
public String[] getAnnotationData() {
if (isCompatibleKotlinCompiledFile() && annotationData == null) {
LOG.error("Kotlin annotation " + type + " is incorrect for class: " + fqName);
return null;
}
return annotationData;
}
/**
* @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 type != null && type.isValidAnnotation() && isAbiVersionCompatible(version);
@NotNull
public HeaderType getType() {
return type;
}
/**
@@ -105,16 +111,14 @@ public final class KotlinClassFileHeader {
*/
@NotNull
public FqName getFqName() {
assert fqName != null;
return fqName;
}
@Nullable
public String[] getAnnotationData() {
if (annotationData == null && type != null) {
LOG.error("Data for annotations " + type.correspondingAnnotation + " was not read.");
}
return annotationData;
/**
* @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 type.isValidAnnotation() && isAbiVersionCompatible(version);
}
private static class ReadDataFromAnnotationVisitor extends ClassVisitor {