Deserialize annotations on class object properties
Class object properties' backing fields are generated into static fields of the containing class, not into fields of class object. For fields we now store the flag which, if set, tells that this field should be looked for in the containing class
This commit is contained in:
committed by
Pavel V. Talanov
parent
32c5624531
commit
19299daacd
@@ -66,19 +66,23 @@ public class JavaSerializerExtension extends SerializerExtension {
|
||||
Pair<Type, String> field = memberMap.getFieldOfProperty(property);
|
||||
Type fieldType;
|
||||
String fieldName;
|
||||
boolean isStaticInOuter;
|
||||
String syntheticMethodName;
|
||||
if (field != null) {
|
||||
fieldType = field.first;
|
||||
fieldName = field.second;
|
||||
isStaticInOuter = memberMap.isStaticFieldInOuterClass(property);
|
||||
syntheticMethodName = null;
|
||||
}
|
||||
else {
|
||||
fieldType = null;
|
||||
fieldName = null;
|
||||
isStaticInOuter = false;
|
||||
syntheticMethodName = memberMap.getSyntheticMethodNameOfProperty(property);
|
||||
}
|
||||
|
||||
JavaProtoBufUtil.savePropertySignature(proto, fieldType, fieldName, syntheticMethodName, getterMethod, setterMethod, nameTable);
|
||||
JavaProtoBufUtil.savePropertySignature(proto, fieldType, fieldName, isStaticInOuter, syntheticMethodName, getterMethod,
|
||||
setterMethod, nameTable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,15 +26,14 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public final class MemberMap {
|
||||
private final Map<FunctionDescriptor, Method> methodForFunction = new HashMap<FunctionDescriptor, Method>();
|
||||
private final Map<PropertyDescriptor, Pair<Type, String>> fieldForProperty = new HashMap<PropertyDescriptor, Pair<Type, String>>();
|
||||
private final Map<PropertyDescriptor, String> syntheticMethodNameForProperty = new HashMap<PropertyDescriptor, String>();
|
||||
private final Map<CallableMemberDescriptor, Name> srcClassNameForCallable = new HashMap<CallableMemberDescriptor, Name>();
|
||||
private final Set<PropertyDescriptor> staticFieldInOuterClass = new HashSet<PropertyDescriptor>();
|
||||
|
||||
@NotNull
|
||||
public static MemberMap union(@NotNull Collection<MemberMap> maps) {
|
||||
@@ -55,6 +54,10 @@ public final class MemberMap {
|
||||
for (Map.Entry<CallableMemberDescriptor, Name> entry : map.srcClassNameForCallable.entrySet()) {
|
||||
result.recordSrcClassNameForCallable(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
for (PropertyDescriptor property : map.staticFieldInOuterClass) {
|
||||
result.recordStaticFieldInOuterClass(property);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -80,6 +83,11 @@ public final class MemberMap {
|
||||
assert old == null : "Duplicate src class name for callable: " + descriptor + "; " + old;
|
||||
}
|
||||
|
||||
public void recordStaticFieldInOuterClass(@NotNull PropertyDescriptor property) {
|
||||
boolean added = staticFieldInOuterClass.add(property);
|
||||
assert added : "Duplicate static field in outer class: " + property;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Method getMethodOfDescriptor(@NotNull FunctionDescriptor descriptor) {
|
||||
return methodForFunction.get(descriptor);
|
||||
@@ -100,6 +108,10 @@ public final class MemberMap {
|
||||
return srcClassNameForCallable.get(descriptor);
|
||||
}
|
||||
|
||||
public boolean isStaticFieldInOuterClass(@NotNull PropertyDescriptor property) {
|
||||
return staticFieldInOuterClass.contains(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Functions: " + methodForFunction.size() +
|
||||
|
||||
@@ -180,6 +180,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
ImplementationBodyCodegen codegen = getParentBodyCodegen(classBodyCodegen);
|
||||
builder = codegen.v;
|
||||
backingFieldContext = codegen.context;
|
||||
v.getMemberMap().recordStaticFieldInOuterClass(propertyDescriptor);
|
||||
} else {
|
||||
if (kind != OwnerKind.NAMESPACE || isDelegate) {
|
||||
modifiers |= ACC_PRIVATE;
|
||||
@@ -193,7 +194,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
|
||||
String name = backingFieldContext.getFieldName(propertyDescriptor, isDelegate);
|
||||
|
||||
builder.getMemberMap().recordFieldOfProperty(propertyDescriptor, type, name);
|
||||
v.getMemberMap().recordFieldOfProperty(propertyDescriptor, type, name);
|
||||
|
||||
return builder.newField(element, modifiers, name, type.getDescriptor(),
|
||||
typeMapper.mapFieldSignature(jetType), defaultValue);
|
||||
|
||||
Reference in New Issue
Block a user