Make KotlinClassFileHeader immutable, make its inner class nested
This commit is contained in:
+28
-19
@@ -26,11 +26,10 @@ public final class KotlinClassFileHeader {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull VirtualFile virtualFile) {
|
public static KotlinClassFileHeader readKotlinHeaderFromClassFile(@NotNull VirtualFile virtualFile) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = virtualFile.contentsToByteArray();
|
ClassReader reader = new ClassReader(virtualFile.contentsToByteArray());
|
||||||
ClassReader reader = new ClassReader(bytes);
|
ReadDataFromAnnotationVisitor visitor = new ReadDataFromAnnotationVisitor();
|
||||||
KotlinClassFileHeader classFileData = new KotlinClassFileHeader();
|
reader.accept(visitor, SKIP_CODE | SKIP_FRAMES | SKIP_DEBUG);
|
||||||
reader.accept(classFileData.new ReadDataFromAnnotationVisitor(), SKIP_CODE | SKIP_FRAMES | SKIP_DEBUG);
|
return new KotlinClassFileHeader(visitor.version, visitor.annotationData, visitor.type, visitor.fqName);
|
||||||
return classFileData;
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -70,14 +69,20 @@ public final class KotlinClassFileHeader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int version = AbiVersionUtil.INVALID_VERSION;
|
private final int version;
|
||||||
|
@Nullable
|
||||||
|
private final String[] annotationData;
|
||||||
|
@Nullable
|
||||||
|
private final HeaderType type;
|
||||||
|
@Nullable
|
||||||
|
private final FqName fqName;
|
||||||
|
|
||||||
@Nullable
|
private KotlinClassFileHeader(int version, @Nullable String[] annotationData, @Nullable HeaderType type, @Nullable FqName fqName) {
|
||||||
private String[] annotationData = null;
|
this.version = version;
|
||||||
@Nullable
|
this.annotationData = annotationData;
|
||||||
private HeaderType type = null;
|
this.type = type;
|
||||||
@Nullable
|
this.fqName = fqName;
|
||||||
private JvmClassName jvmClassName = null;
|
}
|
||||||
|
|
||||||
public int getVersion() {
|
public int getVersion() {
|
||||||
return version;
|
return version;
|
||||||
@@ -100,8 +105,8 @@ public final class KotlinClassFileHeader {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public FqName getFqName() {
|
public FqName getFqName() {
|
||||||
assert jvmClassName != null;
|
assert fqName != null;
|
||||||
return jvmClassName.getFqName();
|
return fqName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -112,7 +117,14 @@ public final class KotlinClassFileHeader {
|
|||||||
return annotationData;
|
return annotationData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReadDataFromAnnotationVisitor extends ClassVisitor {
|
private static class ReadDataFromAnnotationVisitor extends ClassVisitor {
|
||||||
|
private int version = AbiVersionUtil.INVALID_VERSION;
|
||||||
|
@Nullable
|
||||||
|
private String[] annotationData = null;
|
||||||
|
@Nullable
|
||||||
|
private HeaderType type = null;
|
||||||
|
@Nullable
|
||||||
|
private FqName fqName = null;
|
||||||
|
|
||||||
public ReadDataFromAnnotationVisitor() {
|
public ReadDataFromAnnotationVisitor() {
|
||||||
super(Opcodes.ASM4);
|
super(Opcodes.ASM4);
|
||||||
@@ -120,7 +132,7 @@ public final class KotlinClassFileHeader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||||
jvmClassName = JvmClassName.byInternalName(name);
|
fqName = JvmClassName.byInternalName(name).getFqName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,7 +197,4 @@ public final class KotlinClassFileHeader {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private KotlinClassFileHeader() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user