KotlinClassFileHeader now saves JvmClassName for processed class
Add utility methods Refactor static method to member methods
This commit is contained in:
+39
-15
@@ -23,18 +23,6 @@ import java.util.List;
|
||||
import static org.jetbrains.asm4.ClassReader.*;
|
||||
|
||||
public final class KotlinClassFileHeader {
|
||||
@Nullable
|
||||
public static ClassData readClassData(@NotNull VirtualFile virtualFile) {
|
||||
String[] data = readKotlinHeaderFromClassFile(virtualFile).getAnnotationData();
|
||||
return data != null ? JavaProtoBufUtil.readClassDataFrom(data) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PackageData readPackageData(@NotNull VirtualFile virtualFile) {
|
||||
String[] data = readKotlinHeaderFromClassFile(virtualFile).getAnnotationData();
|
||||
return data != null ? JavaProtoBufUtil.readPackageDataFrom(data) : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull VirtualFile virtualFile) {
|
||||
try {
|
||||
@@ -71,20 +59,51 @@ public final class KotlinClassFileHeader {
|
||||
|
||||
@Nullable
|
||||
private String[] annotationData = null;
|
||||
|
||||
@NotNull
|
||||
HeaderType type = HeaderType.NONE;
|
||||
@Nullable
|
||||
JvmClassName jvmClassName = null;
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public HeaderType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isKotlinCompiledFile() {
|
||||
return type != HeaderType.NONE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmClassName getJvmClassName() {
|
||||
assert jvmClassName != null;
|
||||
return jvmClassName;
|
||||
}
|
||||
|
||||
public String[] getAnnotationData() {
|
||||
assertDataRead();
|
||||
return annotationData;
|
||||
}
|
||||
|
||||
private void assertDataRead() {
|
||||
if (annotationData == null && type != HeaderType.NONE) {
|
||||
throw new IllegalStateException("Data for annotations " + type.correspondingAnnotation + " was not read.");
|
||||
}
|
||||
return annotationData;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassData readClassData() {
|
||||
assert type == HeaderType.CLASS;
|
||||
return JavaProtoBufUtil.readClassDataFrom(getAnnotationData());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PackageData readPackageData() {
|
||||
assert type == HeaderType.PACKAGE;
|
||||
return JavaProtoBufUtil.readPackageDataFrom(getAnnotationData());
|
||||
}
|
||||
|
||||
private class ReadDataFromAnnotationVisitor extends ClassVisitor {
|
||||
@@ -93,6 +112,11 @@ public final class KotlinClassFileHeader {
|
||||
super(Opcodes.ASM4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
jvmClassName = JvmClassName.byInternalName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
|
||||
for (HeaderType headerType : HeaderType.values()) {
|
||||
|
||||
Reference in New Issue
Block a user