Write java signature of serialized descriptors efficiently

Instead of storing a string with the signature, write the name, return type and
parameter types separately, reusing the name table. Refactor the name table to
allow it to store not only names of Kotlin entities, but also arbitrary names
and fq-names
This commit is contained in:
Alexander Udalov
2013-07-11 17:12:01 +04:00
parent eee9bb5a12
commit 453b0e8f10
13 changed files with 1841 additions and 76 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.*;
import org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil;
import org.jetbrains.jet.descriptors.serialization.NameResolver;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationDeserializer;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
@@ -175,17 +176,19 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
@Override
public List<AnnotationDescriptor> loadCallableAnnotations(
@NotNull ClassOrNamespaceDescriptor container,
@NotNull ProtoBuf.Callable callableProto
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
) {
String signature = getCallableSignature(proto, nameResolver, kind);
if (signature == null) return Collections.emptyList();
VirtualFile file = findVirtualFileByDescriptor(container);
try {
// TODO: calculate this only once for each container
Map<String, List<AnnotationDescriptor>> memberAnnotations = loadMemberAnnotationsFromFile(file);
String signature = JavaProtoBufUtil.loadJavaSignature(callableProto);
if (signature == null) return Collections.emptyList();
List<AnnotationDescriptor> annotations = memberAnnotations.get(signature);
return annotations == null ? Collections.<AnnotationDescriptor>emptyList() : annotations;
}
@@ -194,6 +197,21 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
}
}
@Nullable
private static String getCallableSignature(
@NotNull ProtoBuf.Callable proto,
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
) {
switch (kind) {
case FUNCTION:
return JavaProtoBufUtil.loadMethodSignature(proto, nameResolver);
// TODO: getters, setters
default:
return null;
}
}
@NotNull
private Map<String, List<AnnotationDescriptor>> loadMemberAnnotationsFromFile(@NotNull VirtualFile file) throws IOException {
final Map<String, List<AnnotationDescriptor>> memberAnnotations = new HashMap<String, List<AnnotationDescriptor>>();