companionObjectType --> classValueType

(NB: it IS NOT a companion object in case of OBJECT or ENUM_ENTRY)
Unify related names.
This commit is contained in:
Dmitry Petrov
2015-11-17 18:23:27 +03:00
parent 7b432c878a
commit 99b411c8ca
9 changed files with 36 additions and 35 deletions
@@ -426,7 +426,7 @@ public abstract class AnnotationCodegen {
for (ConstantValue<?> value : values) { for (ConstantValue<?> value : values) {
if (value instanceof EnumValue) { if (value instanceof EnumValue) {
ClassDescriptor enumEntry = ((EnumValue) value).getValue(); ClassDescriptor enumEntry = ((EnumValue) value).getValue();
KotlinType classObjectType = DescriptorUtilsKt.getCompanionObjectType(enumEntry); KotlinType classObjectType = DescriptorUtilsKt.getClassValueType(enumEntry);
if (classObjectType != null) { if (classObjectType != null) {
if ("java/lang/annotation/ElementType".equals(typeMapper.mapType(classObjectType).getInternalName())) { if ("java/lang/annotation/ElementType".equals(typeMapper.mapType(classObjectType).getInternalName())) {
result.add(ElementType.valueOf(enumEntry.getName().asString())); result.add(ElementType.valueOf(enumEntry.getName().asString()));
@@ -454,7 +454,7 @@ public abstract class AnnotationCodegen {
ConstantValue<?> compileTimeConstant = valueArguments.iterator().next(); ConstantValue<?> compileTimeConstant = valueArguments.iterator().next();
if (compileTimeConstant instanceof EnumValue) { if (compileTimeConstant instanceof EnumValue) {
ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue(); ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue();
KotlinType classObjectType = DescriptorUtilsKt.getCompanionObjectType(enumEntry); KotlinType classObjectType = DescriptorUtilsKt.getClassValueType(enumEntry);
if (classObjectType != null) { if (classObjectType != null) {
if ("java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName())) { if ("java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName())) {
return RetentionPolicy.valueOf(enumEntry.getName().asString()); return RetentionPolicy.valueOf(enumEntry.getName().asString());
@@ -19,7 +19,8 @@ package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.resolve.descriptorUtil.classValueDescriptor import org.jetbrains.kotlin.resolve.descriptorUtil.classValueDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType import org.jetbrains.kotlin.resolve.descriptorUtil.classValueTypeDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.hasCompanionObject
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassifierQualifier import org.jetbrains.kotlin.resolve.scopes.receivers.ClassifierQualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.PackageQualifier import org.jetbrains.kotlin.resolve.scopes.receivers.PackageQualifier
@@ -27,7 +28,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
public fun resolveQualifierAsReceiverInExpression( public fun resolveQualifierAsReceiverInExpression(
qualifier: Qualifier, qualifier: Qualifier,
selector: DeclarationDescriptor?, selector: DeclarationDescriptor?,
@@ -96,17 +96,20 @@ private fun resolveQualifierReferenceTarget(
val classifier = qualifier.classifier val classifier = qualifier.classifier
val selectorIsCallable = selector is CallableDescriptor && val selectorIsCallable = selector is CallableDescriptor &&
(selector.dispatchReceiverParameter != null || selector.extensionReceiverParameter != null) (selector.dispatchReceiverParameter != null || selector.extensionReceiverParameter != null)
val referenceTarget = classifier.classValueDescriptor // TODO simplify this code.
if (selectorIsCallable && referenceTarget != null) { // Given a class qualifier in expression position,
val classObjectType = classifier.companionObjectType!! // it should provide a proper REFERENCE_TARGET (with type),
val classObjectDescriptor = DescriptorUtils.getClassDescriptorForType(classObjectType) // and, in case of implicit companion object reference, SHORT_REFERENCE_TO_COMPANION_OBJECT.
context.trace.record(BindingContext.REFERENCE_TARGET, qualifier.referenceExpression, referenceTarget) val classValueDescriptor = classifier.classValueDescriptor
context.trace.recordType(qualifier.expression, classObjectType) if (selectorIsCallable && classValueDescriptor != null) {
if (classifier.companionObjectDescriptor != null) { val classValueTypeDescriptor = classifier.classValueTypeDescriptor!!
context.trace.record(BindingContext.REFERENCE_TARGET, qualifier.referenceExpression, classValueDescriptor)
context.trace.recordType(qualifier.expression, classValueTypeDescriptor.defaultType)
if (classifier.hasCompanionObject) {
context.trace.record(BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, qualifier.referenceExpression, classifier) context.trace.record(BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, qualifier.referenceExpression, classifier)
symbolUsageValidator.validateTypeUsage(referenceTarget, context.trace, qualifier.referenceExpression) symbolUsageValidator.validateTypeUsage(classValueDescriptor, context.trace, qualifier.referenceExpression)
} }
return classObjectDescriptor return classValueTypeDescriptor
} }
} }
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils.isStaticNestedClass
import org.jetbrains.kotlin.resolve.LibrarySourceHacks import org.jetbrains.kotlin.resolve.LibrarySourceHacks
import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.descriptorUtil.hasCompanionObject import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope
@@ -187,13 +187,13 @@ private object VariableCollector : CallableDescriptorCollector<VariableDescripto
private fun getContributedFakeDescriptorForObject(scope: LexicalScope, name: Name, location: LookupLocation): VariableDescriptor? { private fun getContributedFakeDescriptorForObject(scope: LexicalScope, name: Name, location: LookupLocation): VariableDescriptor? {
val classifier = scope.getContributedClassifier(name, location) val classifier = scope.getContributedClassifier(name, location)
if (classifier !is ClassDescriptor || !classifier.hasCompanionObject) return null if (classifier !is ClassDescriptor || !classifier.hasClassValueDescriptor) return null
return FakeCallableDescriptorForObject(classifier) return FakeCallableDescriptorForObject(classifier)
} }
private fun findFakeDescriptorForObject(scope: HierarchicalScope, name: Name, location: LookupLocation): VariableDescriptor? { private fun findFakeDescriptorForObject(scope: HierarchicalScope, name: Name, location: LookupLocation): VariableDescriptor? {
val classifier = scope.findClassifier(name, location) val classifier = scope.findClassifier(name, location)
if (classifier !is ClassDescriptor || !classifier.hasCompanionObject) return null if (classifier !is ClassDescriptor || !classifier.hasClassValueDescriptor) return null
return FakeCallableDescriptorForObject(classifier) return FakeCallableDescriptorForObject(classifier)
} }
@@ -17,9 +17,9 @@
package org.jetbrains.kotlin.resolve.calls.util package org.jetbrains.kotlin.resolve.calls.util
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
import org.jetbrains.kotlin.resolve.descriptorUtil.getClassObjectReferenceTarget import org.jetbrains.kotlin.resolve.descriptorUtil.getClassObjectReferenceTarget
import org.jetbrains.kotlin.resolve.descriptorUtil.hasCompanionObject import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import java.util.Collections import java.util.Collections
@@ -28,7 +28,7 @@ public class FakeCallableDescriptorForObject(
) : DeclarationDescriptorWithVisibility by classDescriptor.getClassObjectReferenceTarget(), VariableDescriptor { ) : DeclarationDescriptorWithVisibility by classDescriptor.getClassObjectReferenceTarget(), VariableDescriptor {
init { init {
assert(classDescriptor.hasCompanionObject) { assert(classDescriptor.hasClassValueDescriptor) {
"FakeCallableDescriptorForObject can be created only for objects, classes with companion object or enum entries: $classDescriptor" "FakeCallableDescriptorForObject can be created only for objects, classes with companion object or enum entries: $classDescriptor"
} }
@@ -52,7 +52,7 @@ public class FakeCallableDescriptorForObject(
override fun getOverriddenDescriptors(): Set<CallableDescriptor> = Collections.emptySet() override fun getOverriddenDescriptors(): Set<CallableDescriptor> = Collections.emptySet()
override fun getType(): KotlinType = classDescriptor.companionObjectType!! override fun getType(): KotlinType = classDescriptor.classValueType!!
override fun isVar() = false override fun isVar() = false
@@ -22,11 +22,7 @@ import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.psi.psiUtil.getTopmostParentQualifiedExpressionForSelector import org.jetbrains.kotlin.psi.psiUtil.getTopmostParentQualifiedExpressionForSelector
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContext.* import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
import org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType
import org.jetbrains.kotlin.resolve.descriptorUtil.hasCompanionObject
import org.jetbrains.kotlin.resolve.scopes.ChainedScope import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.FilteringScope import org.jetbrains.kotlin.resolve.scopes.FilteringScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
@@ -105,7 +101,7 @@ class ClassQualifier(
val scopes = ArrayList<MemberScope>(3) val scopes = ArrayList<MemberScope>(3)
val classObjectTypeScope = classifier.companionObjectType?.memberScope?.let { val classObjectTypeScope = classifier.classValueType?.memberScope?.let {
FilteringScope(it) { it !is ClassDescriptor } FilteringScope(it) { it !is ClassDescriptor }
} }
scopes.addIfNotNull(classObjectTypeScope) scopes.addIfNotNull(classObjectTypeScope)
@@ -143,7 +139,7 @@ fun createClassifierQualifier(
classifier: ClassifierDescriptor, classifier: ClassifierDescriptor,
bindingContext: BindingContext bindingContext: BindingContext
): ClassifierQualifier { ): ClassifierQualifier {
val companionObjectReceiver = (classifier as? ClassDescriptor)?.companionObjectType?.let { val companionObjectReceiver = (classifier as? ClassDescriptor)?.classValueType?.let {
ExpressionReceiver.create(referenceExpression, it, bindingContext) ExpressionReceiver.create(referenceExpression, it, bindingContext)
} }
return if (classifier is ClassDescriptor) return if (classifier is ClassDescriptor)
@@ -71,7 +71,9 @@ public val ClassDescriptor.classId: ClassId
throw IllegalStateException("Illegal container: $owner") throw IllegalStateException("Illegal container: $owner")
} }
public val ClassDescriptor.hasCompanionObject: Boolean get() = companionObjectType != null public val ClassDescriptor.hasCompanionObject: Boolean get() = companionObjectDescriptor != null
public val ClassDescriptor.hasClassValueDescriptor: Boolean get() = classValueDescriptor != null
public val ClassDescriptor.classValueDescriptor: ClassDescriptor? public val ClassDescriptor.classValueDescriptor: ClassDescriptor?
get() = if (kind.isSingleton) this else companionObjectDescriptor get() = if (kind.isSingleton) this else companionObjectDescriptor
@@ -89,7 +91,7 @@ public val ClassDescriptor.classValueTypeDescriptor: ClassDescriptor?
} }
/** If a literal of this class can be used as a value, returns the type of this value */ /** If a literal of this class can be used as a value, returns the type of this value */
public val ClassDescriptor.companionObjectType: KotlinType? public val ClassDescriptor.classValueType: KotlinType?
get() = classValueTypeDescriptor?.getDefaultType() get() = classValueTypeDescriptor?.getDefaultType()
public val DeclarationDescriptorWithVisibility.isEffectivelyPublicApi: Boolean public val DeclarationDescriptorWithVisibility.isEffectivelyPublicApi: Boolean
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.utils.sure
@@ -141,7 +141,7 @@ public class EnumValue(
) : ConstantValue<ClassDescriptor>(value) { ) : ConstantValue<ClassDescriptor>(value) {
override val type: KotlinType override val type: KotlinType
get() = value.companionObjectType.sure { "Enum entry must have a class object type: " + value } get() = value.classValueType.sure { "Enum entry must have a class object type: " + value }
override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitEnumValue(this, data) override fun <R, D> accept(visitor: AnnotationArgumentVisitor<R, D>, data: D) = visitor.visitEnumValue(this, data)
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
@@ -252,7 +252,7 @@ public fun CallTypeAndReceiver<*, *>.receiverTypes(
val receiverType = val receiverType =
bindingContext.getType(receiverExpression) ?: bindingContext.getType(receiverExpression) ?:
(bindingContext.get(BindingContext.QUALIFIER, receiverExpression) as? ClassQualifier)?.let { (bindingContext.get(BindingContext.QUALIFIER, receiverExpression) as? ClassQualifier)?.let {
it.classifier.companionObjectType it.classifier.classValueType
} ?: } ?:
return emptyList() return emptyList()
listOf(ExpressionReceiver.create(receiverExpression, receiverType, bindingContext)) listOf(ExpressionReceiver.create(receiverExpression, receiverType, bindingContext))
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.companionObjectType import org.jetbrains.kotlin.resolve.descriptorUtil.classValueType
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
@@ -114,7 +114,7 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
if (qualifierType != null) return TypeInfo(qualifierType, Variance.IN_VARIANCE) if (qualifierType != null) return TypeInfo(qualifierType, Variance.IN_VARIANCE)
if (receiver !is ClassQualifier) return null if (receiver !is ClassQualifier) return null
val classifierType = receiver.classifier.companionObjectType val classifierType = receiver.classifier.classValueType
if (classifierType != null) return TypeInfo(classifierType, Variance.IN_VARIANCE) if (classifierType != null) return TypeInfo(classifierType, Variance.IN_VARIANCE)
val javaClassifier = receiver.classifier as? JavaClassDescriptor ?: return null val javaClassifier = receiver.classifier as? JavaClassDescriptor ?: return null