Write full synthetic method signature for annotated property

This will be needed to support annotated extension properties, since they have
the same name but different signatures
This commit is contained in:
Alexander Udalov
2013-10-09 22:46:51 +04:00
parent 6e45533065
commit 806d264771
9 changed files with 166 additions and 106 deletions
@@ -17,6 +17,8 @@
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.Method;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -25,7 +27,7 @@ public final class JvmAbi {
* This constant is used to identify binary format (class file) versions
* If you change class file metadata format and/or naming conventions, please increase this number
*/
public static final int VERSION = 9;
public static final int VERSION = 10;
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
@@ -39,7 +41,6 @@ public final class JvmAbi {
public static final String DELEGATED_PROPERTY_NAME_SUFFIX = "$delegate";
public static final String ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX = "$annotations";
public static final String ANNOTATED_PROPERTY_METHOD_SIGNATURE = "()V";
public static final String INSTANCE_FIELD = "instance$";
public static final String CLASS_OBJECT_FIELD = "object$";
@@ -56,8 +57,12 @@ public final class JvmAbi {
}
@NotNull
public static String getSyntheticMethodNameForAnnotatedProperty(@NotNull Name propertyName) {
return propertyName.asString() + ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX;
public static Method getSyntheticMethodSignatureForAnnotatedProperty(@NotNull Name propertyName) {
return new Method(
propertyName.asString() + ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX,
Type.VOID_TYPE,
new Type[0]
);
}
@NotNull
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
@@ -287,23 +286,21 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
@NotNull NameResolver nameResolver,
@NotNull AnnotatedCallableKind kind
) {
SignatureDeserializer deserializer = new SignatureDeserializer(nameResolver);
switch (kind) {
case FUNCTION:
if (proto.hasExtension(JavaProtoBuf.methodSignature)) {
JavaProtoBuf.JavaMethodSignature signature = proto.getExtension(JavaProtoBuf.methodSignature);
return new SignatureDeserializer(nameResolver).methodSignature(signature);
return deserializer.methodSignature(proto.getExtension(JavaProtoBuf.methodSignature));
}
break;
case PROPERTY_GETTER:
if (proto.hasExtension(JavaProtoBuf.propertySignature)) {
JavaProtoBuf.JavaPropertySignature propertySignature = proto.getExtension(JavaProtoBuf.propertySignature);
return new SignatureDeserializer(nameResolver).methodSignature(propertySignature.getGetter());
return deserializer.methodSignature(proto.getExtension(JavaProtoBuf.propertySignature).getGetter());
}
break;
case PROPERTY_SETTER:
if (proto.hasExtension(JavaProtoBuf.propertySignature)) {
JavaProtoBuf.JavaPropertySignature propertySignature = proto.getExtension(JavaProtoBuf.propertySignature);
return new SignatureDeserializer(nameResolver).methodSignature(propertySignature.getSetter());
return deserializer.methodSignature(proto.getExtension(JavaProtoBuf.propertySignature).getSetter());
}
break;
case PROPERTY:
@@ -312,13 +309,12 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
if (propertySignature.hasField()) {
JavaProtoBuf.JavaFieldSignature field = propertySignature.getField();
String type = new SignatureDeserializer(nameResolver).typeDescriptor(field.getType());
String type = deserializer.typeDescriptor(field.getType());
Name name = nameResolver.getName(field.getName());
return MemberSignature.fromFieldNameAndDesc(name, type);
}
else if (propertySignature.hasSyntheticMethodName()) {
Name name = nameResolver.getName(propertySignature.getSyntheticMethodName());
return MemberSignature.fromMethodNameAndDesc(name, JvmAbi.ANNOTATED_PROPERTY_METHOD_SIGNATURE);
else if (propertySignature.hasSyntheticMethod()) {
return deserializer.methodSignature(propertySignature.getSyntheticMethod());
}
}
break;
@@ -58,12 +58,12 @@ message JavaFieldSignature {
}
message JavaPropertySignature {
// A property itself is identified either by the field, or by the name of the synthetic method.
// If the property is annotated, then either field or synthetic_method_name should be present
// A property itself is identified either by the field, or by the synthetic method.
// If the property is annotated, then either field or synthetic_method should be present
optional JavaFieldSignature field = 1;
// Name of the synthetic method created to store property annotations. Signature is always "()V"
optional int32 synthetic_method_name = 2;
// Annotations on properties without backing fields are written on a synthetic method with this signature
optional JavaMethodSignature synthetic_method = 2;
optional JavaMethodSignature getter = 3;
optional JavaMethodSignature setter = 4;
@@ -1945,8 +1945,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
boolean hasField();
@@ -1954,29 +1954,29 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature getField();
// optional int32 synthetic_method_name = 2;
// optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
boolean hasSyntheticMethodName();
boolean hasSyntheticMethod();
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
int getSyntheticMethodName();
org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature getSyntheticMethod();
// optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature getter = 3;
/**
@@ -2054,9 +2054,17 @@ public final class JavaProtoBuf {
bitField0_ |= 0x00000001;
break;
}
case 16: {
case 18: {
org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.Builder subBuilder = null;
if (((bitField0_ & 0x00000002) == 0x00000002)) {
subBuilder = syntheticMethod_.toBuilder();
}
syntheticMethod_ = input.readMessage(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(syntheticMethod_);
syntheticMethod_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000002;
syntheticMethodName_ = input.readInt32();
break;
}
case 26: {
@@ -2119,8 +2127,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public boolean hasField() {
@@ -2130,36 +2138,36 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature getField() {
return field_;
}
// optional int32 synthetic_method_name = 2;
public static final int SYNTHETIC_METHOD_NAME_FIELD_NUMBER = 2;
private int syntheticMethodName_;
// optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;
public static final int SYNTHETIC_METHOD_FIELD_NUMBER = 2;
private org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature syntheticMethod_;
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public boolean hasSyntheticMethodName() {
public boolean hasSyntheticMethod() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public int getSyntheticMethodName() {
return syntheticMethodName_;
public org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature getSyntheticMethod() {
return syntheticMethod_;
}
// optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature getter = 3;
@@ -2196,7 +2204,7 @@ public final class JavaProtoBuf {
private void initFields() {
field_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature.getDefaultInstance();
syntheticMethodName_ = 0;
syntheticMethod_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
getter_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
setter_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
}
@@ -2211,6 +2219,12 @@ public final class JavaProtoBuf {
return false;
}
}
if (hasSyntheticMethod()) {
if (!getSyntheticMethod().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
if (hasGetter()) {
if (!getGetter().isInitialized()) {
memoizedIsInitialized = 0;
@@ -2234,7 +2248,7 @@ public final class JavaProtoBuf {
output.writeMessage(1, field_);
}
if (((bitField0_ & 0x00000002) == 0x00000002)) {
output.writeInt32(2, syntheticMethodName_);
output.writeMessage(2, syntheticMethod_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeMessage(3, getter_);
@@ -2256,7 +2270,7 @@ public final class JavaProtoBuf {
}
if (((bitField0_ & 0x00000002) == 0x00000002)) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, syntheticMethodName_);
.computeMessageSize(2, syntheticMethod_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
size += com.google.protobuf.CodedOutputStream
@@ -2359,7 +2373,7 @@ public final class JavaProtoBuf {
super.clear();
field_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000001);
syntheticMethodName_ = 0;
syntheticMethod_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000002);
getter_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000004);
@@ -2395,7 +2409,7 @@ public final class JavaProtoBuf {
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
to_bitField0_ |= 0x00000002;
}
result.syntheticMethodName_ = syntheticMethodName_;
result.syntheticMethod_ = syntheticMethod_;
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
to_bitField0_ |= 0x00000004;
}
@@ -2413,8 +2427,8 @@ public final class JavaProtoBuf {
if (other.hasField()) {
mergeField(other.getField());
}
if (other.hasSyntheticMethodName()) {
setSyntheticMethodName(other.getSyntheticMethodName());
if (other.hasSyntheticMethod()) {
mergeSyntheticMethod(other.getSyntheticMethod());
}
if (other.hasGetter()) {
mergeGetter(other.getGetter());
@@ -2432,6 +2446,12 @@ public final class JavaProtoBuf {
return false;
}
}
if (hasSyntheticMethod()) {
if (!getSyntheticMethod().isInitialized()) {
return false;
}
}
if (hasGetter()) {
if (!getGetter().isInitialized()) {
@@ -2472,8 +2492,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public boolean hasField() {
@@ -2483,8 +2503,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature getField() {
@@ -2494,8 +2514,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public Builder setField(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature value) {
@@ -2511,8 +2531,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public Builder setField(
@@ -2526,8 +2546,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public Builder mergeField(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaFieldSignature value) {
@@ -2546,8 +2566,8 @@ public final class JavaProtoBuf {
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaFieldSignature field = 1;</code>
*
* <pre>
* A property itself is identified either by the field, or by the name of the synthetic method.
* If the property is annotated, then either field or synthetic_method_name should be present
* A property itself is identified either by the field, or by the synthetic method.
* If the property is annotated, then either field or synthetic_method should be present
* </pre>
*/
public Builder clearField() {
@@ -2557,52 +2577,88 @@ public final class JavaProtoBuf {
return this;
}
// optional int32 synthetic_method_name = 2;
private int syntheticMethodName_ ;
// optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;
private org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature syntheticMethod_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public boolean hasSyntheticMethodName() {
public boolean hasSyntheticMethod() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public int getSyntheticMethodName() {
return syntheticMethodName_;
public org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature getSyntheticMethod() {
return syntheticMethod_;
}
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public Builder setSyntheticMethodName(int value) {
public Builder setSyntheticMethod(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature value) {
if (value == null) {
throw new NullPointerException();
}
syntheticMethod_ = value;
bitField0_ |= 0x00000002;
syntheticMethodName_ = value;
return this;
}
/**
* <code>optional int32 synthetic_method_name = 2;</code>
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Name of the synthetic method created to store property annotations. Signature is always "()V"
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public Builder clearSyntheticMethodName() {
public Builder setSyntheticMethod(
org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.Builder builderForValue) {
syntheticMethod_ = builderForValue.build();
bitField0_ |= 0x00000002;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public Builder mergeSyntheticMethod(org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature value) {
if (((bitField0_ & 0x00000002) == 0x00000002) &&
syntheticMethod_ != org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance()) {
syntheticMethod_ =
org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.newBuilder(syntheticMethod_).mergeFrom(value).buildPartial();
} else {
syntheticMethod_ = value;
}
bitField0_ |= 0x00000002;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.JavaMethodSignature synthetic_method = 2;</code>
*
* <pre>
* Annotations on properties without backing fields are written on a synthetic method with this signature
* </pre>
*/
public Builder clearSyntheticMethod() {
syntheticMethod_ = org.jetbrains.jet.descriptors.serialization.JavaProtoBuf.JavaMethodSignature.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000002);
syntheticMethodName_ = 0;
return this;
}