Introduce PropertyDescriptor.isDelegated, write new flag to metadata

#KT-8384 In Progress
This commit is contained in:
Alexander Udalov
2017-01-17 20:08:19 +03:00
parent 76fc3b40d5
commit f1cd2ee6fd
24 changed files with 111 additions and 43 deletions
@@ -33,7 +33,7 @@ import java.util.List;
public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements JavaCallableMemberDescriptor {
private final boolean isStaticFinal;
protected JavaPropertyDescriptor(
private JavaPropertyDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Annotations annotations,
@NotNull Modality modality,
@@ -46,7 +46,7 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
boolean isStaticFinal
) {
super(containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
/* lateInit = */ false, /* isConst = */ false, /* isHeader = */ false, /* isImpl = */ false, /* isExternal = */ false);
false, false, false, false, false, false);
this.isStaticFinal = isStaticFinal;
}
@@ -16,7 +16,18 @@
package org.jetbrains.kotlin.descriptors
public interface VariableDescriptorWithAccessors : VariableDescriptor {
public val getter: VariableAccessorDescriptor?
public val setter: VariableAccessorDescriptor?
}
interface VariableDescriptorWithAccessors : VariableDescriptor {
val getter: VariableAccessorDescriptor?
val setter: VariableAccessorDescriptor?
/**
* Please be careful with this method. Depending on the fact that a property is delegated may be dangerous in the compiler.
* Whether or not a property is delegated is neither the API or the ABI of that property, and one should be able to recompile a library
* in a way that makes some non-delegated properties delegated or vice versa, without any problems at compilation time or at runtime.
*
* This flag is needed for reflection however, that's why it's serialized to metadata and is exposed in this interface.
*/
@Deprecated("Do not call this method in the compiler front-end.")
val isDelegated: Boolean
}
@@ -47,6 +47,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
private final boolean isHeader;
private final boolean isImpl;
private final boolean isExternal;
private final boolean isDelegated;
private ReceiverParameterDescriptor dispatchReceiverParameter;
private ReceiverParameterDescriptor extensionReceiverParameter;
@@ -69,7 +70,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
boolean isConst,
boolean isHeader,
boolean isImpl,
boolean isExternal
boolean isExternal,
boolean isDelegated
) {
super(containingDeclaration, annotations, name, null, isVar, source);
this.modality = modality;
@@ -81,6 +83,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
this.isHeader = isHeader;
this.isImpl = isImpl;
this.isExternal = isExternal;
this.isDelegated = isDelegated;
}
@NotNull
@@ -97,11 +100,12 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
boolean isConst,
boolean isHeader,
boolean isImpl,
boolean isExternal
boolean isExternal,
boolean isDelegated
) {
return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
modality, visibility, isVar, name, kind, source, lateInit, isConst,
isHeader, isImpl, isExternal);
isHeader, isImpl, isExternal, isDelegated);
}
public void setType(
@@ -209,6 +213,11 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
return isExternal;
}
@Override
public boolean isDelegated() {
return isDelegated;
}
@Override
@NotNull
public List<PropertyAccessorDescriptor> getAccessors() {
@@ -353,7 +362,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
) {
return new PropertyDescriptorImpl(
newOwner, original, getAnnotations(), newModality, newVisibility, isVar(), getName(), kind, SourceElement.NO_SOURCE,
isLateInit(), isConst(), isHeader(), isImpl(), isExternal()
isLateInit(), isConst(), isHeader(), isImpl(), isExternal(), isDelegated()
);
}
@@ -379,11 +379,7 @@ public class ErrorUtils {
Name.special("<ERROR PROPERTY>"),
CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE,
/* lateInit = */ false,
/* isConst = */ false,
/* isHeader = */ false,
/* isImpl = */ false,
/* isExternal = */ false
false, false, false, false, false, false
);
descriptor.setType(ERROR_PROPERTY_TYPE,
Collections.<TypeParameterDescriptor>emptyList(),
@@ -301,6 +301,8 @@ message Property {
isConst
lateinit
hasConstant
isExternal
isDelegated
*/
optional int32 flags = 11 [default = 518 /* public (6) final property with getter (512) */];
optional int32 old_flags = 1 [default = 2054];
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.protobuf.Internal;
import org.jetbrains.kotlin.types.KotlinType;
public class Flags {
private Flags() {}
@@ -67,6 +66,7 @@ public class Flags {
public static final BooleanFlagField IS_LATEINIT = FlagField.booleanAfter(IS_CONST);
public static final BooleanFlagField HAS_CONSTANT = FlagField.booleanAfter(IS_LATEINIT);
public static final BooleanFlagField IS_EXTERNAL_PROPERTY = FlagField.booleanAfter(HAS_CONSTANT);
public static final BooleanFlagField IS_DELEGATED = FlagField.booleanAfter(IS_EXTERNAL_PROPERTY);
// Parameters
@@ -173,7 +173,8 @@ public class Flags {
boolean hasConstant,
boolean isConst,
boolean lateInit,
boolean isExternal
boolean isExternal,
boolean isDelegated
) {
return HAS_ANNOTATIONS.toFlags(hasAnnotations)
| VISIBILITY.toFlags(visibility(visibility))
@@ -186,6 +187,7 @@ public class Flags {
| IS_LATEINIT.toFlags(lateInit)
| HAS_CONSTANT.toFlags(hasConstant)
| IS_EXTERNAL_PROPERTY.toFlags(isExternal)
| IS_DELEGATED.toFlags(isDelegated)
;
}
@@ -15322,6 +15322,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
boolean hasFlags();
@@ -15339,6 +15341,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
int getFlags();
@@ -15664,6 +15668,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public boolean hasFlags() {
@@ -15683,6 +15689,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public int getFlags() {
@@ -16371,6 +16379,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public boolean hasFlags() {
@@ -16390,6 +16400,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public int getFlags() {
@@ -16409,6 +16421,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public Builder setFlags(int value) {
@@ -16431,6 +16445,8 @@ public final class ProtoBuf {
*isConst
*lateinit
*hasConstant
*isExternal
*isDelegated
* </pre>
*/
public Builder clearFlags() {
@@ -47,6 +47,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
Flags.IS_LATEINIT.get(flags),
Flags.IS_CONST.get(flags),
Flags.IS_EXTERNAL_PROPERTY.get(flags),
Flags.IS_DELEGATED.get(flags),
proto,
c.nameResolver,
c.typeTable,
@@ -105,6 +105,7 @@ class DeserializedPropertyDescriptor(
isLateInit: Boolean,
isConst: Boolean,
isExternal: Boolean,
isDelegated: Boolean,
override val proto: ProtoBuf.Property,
override val nameResolver: NameResolver,
override val typeTable: TypeTable,
@@ -113,7 +114,7 @@ class DeserializedPropertyDescriptor(
) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst, false, false,
isExternal) {
isExternal, isDelegated) {
override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
@@ -124,6 +125,7 @@ class DeserializedPropertyDescriptor(
): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor(
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, isLateInit, isConst, isExternal,
@Suppress("DEPRECATION") isDelegated,
proto, nameResolver, typeTable, sinceKotlinInfoTable, containerSource
)
}