Serialize/Deserialize const modifier

This commit is contained in:
Denis Zharkov
2015-09-21 16:34:20 +03:00
parent b2b76d16d0
commit 98dd08109d
10 changed files with 69 additions and 9 deletions
@@ -179,10 +179,12 @@ public class DescriptorSerializer {
boolean hasSetter = false;
boolean hasConstant = false;
boolean lateInit = false;
boolean isConst = false;
if (descriptor instanceof PropertyDescriptor) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
lateInit = propertyDescriptor.isLateInit();
isConst = propertyDescriptor.isConst();
int propertyFlags = Flags.getAccessorFlags(
hasAnnotations(propertyDescriptor),
@@ -232,7 +234,8 @@ public class DescriptorSerializer {
hasGetter,
hasSetter,
hasConstant,
lateInit
lateInit,
isConst
));
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) {
+14
View File
@@ -0,0 +1,14 @@
//ALLOW_AST_ACCESS
package test
const private val topLevel = 1
object A {
const protected val inObject = 2
}
class B {
companion object {
const val inCompanion = 3
}
}
@@ -0,0 +1,20 @@
package test
private const val topLevel: kotlin.Int = 1
private fun <get-topLevel>(): kotlin.Int
public object A {
/*primary*/ private constructor A()
protected const final val inObject: kotlin.Int = 2
protected final fun <get-inObject>(): kotlin.Int
}
public final class B {
/*primary*/ public constructor B()
public companion object Companion {
/*primary*/ private constructor Companion()
public const final val inCompanion: kotlin.Int = 3
public final fun <get-inCompanion>(): kotlin.Int
}
}
@@ -4471,6 +4471,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin(fileName);
}
@TestMetadata("Const.kt")
public void testConst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Const.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("Constants.kt")
public void testConstants() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");
@@ -2580,6 +2580,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName);
}
@TestMetadata("Const.kt")
public void testConst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Const.kt");
doTest(fileName);
}
@TestMetadata("Constants.kt")
public void testConstants() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");
@@ -250,6 +250,7 @@ message Callable {
hasGetter
hasSetter
hasConstant
isConst
lateinit
*/
optional int32 flags = 1;
@@ -48,7 +48,9 @@ public class Flags {
public static final FlagField<Boolean> HAS_SETTER = FlagField.booleanAfter(HAS_GETTER);
public static final FlagField<Boolean> HAS_CONSTANT = FlagField.booleanAfter(HAS_SETTER);
public static final FlagField<Boolean> LATE_INIT = FlagField.booleanAfter(HAS_CONSTANT);
public static final FlagField<Boolean> IS_CONST = FlagField.booleanAfter(HAS_CONSTANT);
public static final FlagField<Boolean> LATE_INIT = FlagField.booleanAfter(IS_CONST);
// Parameters
@@ -115,7 +117,8 @@ public class Flags {
boolean hasGetter,
boolean hasSetter,
boolean hasConstant,
boolean lateInit
boolean lateInit,
boolean isConst
) {
return HAS_ANNOTATIONS.toFlags(hasAnnotations)
| MODALITY.toFlags(modality(modality))
@@ -126,6 +129,7 @@ public class Flags {
| HAS_SETTER.toFlags(hasSetter)
| HAS_CONSTANT.toFlags(hasConstant)
| LATE_INIT.toFlags(lateInit)
| IS_CONST.toFlags(isConst)
;
}
@@ -45,8 +45,6 @@ public class MemberDeserializer(private val c: DeserializationContext) {
private fun loadProperty(proto: Callable): PropertyDescriptor {
val flags = proto.getFlags()
val lateInit = Flags.LATE_INIT.get(flags)
val property = DeserializedPropertyDescriptor(
c.containingDeclaration, null,
getAnnotations(proto, flags, AnnotatedCallableKind.PROPERTY),
@@ -57,7 +55,8 @@ public class MemberDeserializer(private val c: DeserializationContext) {
Deserialization.memberKind(Flags.MEMBER_KIND.get(flags)),
proto,
c.nameResolver,
Flags.LATE_INIT.get(flags)
Flags.LATE_INIT.get(flags),
Flags.IS_CONST.get(flags)
)
val local = c.childContext(property, proto.getTypeParameterList())
@@ -39,10 +39,11 @@ public class DeserializedPropertyDescriptor(
kind: Kind,
override public val proto: ProtoBuf.Callable,
override public val nameResolver: NameResolver,
lateInit: Boolean
lateInit: Boolean,
isConst: Boolean
) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations,
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, lateInit, false) {
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, lateInit, isConst) {
override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
@@ -52,6 +53,6 @@ public class DeserializedPropertyDescriptor(
kind: Kind
): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor(
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, proto, nameResolver, isLateInit, false)
newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, proto, nameResolver, isLateInit, isConst)
}
}
@@ -2578,6 +2578,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
doTest(fileName);
}
@TestMetadata("Const.kt")
public void testConst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Const.kt");
doTest(fileName);
}
@TestMetadata("Constants.kt")
public void testConstants() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");