Change .kotlin_class_names format a little
Before writing a list of indexes of built-in classes' names, write the length of such a list. It helps to read this list normally (not until an exception happens)
This commit is contained in:
Binary file not shown.
+13
-10
@@ -85,22 +85,25 @@ class BuiltinsNamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl {
|
|||||||
private final NotNullLazyValue<Collection<Name>> classNames = storageManager.createLazyValue(new Computable<Collection<Name>>() {
|
private final NotNullLazyValue<Collection<Name>> classNames = storageManager.createLazyValue(new Computable<Collection<Name>>() {
|
||||||
@Override
|
@Override
|
||||||
public Collection<Name> compute() {
|
public Collection<Name> compute() {
|
||||||
InputStream namesStream =
|
InputStream in = getStream(BuiltInsSerializationUtil.getClassNamesFilePath(BuiltinsNamespaceDescriptorImpl.this));
|
||||||
getStream(BuiltInsSerializationUtil.getClassNamesFilePath(BuiltinsNamespaceDescriptorImpl.this));
|
|
||||||
List<Name> result = new ArrayList<Name>();
|
|
||||||
try {
|
try {
|
||||||
DataInputStream data = new DataInputStream(namesStream);
|
DataInputStream data = new DataInputStream(in);
|
||||||
while (true) {
|
try {
|
||||||
result.add(nameResolver.getName(data.readInt()));
|
int size = data.readInt();
|
||||||
|
List<Name> result = new ArrayList<Name>(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
result.add(nameResolver.getName(data.readInt()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
data.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (EOFException e) {
|
|
||||||
// OK: finishing the loop
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.lang.BuiltInsSerializationUtil;
|
import org.jetbrains.jet.lang.types.lang.BuiltInsSerializationUtil;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.test.util.DescriptorValidator;
|
import org.jetbrains.jet.test.util.DescriptorValidator;
|
||||||
@@ -21,6 +22,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -58,7 +60,7 @@ public class BuiltInsSerializer {
|
|||||||
System.err.println("Could not make directories: " + destDir);
|
System.err.println("Could not make directories: " + destDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
final DescriptorSerializer serializer = new DescriptorSerializer(new SerializerExtension() {
|
DescriptorSerializer serializer = new DescriptorSerializer(new SerializerExtension() {
|
||||||
private final ImmutableSet<String> set = ImmutableSet.of("Any", "Nothing");
|
private final ImmutableSet<String> set = ImmutableSet.of("Any", "Nothing");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,13 +68,11 @@ public class BuiltInsSerializer {
|
|||||||
return !set.contains(classDescriptor.getName().asString());
|
return !set.contains(classDescriptor.getName().asString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ByteArrayOutputStream classNames = new ByteArrayOutputStream();
|
|
||||||
final DataOutputStream data = new DataOutputStream(classNames);
|
final List<Name> classNames = new ArrayList<Name>();
|
||||||
ClassSerializationUtil.serializeClasses(allDescriptors, ClassSerializationUtil.constantSerializer(serializer), new ClassSerializationUtil.Sink() {
|
ClassSerializationUtil.serializeClasses(allDescriptors, ClassSerializationUtil.constantSerializer(serializer), new ClassSerializationUtil.Sink() {
|
||||||
@Override
|
@Override
|
||||||
public void writeClass(
|
public void writeClass(@NotNull ClassDescriptor classDescriptor, @NotNull ProtoBuf.Class classProto) {
|
||||||
@NotNull ClassDescriptor classDescriptor, @NotNull ProtoBuf.Class classProto
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
classProto.writeTo(stream);
|
classProto.writeTo(stream);
|
||||||
@@ -80,8 +80,7 @@ public class BuiltInsSerializer {
|
|||||||
write(destDir, getFileName(classDescriptor), stream);
|
write(destDir, getFileName(classDescriptor), stream);
|
||||||
|
|
||||||
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
|
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
|
||||||
int index = serializer.getNameTable().getSimpleNameIndex(classDescriptor.getName());
|
classNames.add(classDescriptor.getName());
|
||||||
data.writeInt(index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
@@ -89,7 +88,19 @@ public class BuiltInsSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
data.close();
|
|
||||||
|
ByteArrayOutputStream classNamesStream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream data = new DataOutputStream(classNamesStream);
|
||||||
|
try {
|
||||||
|
data.writeInt(classNames.size());
|
||||||
|
for (Name className : classNames) {
|
||||||
|
int index = serializer.getNameTable().getSimpleNameIndex(className);
|
||||||
|
data.writeInt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
data.close();
|
||||||
|
}
|
||||||
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
for (DeclarationDescriptor descriptor : allDescriptors) {
|
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||||
@@ -106,7 +117,7 @@ public class BuiltInsSerializer {
|
|||||||
NameSerializationUtil.serializeNameTable(nameStream, serializer.getNameTable());
|
NameSerializationUtil.serializeNameTable(nameStream, serializer.getNameTable());
|
||||||
write(destDir, BuiltInsSerializationUtil.getNameTableFilePath(namespace), nameStream);
|
write(destDir, BuiltInsSerializationUtil.getNameTableFilePath(namespace), nameStream);
|
||||||
|
|
||||||
write(destDir, BuiltInsSerializationUtil.getClassNamesFilePath(namespace), classNames);
|
write(destDir, BuiltInsSerializationUtil.getClassNamesFilePath(namespace), classNamesStream);
|
||||||
|
|
||||||
System.out.println("Total bytes written: " + totalSize + " to " + totalFiles + " files");
|
System.out.println("Total bytes written: " + totalSize + " to " + totalFiles + " files");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user