Write ProtoBuf.Package to .kotlin_package
Instead of a delimited list of callables. Also some minor refactorings
This commit is contained in:
@@ -9,7 +9,10 @@ import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.descriptors.serialization.*;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
@@ -26,6 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public class BuiltInsSerializer {
|
||||
private static final String BUILT_INS_SRC_DIR = "idea/builtinsSrc";
|
||||
private static final String DEST_DIR = "compiler/frontend/builtins";
|
||||
@@ -50,8 +54,6 @@ public class BuiltInsSerializer {
|
||||
|
||||
DescriptorValidator.validate(namespace);
|
||||
|
||||
List<DeclarationDescriptor> allDescriptors = DescriptorSerializer.sort(namespace.getMemberScope().getAllDescriptors());
|
||||
|
||||
final File destDir = new File(DEST_DIR);
|
||||
if (!FileUtil.delete(destDir)) {
|
||||
System.err.println("Could not delete: " + destDir);
|
||||
@@ -70,13 +72,13 @@ public class BuiltInsSerializer {
|
||||
});
|
||||
|
||||
final List<Name> classNames = new ArrayList<Name>();
|
||||
List<DeclarationDescriptor> allDescriptors = DescriptorSerializer.sort(namespace.getMemberScope().getAllDescriptors());
|
||||
ClassSerializationUtil.serializeClasses(allDescriptors, serializer, new ClassSerializationUtil.Sink() {
|
||||
@Override
|
||||
public void writeClass(@NotNull ClassDescriptor classDescriptor, @NotNull ProtoBuf.Class classProto) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
classProto.writeTo(stream);
|
||||
|
||||
write(destDir, getFileName(classDescriptor), stream);
|
||||
|
||||
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
|
||||
@@ -90,7 +92,27 @@ public class BuiltInsSerializer {
|
||||
});
|
||||
|
||||
ByteArrayOutputStream classNamesStream = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(classNamesStream);
|
||||
writeClassNames(serializer, classNames, classNamesStream);
|
||||
write(destDir, BuiltInsSerializationUtil.getClassNamesFilePath(namespace), classNamesStream);
|
||||
|
||||
ByteArrayOutputStream packageStream = new ByteArrayOutputStream();
|
||||
ProtoBuf.Package packageProto = serializer.packageProto(namespace).build();
|
||||
packageProto.writeTo(packageStream);
|
||||
write(destDir, BuiltInsSerializationUtil.getPackageFilePath(namespace), packageStream);
|
||||
|
||||
ByteArrayOutputStream nameStream = new ByteArrayOutputStream();
|
||||
NameSerializationUtil.serializeNameTable(nameStream, serializer.getNameTable());
|
||||
write(destDir, BuiltInsSerializationUtil.getNameTableFilePath(namespace), nameStream);
|
||||
|
||||
System.out.println("Total bytes written: " + totalSize + " to " + totalFiles + " files");
|
||||
}
|
||||
|
||||
private static void writeClassNames(
|
||||
@NotNull DescriptorSerializer serializer,
|
||||
@NotNull List<Name> classNames,
|
||||
@NotNull ByteArrayOutputStream stream
|
||||
) throws IOException {
|
||||
DataOutputStream data = new DataOutputStream(stream);
|
||||
try {
|
||||
data.writeInt(classNames.size());
|
||||
for (Name className : classNames) {
|
||||
@@ -101,35 +123,17 @@ public class BuiltInsSerializer {
|
||||
finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
CallableMemberDescriptor callableMemberDescriptor = (CallableMemberDescriptor) descriptor;
|
||||
ProtoBuf.Callable proto = serializer.callableProto(callableMemberDescriptor).build();
|
||||
proto.writeDelimitedTo(stream);
|
||||
}
|
||||
}
|
||||
|
||||
write(destDir, BuiltInsSerializationUtil.getPackageFilePath(namespace), stream);
|
||||
|
||||
ByteArrayOutputStream nameStream = new ByteArrayOutputStream();
|
||||
NameSerializationUtil.serializeNameTable(nameStream, serializer.getNameTable());
|
||||
write(destDir, BuiltInsSerializationUtil.getNameTableFilePath(namespace), nameStream);
|
||||
|
||||
write(destDir, BuiltInsSerializationUtil.getClassNamesFilePath(namespace), classNamesStream);
|
||||
|
||||
System.out.println("Total bytes written: " + totalSize + " to " + totalFiles + " files");
|
||||
}
|
||||
|
||||
private static void write(File destDir, String fileName, ByteArrayOutputStream stream) throws IOException {
|
||||
private static void write(@NotNull File destDir, @NotNull String fileName, @NotNull ByteArrayOutputStream stream) throws IOException {
|
||||
totalSize += stream.size();
|
||||
totalFiles++;
|
||||
FileUtil.writeToFile(new File(destDir, fileName), stream.toByteArray());
|
||||
System.out.println(stream.size() + " bytes written to " + fileName);
|
||||
}
|
||||
|
||||
private static String getFileName(ClassDescriptor classDescriptor) {
|
||||
@NotNull
|
||||
private static String getFileName(@NotNull ClassDescriptor classDescriptor) {
|
||||
return BuiltInsSerializationUtil.getClassMetadataPath(ClassSerializationUtil.getClassId(classDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user