From e981681d3e320a6b31fe3359fcb8dcd823324a30 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 19 Sep 2013 18:23:49 +0400 Subject: [PATCH] Remove KotlinClassFileHeader.HeaderType.NONE Use null instead --- .../jvm/compiler/CliVirtualFileFinder.java | 3 +-- .../DeserializedDescriptorResolver.java | 2 +- .../java/resolver/KotlinClassFileHeader.java | 24 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliVirtualFileFinder.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliVirtualFileFinder.java index f6a34e58b0d..7be8112f25e 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliVirtualFileFinder.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliVirtualFileFinder.java @@ -20,7 +20,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; 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.vfilefinder.VirtualFileFinder; import org.jetbrains.jet.lang.resolve.name.FqName; @@ -80,7 +79,7 @@ public class CliVirtualFileFinder implements VirtualFileFinder { return null; } //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; } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/DeserializedDescriptorResolver.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/DeserializedDescriptorResolver.java index 70e291e686c..6258ffa260b 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/DeserializedDescriptorResolver.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/DeserializedDescriptorResolver.java @@ -127,7 +127,7 @@ public final class DeserializedDescriptorResolver { private String[] readData(@NotNull VirtualFile virtualFile) { KotlinClassFileHeader header = KotlinClassFileHeader.readKotlinHeaderFromClassFile(virtualFile); int version = header.getVersion(); - if (!isAbiVersionCompatible(version) && header.getType() != KotlinClassFileHeader.HeaderType.NONE) { + if (!isAbiVersionCompatible(version) && header.getType() != null) { errorReporter.reportIncompatibleAbiVersion(header.getFqName(), virtualFile, version); return null; } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/KotlinClassFileHeader.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/KotlinClassFileHeader.java index 9d7b4b52bbd..ad914072397 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/KotlinClassFileHeader.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/resolver/KotlinClassFileHeader.java @@ -42,8 +42,7 @@ public final class KotlinClassFileHeader { CLASS(JvmAnnotationNames.KOTLIN_CLASS), PACKAGE(JvmAnnotationNames.KOTLIN_PACKAGE), OLD_CLASS(JvmAnnotationNames.OLD_JET_CLASS_ANNOTATION), - OLD_PACKAGE(JvmAnnotationNames.OLD_JET_PACKAGE_CLASS_ANNOTATION), - NONE(null); + OLD_PACKAGE(JvmAnnotationNames.OLD_JET_PACKAGE_CLASS_ANNOTATION); @Nullable private final JvmClassName correspondingAnnotation; @@ -56,7 +55,7 @@ public final class KotlinClassFileHeader { return this == CLASS || this == PACKAGE; } - @NotNull + @Nullable private static HeaderType byDescriptor(@NotNull String desc) { for (HeaderType headerType : HeaderType.values()) { JvmClassName annotation = headerType.correspondingAnnotation; @@ -67,7 +66,7 @@ public final class KotlinClassFileHeader { return headerType; } } - return NONE; + return null; } } @@ -75,8 +74,8 @@ public final class KotlinClassFileHeader { @Nullable private String[] annotationData = null; - @NotNull - private HeaderType type = HeaderType.NONE; + @Nullable + private HeaderType type = null; @Nullable private JvmClassName jvmClassName = null; @@ -84,7 +83,7 @@ public final class KotlinClassFileHeader { return version; } - @NotNull + @Nullable public HeaderType getType() { 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 */ public boolean isCompatibleKotlinCompiledFile() { - return type.isValidAnnotation() && isAbiVersionCompatible(version); + return type != null && type.isValidAnnotation() && isAbiVersionCompatible(version); } /** @@ -107,7 +106,7 @@ public final class KotlinClassFileHeader { @Nullable public String[] getAnnotationData() { - if (annotationData == null && type != HeaderType.NONE) { + if (annotationData == null && type != null) { LOG.error("Data for annotations " + type.correspondingAnnotation + " was not read."); } return annotationData; @@ -127,14 +126,15 @@ public final class KotlinClassFileHeader { @Override public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { HeaderType headerTypeByAnnotation = HeaderType.byDescriptor(desc); - if (headerTypeByAnnotation == HeaderType.NONE) { + if (headerTypeByAnnotation == 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 " + headerTypeByAnnotation.correspondingAnnotation + " present!"); } - if (!type.isValidAnnotation()) { + if (!alreadyFoundValid) { type = headerTypeByAnnotation; } if (!headerTypeByAnnotation.isValidAnnotation()) {