Remove KotlinClassFileHeader.HeaderType.NONE

Use null instead
This commit is contained in:
Alexander Udalov
2013-09-19 18:23:49 +04:00
parent b4d9fb75d8
commit e981681d3e
3 changed files with 14 additions and 15 deletions
@@ -20,7 +20,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.jvm.compiler.ClassPath;
import org.jetbrains.jet.lang.resolve.java.resolver.KotlinClassFileHeader; import org.jetbrains.jet.lang.resolve.java.resolver.KotlinClassFileHeader;
import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder; import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -80,7 +79,7 @@ public class CliVirtualFileFinder implements VirtualFileFinder {
return null; return null;
} }
//NOTE: currently we use VirtualFileFinder to find Kotlin binaries only //NOTE: currently we use VirtualFileFinder to find Kotlin binaries only
if (KotlinClassFileHeader.readKotlinHeaderFromClassFile(vFile).getType() != KotlinClassFileHeader.HeaderType.NONE) { if (KotlinClassFileHeader.readKotlinHeaderFromClassFile(vFile).getType() != null) {
return vFile; return vFile;
} }
} }
@@ -127,7 +127,7 @@ public final class DeserializedDescriptorResolver {
private String[] readData(@NotNull VirtualFile virtualFile) { private String[] readData(@NotNull VirtualFile virtualFile) {
KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(virtualFile); KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(virtualFile);
int version = header.getVersion(); int version = header.getVersion();
if (!isAbiVersionCompatible(version) && header.getType() != KotlinClassFileHeader.HeaderType.NONE) { if (!isAbiVersionCompatible(version) && header.getType() != null) {
errorReporter.reportIncompatibleAbiVersion(header.getFqName(), virtualFile, version); errorReporter.reportIncompatibleAbiVersion(header.getFqName(), virtualFile, version);
return null; return null;
} }
@@ -42,8 +42,7 @@ public final class KotlinClassFileHeader {
CLASS(JvmAnnotationNames.KOTLIN_CLASS), CLASS(JvmAnnotationNames.KOTLIN_CLASS),
PACKAGE(JvmAnnotationNames.KOTLIN_PACKAGE), PACKAGE(JvmAnnotationNames.KOTLIN_PACKAGE),
OLD_CLASS(JvmAnnotationNames.OLD_JET_CLASS_ANNOTATION), OLD_CLASS(JvmAnnotationNames.OLD_JET_CLASS_ANNOTATION),
OLD_PACKAGE(JvmAnnotationNames.OLD_JET_PACKAGE_CLASS_ANNOTATION), OLD_PACKAGE(JvmAnnotationNames.OLD_JET_PACKAGE_CLASS_ANNOTATION);
NONE(null);
@Nullable @Nullable
private final JvmClassName correspondingAnnotation; private final JvmClassName correspondingAnnotation;
@@ -56,7 +55,7 @@ public final class KotlinClassFileHeader {
return this == CLASS || this == PACKAGE; return this == CLASS || this == PACKAGE;
} }
@NotNull @Nullable
private static HeaderType byDescriptor(@NotNull String desc) { private static HeaderType byDescriptor(@NotNull String desc) {
for (HeaderType headerType : HeaderType.values()) { for (HeaderType headerType : HeaderType.values()) {
JvmClassName annotation = headerType.correspondingAnnotation; JvmClassName annotation = headerType.correspondingAnnotation;
@@ -67,7 +66,7 @@ public final class KotlinClassFileHeader {
return headerType; return headerType;
} }
} }
return NONE; return null;
} }
} }
@@ -75,8 +74,8 @@ public final class KotlinClassFileHeader {
@Nullable @Nullable
private String[] annotationData = null; private String[] annotationData = null;
@NotNull @Nullable
private HeaderType type = HeaderType.NONE; private HeaderType type = null;
@Nullable @Nullable
private JvmClassName jvmClassName = null; private JvmClassName jvmClassName = null;
@@ -84,7 +83,7 @@ public final class KotlinClassFileHeader {
return version; return version;
} }
@NotNull @Nullable
public HeaderType getType() { public HeaderType getType() {
return type; return type;
} }
@@ -93,7 +92,7 @@ public final class KotlinClassFileHeader {
* @return true if this is a header for compiled Kotlin file with correct abi version which can be processed by compiler or the IDE * @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() { public boolean isCompatibleKotlinCompiledFile() {
return type.isValidAnnotation() && isAbiVersionCompatible(version); return type != null && type.isValidAnnotation() && isAbiVersionCompatible(version);
} }
/** /**
@@ -107,7 +106,7 @@ public final class KotlinClassFileHeader {
@Nullable @Nullable
public String[] getAnnotationData() { public String[] getAnnotationData() {
if (annotationData == null && type != HeaderType.NONE) { if (annotationData == null && type != null) {
LOG.error("Data for annotations " + type.correspondingAnnotation + " was not read."); LOG.error("Data for annotations " + type.correspondingAnnotation + " was not read.");
} }
return annotationData; return annotationData;
@@ -127,14 +126,15 @@ public final class KotlinClassFileHeader {
@Override @Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
HeaderType headerTypeByAnnotation = HeaderType.byDescriptor(desc); HeaderType headerTypeByAnnotation = HeaderType.byDescriptor(desc);
if (headerTypeByAnnotation == HeaderType.NONE) { if (headerTypeByAnnotation == null) {
return null; return null;
} }
if (headerTypeByAnnotation.isValidAnnotation() && type.isValidAnnotation()) { boolean alreadyFoundValid = type != null && type.isValidAnnotation();
if (headerTypeByAnnotation.isValidAnnotation() && alreadyFoundValid) {
throw new IllegalStateException("Both " + type.correspondingAnnotation + " and " throw new IllegalStateException("Both " + type.correspondingAnnotation + " and "
+ headerTypeByAnnotation.correspondingAnnotation + " present!"); + headerTypeByAnnotation.correspondingAnnotation + " present!");
} }
if (!type.isValidAnnotation()) { if (!alreadyFoundValid) {
type = headerTypeByAnnotation; type = headerTypeByAnnotation;
} }
if (!headerTypeByAnnotation.isValidAnnotation()) { if (!headerTypeByAnnotation.isValidAnnotation()) {