companionObjectType --> classValueType
(NB: it IS NOT a companion object in case of OBJECT or ENUM_ENTRY) Unify related names.
This commit is contained in:
@@ -426,7 +426,7 @@ public abstract class AnnotationCodegen {
|
||||
for (ConstantValue<?> value : values) {
|
||||
if (value instanceof EnumValue) {
|
||||
ClassDescriptor enumEntry = ((EnumValue) value).getValue();
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getCompanionObjectType(enumEntry);
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getClassValueType(enumEntry);
|
||||
if (classObjectType != null) {
|
||||
if ("java/lang/annotation/ElementType".equals(typeMapper.mapType(classObjectType).getInternalName())) {
|
||||
result.add(ElementType.valueOf(enumEntry.getName().asString()));
|
||||
@@ -454,7 +454,7 @@ public abstract class AnnotationCodegen {
|
||||
ConstantValue<?> compileTimeConstant = valueArguments.iterator().next();
|
||||
if (compileTimeConstant instanceof EnumValue) {
|
||||
ClassDescriptor enumEntry = ((EnumValue) compileTimeConstant).getValue();
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getCompanionObjectType(enumEntry);
|
||||
KotlinType classObjectType = DescriptorUtilsKt.getClassValueType(enumEntry);
|
||||
if (classObjectType != null) {
|
||||
if ("java/lang/annotation/RetentionPolicy".equals(typeMapper.mapType(classObjectType).getInternalName())) {
|
||||
return RetentionPolicy.valueOf(enumEntry.getName().asString());
|
||||
|
||||
+14
-11
@@ -19,7 +19,8 @@ package org.jetbrains.kotlin.resolve
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
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.ClassifierQualifier
|
||||
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.types.expressions.ExpressionTypingContext
|
||||
|
||||
|
||||
public fun resolveQualifierAsReceiverInExpression(
|
||||
qualifier: Qualifier,
|
||||
selector: DeclarationDescriptor?,
|
||||
@@ -96,17 +96,20 @@ private fun resolveQualifierReferenceTarget(
|
||||
val classifier = qualifier.classifier
|
||||
val selectorIsCallable = selector is CallableDescriptor &&
|
||||
(selector.dispatchReceiverParameter != null || selector.extensionReceiverParameter != null)
|
||||
val referenceTarget = classifier.classValueDescriptor
|
||||
if (selectorIsCallable && referenceTarget != null) {
|
||||
val classObjectType = classifier.companionObjectType!!
|
||||
val classObjectDescriptor = DescriptorUtils.getClassDescriptorForType(classObjectType)
|
||||
context.trace.record(BindingContext.REFERENCE_TARGET, qualifier.referenceExpression, referenceTarget)
|
||||
context.trace.recordType(qualifier.expression, classObjectType)
|
||||
if (classifier.companionObjectDescriptor != null) {
|
||||
// TODO simplify this code.
|
||||
// Given a class qualifier in expression position,
|
||||
// it should provide a proper REFERENCE_TARGET (with type),
|
||||
// and, in case of implicit companion object reference, SHORT_REFERENCE_TO_COMPANION_OBJECT.
|
||||
val classValueDescriptor = classifier.classValueDescriptor
|
||||
if (selectorIsCallable && classValueDescriptor != 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)
|
||||
symbolUsageValidator.validateTypeUsage(referenceTarget, context.trace, qualifier.referenceExpression)
|
||||
symbolUsageValidator.validateTypeUsage(classValueDescriptor, context.trace, qualifier.referenceExpression)
|
||||
}
|
||||
return classObjectDescriptor
|
||||
return classValueTypeDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils.isStaticNestedClass
|
||||
import org.jetbrains.kotlin.resolve.LibrarySourceHacks
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
|
||||
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.LexicalChainedScope
|
||||
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? {
|
||||
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)
|
||||
}
|
||||
|
||||
private fun findFakeDescriptorForObject(scope: HierarchicalScope, name: Name, location: LookupLocation): VariableDescriptor? {
|
||||
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)
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.util
|
||||
|
||||
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.hasCompanionObject
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.util.Collections
|
||||
|
||||
@@ -28,7 +28,7 @@ public class FakeCallableDescriptorForObject(
|
||||
) : DeclarationDescriptorWithVisibility by classDescriptor.getClassObjectReferenceTarget(), VariableDescriptor {
|
||||
|
||||
init {
|
||||
assert(classDescriptor.hasCompanionObject) {
|
||||
assert(classDescriptor.hasClassValueDescriptor) {
|
||||
"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 getType(): KotlinType = classDescriptor.companionObjectType!!
|
||||
override fun getType(): KotlinType = classDescriptor.classValueType!!
|
||||
|
||||
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.psiUtil.getTopmostParentQualifiedExpressionForSelector
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.*
|
||||
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.descriptorUtil.classValueType
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.FilteringScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
|
||||
@@ -105,7 +101,7 @@ class ClassQualifier(
|
||||
|
||||
val scopes = ArrayList<MemberScope>(3)
|
||||
|
||||
val classObjectTypeScope = classifier.companionObjectType?.memberScope?.let {
|
||||
val classObjectTypeScope = classifier.classValueType?.memberScope?.let {
|
||||
FilteringScope(it) { it !is ClassDescriptor }
|
||||
}
|
||||
scopes.addIfNotNull(classObjectTypeScope)
|
||||
@@ -143,7 +139,7 @@ fun createClassifierQualifier(
|
||||
classifier: ClassifierDescriptor,
|
||||
bindingContext: BindingContext
|
||||
): ClassifierQualifier {
|
||||
val companionObjectReceiver = (classifier as? ClassDescriptor)?.companionObjectType?.let {
|
||||
val companionObjectReceiver = (classifier as? ClassDescriptor)?.classValueType?.let {
|
||||
ExpressionReceiver.create(referenceExpression, it, bindingContext)
|
||||
}
|
||||
return if (classifier is ClassDescriptor)
|
||||
|
||||
@@ -71,7 +71,9 @@ public val ClassDescriptor.classId: ClassId
|
||||
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?
|
||||
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 */
|
||||
public val ClassDescriptor.companionObjectType: KotlinType?
|
||||
public val ClassDescriptor.classValueType: KotlinType?
|
||||
get() = classValueTypeDescriptor?.getDefaultType()
|
||||
|
||||
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.annotations.AnnotationArgumentVisitor
|
||||
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.KotlinType
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
@@ -141,7 +141,7 @@ public class EnumValue(
|
||||
) : ConstantValue<ClassDescriptor>(value) {
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
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.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
@@ -252,7 +252,7 @@ public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
val receiverType =
|
||||
bindingContext.getType(receiverExpression) ?:
|
||||
(bindingContext.get(BindingContext.QUALIFIER, receiverExpression) as? ClassQualifier)?.let {
|
||||
it.classifier.companionObjectType
|
||||
it.classifier.classValueType
|
||||
} ?:
|
||||
return emptyList()
|
||||
listOf(ExpressionReceiver.create(receiverExpression, receiverType, bindingContext))
|
||||
|
||||
+2
-2
@@ -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.getResolvedCall
|
||||
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.Qualifier
|
||||
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 (receiver !is ClassQualifier) return null
|
||||
val classifierType = receiver.classifier.companionObjectType
|
||||
val classifierType = receiver.classifier.classValueType
|
||||
if (classifierType != null) return TypeInfo(classifierType, Variance.IN_VARIANCE)
|
||||
|
||||
val javaClassifier = receiver.classifier as? JavaClassDescriptor ?: return null
|
||||
|
||||
Reference in New Issue
Block a user