KotlinInfo now has only one parameter data
Name table is now also stored in data, before the serialized class. ClassData is now public, since it's used in plenty of places as a holder of deserialized protobuf classes.
This commit is contained in:
@@ -61,8 +61,10 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
@@ -219,21 +221,35 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeKotlinInfo() {
|
private void writeKotlinInfo() {
|
||||||
final AnnotationVisitor av = v.getVisitor().visitAnnotation("Ljet/KotlinInfo;", true);
|
AnnotationVisitor av = v.getVisitor().visitAnnotation(JvmStdlibNames.KOTLIN_INFO_CLASS.getDescriptor(), true);
|
||||||
DescriptorSerializer serializer = new DescriptorSerializer(DescriptorNamer.DEFAULT);
|
DescriptorSerializer serializer = new DescriptorSerializer(DescriptorNamer.DEFAULT);
|
||||||
|
|
||||||
|
final ByteArrayOutputStream classStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
ClassSerializationUtil.serializeClass(descriptor, constantSerializer(serializer), new ClassSerializationUtil.Sink() {
|
ClassSerializationUtil.serializeClass(descriptor, constantSerializer(serializer), new ClassSerializationUtil.Sink() {
|
||||||
@Override
|
@Override
|
||||||
public void writeClass(@NotNull ClassDescriptor classDescriptor, @NotNull ProtoBuf.Class classProto) {
|
public void writeClass(@NotNull ClassDescriptor classDescriptor, @NotNull ProtoBuf.Class classProto) {
|
||||||
if (classDescriptor == descriptor) {
|
if (classDescriptor == descriptor) {
|
||||||
av.visit("data", classProto.toByteArray());
|
try {
|
||||||
|
classProto.writeTo(classStream);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ByteArrayOutputStream nameTable = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
NameSerializationUtil.serializeNameTable(nameTable, serializer.getNameTable());
|
NameSerializationUtil.serializeNameTable(out, serializer.getNameTable());
|
||||||
av.visit("nameTable", nameTable.toByteArray());
|
try {
|
||||||
|
out.write(classStream.toByteArray());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
av.visit("data", out.toByteArray());
|
||||||
|
|
||||||
av.visitEnd();
|
av.visitEnd();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java;
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
|
import jet.KotlinInfo;
|
||||||
import jet.runtime.typeinfo.JetConstructor;
|
import jet.runtime.typeinfo.JetConstructor;
|
||||||
|
|
||||||
public class JvmStdlibNames {
|
public class JvmStdlibNames {
|
||||||
@@ -68,6 +69,7 @@ public class JvmStdlibNames {
|
|||||||
*/
|
*/
|
||||||
public static final String JET_CONSTRUCTOR_HIDDEN_FIELD = "hidden";
|
public static final String JET_CONSTRUCTOR_HIDDEN_FIELD = "hidden";
|
||||||
|
|
||||||
|
public static final JvmClassName KOTLIN_INFO_CLASS = JvmClassName.byFqNameWithoutInnerClasses(KotlinInfo.class.getCanonicalName());
|
||||||
|
|
||||||
public static final JvmClassName JET_CLASS = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetClass");
|
public static final JvmClassName JET_CLASS = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetClass");
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -25,10 +25,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
|
import org.jetbrains.jet.lang.resolve.java.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
@@ -86,7 +83,7 @@ public final class JavaAnnotationResolver {
|
|||||||
// Don't process internal jet annotations and jetbrains NotNull annotations
|
// Don't process internal jet annotations and jetbrains NotNull annotations
|
||||||
if (qname.startsWith("jet.runtime.typeinfo.")
|
if (qname.startsWith("jet.runtime.typeinfo.")
|
||||||
|| qname.equals(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().asString())
|
|| qname.equals(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().asString())
|
||||||
|| qname.equals("jet.KotlinInfo")
|
|| qname.equals(JvmStdlibNames.KOTLIN_INFO_CLASS.getFqName().asString())
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
-20
@@ -97,24 +97,4 @@ public abstract class AbstractClassResolver implements ClassResolver {
|
|||||||
protected abstract Name getClassObjectName(@NotNull ClassDescriptor outerClass);
|
protected abstract Name getClassObjectName(@NotNull ClassDescriptor outerClass);
|
||||||
|
|
||||||
protected abstract void classDescriptorCreated(@NotNull ClassDescriptor classDescriptor);
|
protected abstract void classDescriptorCreated(@NotNull ClassDescriptor classDescriptor);
|
||||||
|
|
||||||
protected static class ClassData {
|
|
||||||
private final NameResolver nameResolver;
|
|
||||||
private final ProtoBuf.Class classProto;
|
|
||||||
|
|
||||||
public ClassData(@NotNull NameResolver nameResolver, @NotNull ProtoBuf.Class classProto) {
|
|
||||||
this.nameResolver = nameResolver;
|
|
||||||
this.classProto = classProto;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public NameResolver getNameResolver() {
|
|
||||||
return nameResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public ProtoBuf.Class getClassProto() {
|
|
||||||
return classProto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.descriptors.serialization;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ClassData {
|
||||||
|
private final NameResolver nameResolver;
|
||||||
|
private final ProtoBuf.Class classProto;
|
||||||
|
|
||||||
|
public ClassData(@NotNull NameResolver nameResolver, @NotNull ProtoBuf.Class classProto) {
|
||||||
|
this.nameResolver = nameResolver;
|
||||||
|
this.classProto = classProto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public NameResolver getNameResolver() {
|
||||||
|
return nameResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ProtoBuf.Class getClassProto() {
|
||||||
|
return classProto;
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -23,7 +23,10 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
|
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class ClassSerializationUtil {
|
public class ClassSerializationUtil {
|
||||||
@@ -83,6 +86,19 @@ public class ClassSerializationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ClassData readClassDataFrom(@NotNull byte[] bytes) {
|
||||||
|
try {
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||||
|
NameResolver nameResolver = NameSerializationUtil.deserializeNameResolver(in);
|
||||||
|
ProtoBuf.Class classProto = ProtoBuf.Class.parseFrom(in);
|
||||||
|
return new ClassData(nameResolver, classProto);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ClassId getClassId(@NotNull ClassDescriptor classDescriptor, @NotNull DescriptorNamer namer) {
|
public static ClassId getClassId(@NotNull ClassDescriptor classDescriptor, @NotNull DescriptorNamer namer) {
|
||||||
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
|
||||||
|
|||||||
+5
-8
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.descriptors.serialization;
|
package org.jetbrains.jet.descriptors.serialization;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import jet.KotlinInfo;
|
import jet.KotlinInfo;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -32,7 +31,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class WriteSerializedInfoTest extends CodegenTestCase {
|
public class WriteSerializedInfoTest extends CodegenTestCase {
|
||||||
public static final FqName NAMESPACE_NAME = new FqName("test");
|
public static final FqName NAMESPACE_NAME = new FqName("test");
|
||||||
@@ -64,15 +63,13 @@ public class WriteSerializedInfoTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class KotlinInfoBasedClassResolver extends AbstractClassResolver {
|
private static class KotlinInfoBasedClassResolver extends AbstractClassResolver {
|
||||||
private final NameResolver nameResolver;
|
private final ClassData classData;
|
||||||
private final ProtoBuf.Class classProto;
|
|
||||||
private final NamespaceDescriptorImpl namespace;
|
private final NamespaceDescriptorImpl namespace;
|
||||||
|
|
||||||
public KotlinInfoBasedClassResolver(@NotNull KotlinInfo kotlinInfo) throws InvalidProtocolBufferException {
|
public KotlinInfoBasedClassResolver(@NotNull KotlinInfo kotlinInfo) throws IOException {
|
||||||
super(new LockBasedStorageManager(), AnnotationDeserializer.UNSUPPORTED);
|
super(new LockBasedStorageManager(), AnnotationDeserializer.UNSUPPORTED);
|
||||||
|
|
||||||
this.nameResolver = NameSerializationUtil.deserializeNameResolver(new ByteArrayInputStream(kotlinInfo.nameTable()));
|
this.classData = ClassSerializationUtil.readClassDataFrom(kotlinInfo.data());
|
||||||
this.classProto = ProtoBuf.Class.parseFrom(kotlinInfo.data());
|
|
||||||
this.namespace = JetTestUtils.createTestNamespace(NAMESPACE_NAME.asString());
|
this.namespace = JetTestUtils.createTestNamespace(NAMESPACE_NAME.asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +78,7 @@ public class WriteSerializedInfoTest extends CodegenTestCase {
|
|||||||
protected ClassData getClassData(@NotNull ClassId classId) {
|
protected ClassData getClassData(@NotNull ClassId classId) {
|
||||||
assert classId.getPackageFqName().equals(NAMESPACE_NAME) &&
|
assert classId.getPackageFqName().equals(NAMESPACE_NAME) &&
|
||||||
classId.getRelativeClassName().equals(CLASS_NAME) : "Unsupported classId: " + classId;
|
classId.getRelativeClassName().equals(CLASS_NAME) : "Unsupported classId: " + classId;
|
||||||
return new ClassData(nameResolver, classProto);
|
return classData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -22,6 +22,4 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface KotlinInfo {
|
public @interface KotlinInfo {
|
||||||
byte[] data();
|
byte[] data();
|
||||||
|
|
||||||
byte[] nameTable();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user