Deserialize annotations from package$src files if needed
For top-level members, we now write a FQ name of the package$src class which has the member's annotations, and read the correct file in deserialization
This commit is contained in:
@@ -69,4 +69,7 @@ extend Callable {
|
||||
optional JavaMethodSignature method_signature = 100;
|
||||
|
||||
optional JavaPropertySignature property_signature = 101;
|
||||
|
||||
// For top-level callables, short name of "...Package$src$..." class with the callable's body and annotations
|
||||
optional int32 src_class_name = 102;
|
||||
}
|
||||
|
||||
+13
@@ -9,6 +9,7 @@ public final class JavaProtoBuf {
|
||||
com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
registry.add(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.methodSignature);
|
||||
registry.add(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.propertySignature);
|
||||
registry.add(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.srcClassName);
|
||||
}
|
||||
public interface JavaTypeOrBuilder
|
||||
extends com.google.protobuf.MessageLiteOrBuilder {
|
||||
@@ -1979,6 +1980,18 @@ public final class JavaProtoBuf {
|
||||
null,
|
||||
101,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE);
|
||||
public static final int SRC_CLASS_NAME_FIELD_NUMBER = 102;
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable,
|
||||
java.lang.Integer> srcClassName = com.google.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance(),
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
102,
|
||||
com.google.protobuf.WireFormat.FieldType.INT32);
|
||||
|
||||
static {
|
||||
}
|
||||
|
||||
+14
@@ -105,6 +105,12 @@ public class JavaProtoBufUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name loadSrcClassName(@NotNull ProtoBuf.Callable proto, @NotNull NameResolver nameResolver) {
|
||||
if (!proto.hasExtension(JavaProtoBuf.srcClassName)) return null;
|
||||
return nameResolver.getName(proto.getExtension(JavaProtoBuf.srcClassName));
|
||||
}
|
||||
|
||||
public static void saveMethodSignature(@NotNull ProtoBuf.Callable.Builder proto, @NotNull Method method, @NotNull NameTable nameTable) {
|
||||
proto.setExtension(JavaProtoBuf.methodSignature, new Serializer(nameTable).methodSignature(method));
|
||||
}
|
||||
@@ -122,6 +128,14 @@ public class JavaProtoBufUtil {
|
||||
new Serializer(nameTable).propertySignature(fieldType, fieldName, syntheticMethodName, getter, setter));
|
||||
}
|
||||
|
||||
public static void saveSrcClassName(
|
||||
@NotNull ProtoBuf.Callable.Builder proto,
|
||||
@NotNull Name name,
|
||||
@NotNull NameTable nameTable
|
||||
) {
|
||||
proto.setExtension(JavaProtoBuf.srcClassName, nameTable.getSimpleNameIndex(name));
|
||||
}
|
||||
|
||||
private static class Serializer {
|
||||
private final NameTable nameTable;
|
||||
|
||||
|
||||
+24
-1
@@ -184,7 +184,7 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
|
||||
MemberSignature signature = getCallableSignature(proto, nameResolver, kind);
|
||||
if (signature == null) return Collections.emptyList();
|
||||
|
||||
VirtualFile file = findVirtualFileByDescriptor(container);
|
||||
VirtualFile file = getVirtualFileWithMemberAnnotations(container, proto, nameResolver);
|
||||
|
||||
try {
|
||||
// TODO: calculate this only once for each container
|
||||
@@ -198,6 +198,29 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private VirtualFile getVirtualFileWithMemberAnnotations(
|
||||
@NotNull ClassOrNamespaceDescriptor container,
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
@NotNull NameResolver nameResolver
|
||||
) {
|
||||
if (container instanceof NamespaceDescriptor) {
|
||||
Name name = JavaProtoBufUtil.loadSrcClassName(proto, nameResolver);
|
||||
if (name != null) {
|
||||
// To locate a package$src class, we first find the facade virtual file (*Package.class) and then look up the $src file in
|
||||
// the same directory. This hack is needed because FileManager doesn't find classfiles for $src classes
|
||||
VirtualFile facadeFile = findVirtualFileByPackage((NamespaceDescriptor) container);
|
||||
|
||||
VirtualFile srcFile = facadeFile.getParent().findChild(name + ".class");
|
||||
if (srcFile != null) {
|
||||
return srcFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return findVirtualFileByDescriptor(container);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static MemberSignature getCallableSignature(
|
||||
@NotNull ProtoBuf.Callable proto,
|
||||
|
||||
Reference in New Issue
Block a user