diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java index ad16c00293b..0b4cd85a451 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java @@ -57,7 +57,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem ) { super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL, original.isVar(), Name.identifier("access$" + getIndexedAccessorSuffix(original, index)), - Kind.DECLARATION, SourceElement.NO_SOURCE, false); + Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false); this.calleeDescriptor = original; this.accessorIndex = index; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 66a3a34c0e9..5d6ac561514 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -261,7 +261,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : JetScopeImp kind: CallableMemberDescriptor.Kind, source: SourceElement ) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations, - modality, visibility, isVar, name, kind, source, false) { + modality, visibility, isVar, name, kind, source, + /* lateInit = */ false, /* isConst = */ false) { override var getMethod: FunctionDescriptor by Delegates.notNull() private set diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 76054ee52c4..b191e952af8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -645,7 +645,8 @@ public class DescriptorResolver { JetPsiUtil.safeName(variable.getName()), CallableMemberDescriptor.Kind.DECLARATION, toSourceElement(variable), - false + /* lateInit = */ false, + /* isConst = */ false ); // For a local variable the type must not be deferred type = getVariableType(propertyDescriptor, scope, variable, dataFlowInfo, false, trace); @@ -743,7 +744,8 @@ public class DescriptorResolver { JetPsiUtil.safeName(property.getName()), CallableMemberDescriptor.Kind.DECLARATION, toSourceElement(property), - modifierList != null && modifierList.hasModifier(JetTokens.LATE_INIT_KEYWORD) + modifierList != null && modifierList.hasModifier(JetTokens.LATE_INIT_KEYWORD), + modifierList != null && modifierList.hasModifier(JetTokens.CONST_KEYWORD) ); wrapper.setProperty(propertyDescriptor); @@ -1114,7 +1116,8 @@ public class DescriptorResolver { name, CallableMemberDescriptor.Kind.DECLARATION, toSourceElement(parameter), - false + /* lateInit = */ false, + /* isConst = */ false ); propertyWrapper.setProperty(propertyDescriptor); propertyDescriptor.setType(type, Collections.emptyList(), diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt index c71951d58fc..71552c34e5b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt @@ -95,7 +95,8 @@ object DynamicCallableDescriptors { name, CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - false + /* lateInit = */ false, + /* isConst = */ false ) propertyDescriptor.setType( DynamicType, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/FakeCallableDescriptorForObject.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/FakeCallableDescriptorForObject.kt index 8ba9e0bc3a7..bd4706cb066 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/FakeCallableDescriptorForObject.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/FakeCallableDescriptorForObject.kt @@ -61,4 +61,6 @@ public class FakeCallableDescriptorForObject( override fun getCompileTimeInitializer() = null override fun getSource(): SourceElement = classDescriptor.getSource() + + override fun isConst(): Boolean = false } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt index 9f36b9afb1b..c0dc722c6d0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt @@ -93,7 +93,8 @@ public class LazyScriptClassMemberScope protected constructor( Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - false + /* lateInit = */ false, + /* isConst = */ false ) val returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType() @@ -134,7 +135,8 @@ public class LazyScriptClassMemberScope protected constructor( parameter.getName(), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - false + /* lateInit = */ false, + /* isConst = */ false ) propertyDescriptor.setType( parameter.getType(), diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java index afc762cf76d..0084fb0a57e 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java @@ -36,7 +36,8 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja @NotNull SourceElement source, @Nullable PropertyDescriptor original ) { - super(containingDeclaration, original, annotations, Modality.FINAL, visibility, isVar, name, Kind.DECLARATION, source, false); + super(containingDeclaration, original, annotations, Modality.FINAL, visibility, isVar, name, Kind.DECLARATION, source, + /* lateInit = */ false, /* isConst = */ false); } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/VariableDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/VariableDescriptor.java index 0cc1b7c6080..8d069a454b0 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/VariableDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/VariableDescriptor.java @@ -37,4 +37,10 @@ public interface VariableDescriptor extends CallableDescriptor { @Nullable ConstantValue getCompileTimeInitializer(); + + /** + * @return true if iff original declaration has appropriate flags and type, e.g. `const` modifier in Kotlin. + * It completely does not means that if isConst then `getCompileTimeInitializer` is not null + */ + boolean isConst(); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index dc4ab786104..a9faefb0c91 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -40,6 +40,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp private final PropertyDescriptor original; private final Kind kind; private final boolean lateInit; + private final boolean isConst; private ReceiverParameterDescriptor dispatchReceiverParameter; private ReceiverParameterDescriptor extensionReceiverParameter; @@ -58,7 +59,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp @NotNull Name name, @NotNull Kind kind, @NotNull SourceElement source, - boolean lateInit + boolean lateInit, + boolean isConst ) { super(containingDeclaration, annotations, name, null, isVar, source); this.modality = modality; @@ -66,6 +68,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp this.original = original == null ? this : original; this.kind = kind; this.lateInit = lateInit; + this.isConst = isConst; } @NotNull @@ -78,10 +81,11 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp @NotNull Name name, @NotNull Kind kind, @NotNull SourceElement source, - boolean lateInit + boolean lateInit, + boolean isConst ) { return new PropertyDescriptorImpl(containingDeclaration, null, annotations, - modality, visibility, isVar, name, kind, source, lateInit); + modality, visibility, isVar, name, kind, source, lateInit, isConst); } public void setType( @@ -179,6 +183,11 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp return lateInit; } + @Override + public boolean isConst() { + return isConst; + } + @Override @NotNull public List getAccessors() { @@ -300,7 +309,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp ) { return new PropertyDescriptorImpl(newOwner, original, getAnnotations(), newModality, newVisibility, - isVar(), getName(), kind, SourceElement.NO_SOURCE, isLateInit()); + isVar(), getName(), kind, SourceElement.NO_SOURCE, isLateInit(), isConst()); } @NotNull diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/VariableDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/VariableDescriptorImpl.java index ae08b5a0df9..afdc97e96f1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/VariableDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/VariableDescriptorImpl.java @@ -102,4 +102,9 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo public JetType getReturnType() { return getType(); } + + @Override + public boolean isConst() { + return false; + } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 8dfb9ae5393..f4341f1088d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -707,6 +707,11 @@ internal class DescriptorRendererImpl( if (!startFromName) { renderAnnotations(property, builder) renderVisibility(property.getVisibility(), builder) + + if (property.isConst) { + builder.append("const ") + } + renderModalityForCallable(property, builder) renderOverride(property, builder) renderLateInit(property, builder) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index e16d8b3ff5e..b16475a1269 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -401,7 +401,8 @@ public class ErrorUtils { Name.special(""), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - /*lateInit =*/ false + /* lateInit = */ false, + /* isConst = */ false ); descriptor.setType(ERROR_PROPERTY_TYPE, Collections.emptyList(), diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPropertyDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPropertyDescriptor.kt index 673a3dd7f8d..54fd8f6cd3f 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPropertyDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPropertyDescriptor.kt @@ -42,7 +42,7 @@ public class DeserializedPropertyDescriptor( lateInit: Boolean ) : DeserializedCallableMemberDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations, - modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, lateInit) { + modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, lateInit, false) { override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, @@ -52,6 +52,6 @@ public class DeserializedPropertyDescriptor( kind: Kind ): PropertyDescriptorImpl { return DeserializedPropertyDescriptor( - newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, proto, nameResolver, isLateInit) + newOwner, original, annotations, newModality, newVisibility, isVar, name, kind, proto, nameResolver, isLateInit, false) } }