Deserialize annotations on class members

Make 'Callable' message of descriptors.proto extensible, extend it in
java_descriptors.proto with a JVM signature of the member. This is needed in
order for annotation deserializer to find out which member in the compiled
bytecode corresponds to which descriptor in the hierarchy.

Create a new module 'serialization.java' containing everything related to
Java-specific serialization of descriptors.

Add an extension point to DescriptorSerializer, allowing to perform
platform-specific serialization on a callable
This commit is contained in:
Alexander Udalov
2013-07-05 22:38:46 +04:00
parent d0635aac3e
commit 67ca7b78c4
26 changed files with 368 additions and 99 deletions
@@ -0,0 +1,26 @@
/*
* 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 "compiler/frontend/serialization/src/descriptors.proto";
option java_outer_classname = "JavaProtoBuf";
option optimize_for = LITE_RUNTIME;
extend Callable {
optional string java_signature = 100;
}
@@ -0,0 +1,29 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: compiler/frontend.java/serialization.java/src/java_descriptors.proto
package org.jetbrains.jet.descriptors.serialization;
public final class JavaProtoBuf {
private JavaProtoBuf() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
registry.add(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.javaSignature);
}
public static final int JAVA_SIGNATURE_FIELD_NUMBER = 100;
public static final
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable,
java.lang.String> javaSignature = com.google.protobuf.GeneratedMessageLite
.newSingularGeneratedExtension(
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance(),
"",
null,
null,
100,
com.google.protobuf.WireFormat.FieldType.STRING);
static {
}
// @@protoc_insertion_point(outer_class_scope)
}
@@ -0,0 +1,44 @@
/*
* 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 com.google.protobuf.ExtensionRegistryLite;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.javaSignature;
public class JavaProtoBufUtil {
private JavaProtoBufUtil() {
}
@Nullable
public static String loadJavaSignature(@NotNull ProtoBuf.Callable callable) {
return callable.hasExtension(javaSignature) ? callable.getExtension(javaSignature) : null;
}
public static void saveJavaSignature(@NotNull ProtoBuf.Callable.Builder callable, @NotNull String signature) {
callable.setExtension(javaSignature, signature);
}
@NotNull
public static ClassData readJavaClassDataFrom(@NotNull byte[] data) {
ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance();
JavaProtoBuf.registerAllExtensions(registry);
return ClassData.read(data, registry);
}
}