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:
Alexander Udalov
2013-06-27 22:49:08 +04:00
parent 4e0516472d
commit 83501c3722
8 changed files with 85 additions and 40 deletions
@@ -97,24 +97,4 @@ public abstract class AbstractClassResolver implements ClassResolver {
protected abstract Name getClassObjectName(@NotNull ClassDescriptor outerClass);
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;
}
}
}
@@ -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;
}
}
@@ -23,7 +23,10 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
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;
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
public static ClassId getClassId(@NotNull ClassDescriptor classDescriptor, @NotNull DescriptorNamer namer) {
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();