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
+1
View File
@@ -14,6 +14,7 @@
<orderEntry type="library" name="javax.inject" level="project" />
<orderEntry type="module" module-name="serialization" />
<orderEntry type="library" name="protobuf-java" level="project" />
<orderEntry type="module" module-name="serialization.java" />
</component>
</module>
@@ -41,9 +41,7 @@ import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer;
import org.jetbrains.jet.descriptors.serialization.NameSerializationUtil;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.descriptors.serialization.*;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
import org.jetbrains.jet.lang.psi.*;
@@ -223,7 +221,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void writeKotlinInfo() {
AnnotationVisitor av = v.getVisitor().visitAnnotation(JvmStdlibNames.KOTLIN_INFO_CLASS.getDescriptor(), true);
DescriptorSerializer serializer = new DescriptorSerializer();
DescriptorSerializer serializer = new DescriptorSerializer(new JavaSerializerExtension(typeMapper));
ProtoBuf.Class classProto = serializer.classProto(descriptor).build();
@@ -1844,5 +1843,4 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
@@ -0,0 +1,52 @@
/*
* 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.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.descriptors.serialization.SerializerExtension;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
public class JavaSerializerExtension extends SerializerExtension {
private final JetTypeMapper typeMapper;
public JavaSerializerExtension(@NotNull JetTypeMapper typeMapper) {
this.typeMapper = typeMapper;
}
@Override
public void serializeCallable(@NotNull CallableMemberDescriptor callable, @NotNull ProtoBuf.Callable.Builder proto) {
JvmMethodSignature signature = mapSignature(callable);
if (signature != null) {
JavaProtoBufUtil.saveJavaSignature(proto, signature.getAsmMethod().toString());
}
}
// TODO: this should be done upon generation of the member instead, because we don't know enough at this point to map correctly
@Nullable
private JvmMethodSignature mapSignature(@NotNull CallableMemberDescriptor descriptor) {
if (descriptor instanceof FunctionDescriptor) {
return typeMapper.mapSignature((FunctionDescriptor) descriptor);
}
return null;
}
}