Introduce interface method: VariableDescriptor.isConst

And several default implementations
Also take it into account in renderer
This commit is contained in:
Denis Zharkov
2015-09-21 16:30:11 +03:00
parent 02b64ce1ed
commit bde58d6eb8
13 changed files with 52 additions and 16 deletions
@@ -57,7 +57,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
) { ) {
super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL, super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
original.isVar(), Name.identifier("access$" + getIndexedAccessorSuffix(original, index)), 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.calleeDescriptor = original;
this.accessorIndex = index; this.accessorIndex = index;
@@ -261,7 +261,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : JetScopeImp
kind: CallableMemberDescriptor.Kind, kind: CallableMemberDescriptor.Kind,
source: SourceElement source: SourceElement
) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations, ) : 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() override var getMethod: FunctionDescriptor by Delegates.notNull()
private set private set
@@ -645,7 +645,8 @@ public class DescriptorResolver {
JetPsiUtil.safeName(variable.getName()), JetPsiUtil.safeName(variable.getName()),
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
toSourceElement(variable), toSourceElement(variable),
false /* lateInit = */ false,
/* isConst = */ false
); );
// For a local variable the type must not be deferred // For a local variable the type must not be deferred
type = getVariableType(propertyDescriptor, scope, variable, dataFlowInfo, false, trace); type = getVariableType(propertyDescriptor, scope, variable, dataFlowInfo, false, trace);
@@ -743,7 +744,8 @@ public class DescriptorResolver {
JetPsiUtil.safeName(property.getName()), JetPsiUtil.safeName(property.getName()),
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
toSourceElement(property), 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); wrapper.setProperty(propertyDescriptor);
@@ -1114,7 +1116,8 @@ public class DescriptorResolver {
name, name,
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
toSourceElement(parameter), toSourceElement(parameter),
false /* lateInit = */ false,
/* isConst = */ false
); );
propertyWrapper.setProperty(propertyDescriptor); propertyWrapper.setProperty(propertyDescriptor);
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(), propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
@@ -95,7 +95,8 @@ object DynamicCallableDescriptors {
name, name,
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE, SourceElement.NO_SOURCE,
false /* lateInit = */ false,
/* isConst = */ false
) )
propertyDescriptor.setType( propertyDescriptor.setType(
DynamicType, DynamicType,
@@ -61,4 +61,6 @@ public class FakeCallableDescriptorForObject(
override fun getCompileTimeInitializer() = null override fun getCompileTimeInitializer() = null
override fun getSource(): SourceElement = classDescriptor.getSource() override fun getSource(): SourceElement = classDescriptor.getSource()
override fun isConst(): Boolean = false
} }
@@ -93,7 +93,8 @@ public class LazyScriptClassMemberScope protected constructor(
Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME), Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME),
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE, SourceElement.NO_SOURCE,
false /* lateInit = */ false,
/* isConst = */ false
) )
val returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType() val returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType()
@@ -134,7 +135,8 @@ public class LazyScriptClassMemberScope protected constructor(
parameter.getName(), parameter.getName(),
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE, SourceElement.NO_SOURCE,
false /* lateInit = */ false,
/* isConst = */ false
) )
propertyDescriptor.setType( propertyDescriptor.setType(
parameter.getType(), parameter.getType(),
@@ -36,7 +36,8 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
@NotNull SourceElement source, @NotNull SourceElement source,
@Nullable PropertyDescriptor original @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 @Override
@@ -37,4 +37,10 @@ public interface VariableDescriptor extends CallableDescriptor {
@Nullable @Nullable
ConstantValue<?> getCompileTimeInitializer(); 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();
} }
@@ -40,6 +40,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
private final PropertyDescriptor original; private final PropertyDescriptor original;
private final Kind kind; private final Kind kind;
private final boolean lateInit; private final boolean lateInit;
private final boolean isConst;
private ReceiverParameterDescriptor dispatchReceiverParameter; private ReceiverParameterDescriptor dispatchReceiverParameter;
private ReceiverParameterDescriptor extensionReceiverParameter; private ReceiverParameterDescriptor extensionReceiverParameter;
@@ -58,7 +59,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
@NotNull Name name, @NotNull Name name,
@NotNull Kind kind, @NotNull Kind kind,
@NotNull SourceElement source, @NotNull SourceElement source,
boolean lateInit boolean lateInit,
boolean isConst
) { ) {
super(containingDeclaration, annotations, name, null, isVar, source); super(containingDeclaration, annotations, name, null, isVar, source);
this.modality = modality; this.modality = modality;
@@ -66,6 +68,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
this.original = original == null ? this : original; this.original = original == null ? this : original;
this.kind = kind; this.kind = kind;
this.lateInit = lateInit; this.lateInit = lateInit;
this.isConst = isConst;
} }
@NotNull @NotNull
@@ -78,10 +81,11 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
@NotNull Name name, @NotNull Name name,
@NotNull Kind kind, @NotNull Kind kind,
@NotNull SourceElement source, @NotNull SourceElement source,
boolean lateInit boolean lateInit,
boolean isConst
) { ) {
return new PropertyDescriptorImpl(containingDeclaration, null, annotations, return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
modality, visibility, isVar, name, kind, source, lateInit); modality, visibility, isVar, name, kind, source, lateInit, isConst);
} }
public void setType( public void setType(
@@ -179,6 +183,11 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
return lateInit; return lateInit;
} }
@Override
public boolean isConst() {
return isConst;
}
@Override @Override
@NotNull @NotNull
public List<PropertyAccessorDescriptor> getAccessors() { public List<PropertyAccessorDescriptor> getAccessors() {
@@ -300,7 +309,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
) { ) {
return new PropertyDescriptorImpl(newOwner, original, return new PropertyDescriptorImpl(newOwner, original,
getAnnotations(), newModality, newVisibility, getAnnotations(), newModality, newVisibility,
isVar(), getName(), kind, SourceElement.NO_SOURCE, isLateInit()); isVar(), getName(), kind, SourceElement.NO_SOURCE, isLateInit(), isConst());
} }
@NotNull @NotNull
@@ -102,4 +102,9 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo
public JetType getReturnType() { public JetType getReturnType() {
return getType(); return getType();
} }
@Override
public boolean isConst() {
return false;
}
} }
@@ -707,6 +707,11 @@ internal class DescriptorRendererImpl(
if (!startFromName) { if (!startFromName) {
renderAnnotations(property, builder) renderAnnotations(property, builder)
renderVisibility(property.getVisibility(), builder) renderVisibility(property.getVisibility(), builder)
if (property.isConst) {
builder.append("const ")
}
renderModalityForCallable(property, builder) renderModalityForCallable(property, builder)
renderOverride(property, builder) renderOverride(property, builder)
renderLateInit(property, builder) renderLateInit(property, builder)
@@ -401,7 +401,8 @@ public class ErrorUtils {
Name.special("<ERROR PROPERTY>"), Name.special("<ERROR PROPERTY>"),
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE, SourceElement.NO_SOURCE,
/*lateInit =*/ false /* lateInit = */ false,
/* isConst = */ false
); );
descriptor.setType(ERROR_PROPERTY_TYPE, descriptor.setType(ERROR_PROPERTY_TYPE,
Collections.<TypeParameterDescriptor>emptyList(), Collections.<TypeParameterDescriptor>emptyList(),
@@ -42,7 +42,7 @@ public class DeserializedPropertyDescriptor(
lateInit: Boolean lateInit: Boolean
) : DeserializedCallableMemberDescriptor, ) : DeserializedCallableMemberDescriptor,
PropertyDescriptorImpl(containingDeclaration, original, annotations, 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( override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor, newOwner: DeclarationDescriptor,
@@ -52,6 +52,6 @@ public class DeserializedPropertyDescriptor(
kind: Kind kind: Kind
): PropertyDescriptorImpl { ): PropertyDescriptorImpl {
return DeserializedPropertyDescriptor( 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)
} }
} }