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,
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;
@@ -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
@@ -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.<TypeParameterDescriptor>emptyList(),
@@ -95,7 +95,8 @@ object DynamicCallableDescriptors {
name,
CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE,
false
/* lateInit = */ false,
/* isConst = */ false
)
propertyDescriptor.setType(
DynamicType,
@@ -61,4 +61,6 @@ public class FakeCallableDescriptorForObject(
override fun getCompileTimeInitializer() = null
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),
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(),
@@ -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
@@ -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();
}
@@ -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<PropertyAccessorDescriptor> 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
@@ -102,4 +102,9 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo
public JetType getReturnType() {
return getType();
}
@Override
public boolean isConst() {
return false;
}
}
@@ -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)
@@ -401,7 +401,8 @@ public class ErrorUtils {
Name.special("<ERROR PROPERTY>"),
CallableMemberDescriptor.Kind.DECLARATION,
SourceElement.NO_SOURCE,
/*lateInit =*/ false
/* lateInit = */ false,
/* isConst = */ false
);
descriptor.setType(ERROR_PROPERTY_TYPE,
Collections.<TypeParameterDescriptor>emptyList(),
@@ -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)
}
}