Add declaresOrInheritsDefaultValue, move hasDefaultValue to 'resolution'

'hasDefaultValue' needs to be adapted to support locating default values
in 'expect' functions, and this is not possible in module 'descriptors',
where it was originally declared. Therefore, move it to module
'resolution' and copy its current logic to a separate function
'declaresOrInheritsDefaultValue' which is used in 5 places.
'hasDefaultValue' itself is updated in subsequent commits.

Besides changing imports, also use a simpler declaresDefaultValue in
some places, which does not include default values inherited from
supertypes: this is OK for constructors, and in LazyJavaClassMemberScope
for functions from built-ins which do not have default argument values
at all
This commit is contained in:
Alexander Udalov
2018-01-12 17:00:33 +01:00
parent 7eb66f2579
commit ac5444ef7c
29 changed files with 77 additions and 74 deletions
@@ -18,7 +18,7 @@ package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import kotlin.reflect.KParameter
import kotlin.reflect.KType
@@ -43,7 +43,7 @@ internal class KParameterImpl(
get() = KTypeImpl(descriptor.type) { callable.caller.parameterTypes[index] }
override val isOptional: Boolean
get() = (descriptor as? ValueParameterDescriptor)?.hasDefaultValue() ?: false
get() = (descriptor as? ValueParameterDescriptor)?.declaresOrInheritsDefaultValue() ?: false
override val isVararg: Boolean
get() = descriptor.let { it is ValueParameterDescriptor && it.varargElementType != null }