Delete LOG.error from ReadDataFromAnnotationVisitor
These conditions can happen on a broken binary data, no need to report an error about it
This commit is contained in:
+1
-3
@@ -23,9 +23,7 @@ import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
|
|||||||
public abstract class KotlinClassFileHeader {
|
public abstract class KotlinClassFileHeader {
|
||||||
@Nullable
|
@Nullable
|
||||||
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull KotlinJvmBinaryClass kotlinClass) {
|
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull KotlinJvmBinaryClass kotlinClass) {
|
||||||
ReadDataFromAnnotationVisitor visitor = new ReadDataFromAnnotationVisitor();
|
return ReadDataFromAnnotationVisitor.read(kotlinClass);
|
||||||
kotlinClass.loadClassAnnotations(visitor);
|
|
||||||
return visitor.createHeader(kotlinClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int version;
|
private final int version;
|
||||||
|
|||||||
+17
-9
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.kotlin.header;
|
package org.jetbrains.jet.lang.resolve.kotlin.header;
|
||||||
|
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
|
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
|
||||||
@@ -34,8 +33,6 @@ import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.Annotat
|
|||||||
import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.AnnotationVisitor;
|
import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.AnnotationVisitor;
|
||||||
|
|
||||||
/* package */ class ReadDataFromAnnotationVisitor implements AnnotationVisitor {
|
/* package */ class ReadDataFromAnnotationVisitor implements AnnotationVisitor {
|
||||||
private static final Logger LOG = Logger.getInstance(ReadDataFromAnnotationVisitor.class);
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private enum HeaderType {
|
private enum HeaderType {
|
||||||
CLASS(JvmAnnotationNames.KOTLIN_CLASS),
|
CLASS(JvmAnnotationNames.KOTLIN_CLASS),
|
||||||
@@ -68,8 +65,18 @@ import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.Annotat
|
|||||||
@Nullable
|
@Nullable
|
||||||
private HeaderType foundType = null;
|
private HeaderType foundType = null;
|
||||||
|
|
||||||
|
private ReadDataFromAnnotationVisitor() {
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public KotlinClassFileHeader createHeader(@NotNull KotlinJvmBinaryClass kotlinClass) {
|
public static KotlinClassFileHeader read(@NotNull KotlinJvmBinaryClass kotlinClass) {
|
||||||
|
ReadDataFromAnnotationVisitor visitor = new ReadDataFromAnnotationVisitor();
|
||||||
|
kotlinClass.loadClassAnnotations(visitor);
|
||||||
|
return visitor.createHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public KotlinClassFileHeader createHeader() {
|
||||||
if (foundType == null) {
|
if (foundType == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -80,9 +87,9 @@ import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.Annotat
|
|||||||
|
|
||||||
switch (foundType) {
|
switch (foundType) {
|
||||||
case CLASS:
|
case CLASS:
|
||||||
return serializedDataHeader(SerializedDataHeader.Kind.CLASS, kotlinClass);
|
return serializedDataHeader(SerializedDataHeader.Kind.CLASS);
|
||||||
case PACKAGE:
|
case PACKAGE:
|
||||||
return serializedDataHeader(SerializedDataHeader.Kind.PACKAGE, kotlinClass);
|
return serializedDataHeader(SerializedDataHeader.Kind.PACKAGE);
|
||||||
case PACKAGE_FRAGMENT:
|
case PACKAGE_FRAGMENT:
|
||||||
return new PackageFragmentClassFileHeader(version);
|
return new PackageFragmentClassFileHeader(version);
|
||||||
default:
|
default:
|
||||||
@@ -91,9 +98,10 @@ import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.Annotat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private SerializedDataHeader serializedDataHeader(@NotNull SerializedDataHeader.Kind kind, @NotNull KotlinJvmBinaryClass kotlinClass) {
|
private SerializedDataHeader serializedDataHeader(@NotNull SerializedDataHeader.Kind kind) {
|
||||||
if (annotationData == null) {
|
if (annotationData == null) {
|
||||||
LOG.error("Kotlin annotation " + foundType + " is incorrect for class: " + kotlinClass);
|
// This means that the annotation is found and its ABI version is compatible, but there's no "data" string array in it.
|
||||||
|
// We tell the outside world that there's really no annotation at all
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new SerializedDataHeader(version, annotationData, kind);
|
return new SerializedDataHeader(version, annotationData, kind);
|
||||||
@@ -106,7 +114,7 @@ import static org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass.Annotat
|
|||||||
if (newType == null) return null;
|
if (newType == null) return null;
|
||||||
|
|
||||||
if (foundType != null) {
|
if (foundType != null) {
|
||||||
LOG.error("Both annotations are present for compiled Kotlin file: " + foundType + " and " + newType);
|
// Ignore all Kotlin annotations except the first found
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user