idea: cleanup 'public', property access syntax
This commit is contained in:
@@ -26,31 +26,31 @@ import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
public interface ResolutionFacade {
|
||||
public val project: Project
|
||||
interface ResolutionFacade {
|
||||
val project: Project
|
||||
|
||||
public fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
|
||||
public fun analyzeFullyAndGetResult(elements: Collection<KtElement>): AnalysisResult
|
||||
fun analyzeFullyAndGetResult(elements: Collection<KtElement>): AnalysisResult
|
||||
|
||||
public fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor
|
||||
fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor
|
||||
|
||||
public val moduleDescriptor: ModuleDescriptor
|
||||
val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
// get service for the module this resolution was created for
|
||||
public fun <T : Any> getFrontendService(serviceClass: Class<T>): T
|
||||
fun <T : Any> getFrontendService(serviceClass: Class<T>): T
|
||||
|
||||
public fun <T : Any> getIdeService(serviceClass: Class<T>): T
|
||||
fun <T : Any> getIdeService(serviceClass: Class<T>): T
|
||||
|
||||
// get service for the module defined by PsiElement/ModuleDescriptor passed as parameter
|
||||
public fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T
|
||||
fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T
|
||||
|
||||
public fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
|
||||
fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
|
||||
|
||||
}
|
||||
|
||||
public inline fun <reified T : Any> ResolutionFacade.frontendService(): T
|
||||
inline fun <reified T : Any> ResolutionFacade.frontendService(): T
|
||||
= this.getFrontendService(T::class.java)
|
||||
|
||||
public inline fun <reified T : Any> ResolutionFacade.ideService(): T
|
||||
inline fun <reified T : Any> ResolutionFacade.ideService(): T
|
||||
= this.getIdeService(T::class.java)
|
||||
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.util.supertypesWithAny
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
|
||||
public sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
object UNKNOWN : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object DEFAULT : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
@@ -93,7 +93,7 @@ public sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: D
|
||||
private object NonAnnotationClassifierExclude : DescriptorKindExclude() {
|
||||
override fun excludes(descriptor: DeclarationDescriptor): Boolean {
|
||||
if (descriptor !is ClassifierDescriptor) return false
|
||||
return descriptor !is ClassDescriptor || descriptor.getKind() != ClassKind.ANNOTATION_CLASS
|
||||
return descriptor !is ClassDescriptor || descriptor.kind != ClassKind.ANNOTATION_CLASS
|
||||
}
|
||||
|
||||
override val fullyExcludedDescriptorKinds: Int get() = 0
|
||||
@@ -108,7 +108,7 @@ public sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: D
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : CallType<TReceiver>>(
|
||||
sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : CallType<TReceiver>>(
|
||||
val callType: TCallType,
|
||||
val receiver: TReceiver
|
||||
) {
|
||||
@@ -127,7 +127,7 @@ public sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : Call
|
||||
class ANNOTATION(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.ANNOTATION>(CallType.ANNOTATION, receiver)
|
||||
|
||||
companion object {
|
||||
public fun detect(expression: KtSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
fun detect(expression: KtSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
val parent = expression.parent
|
||||
if (parent is KtCallableReferenceExpression) {
|
||||
return CallTypeAndReceiver.CALLABLE_REFERENCE(parent.typeReference)
|
||||
@@ -205,7 +205,7 @@ public sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : Call
|
||||
}
|
||||
}
|
||||
|
||||
public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
bindingContext: BindingContext,
|
||||
contextElement: PsiElement,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.jetbrains.kotlin.types.typeUtil.*
|
||||
import java.util.*
|
||||
|
||||
fun CallableDescriptor.fuzzyReturnType(): FuzzyType? {
|
||||
val returnType = getReturnType() ?: return null
|
||||
return FuzzyType(returnType, getTypeParameters())
|
||||
val returnType = returnType ?: return null
|
||||
return FuzzyType(returnType, typeParameters)
|
||||
}
|
||||
|
||||
fun CallableDescriptor.fuzzyExtensionReceiverType(): FuzzyType? {
|
||||
val receiverParameter = getExtensionReceiverParameter()
|
||||
return if (receiverParameter != null) FuzzyType(receiverParameter.getType(), getTypeParameters()) else null
|
||||
val receiverParameter = extensionReceiverParameter
|
||||
return if (receiverParameter != null) FuzzyType(receiverParameter.type, typeParameters) else null
|
||||
}
|
||||
|
||||
fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParameters)
|
||||
@@ -52,7 +52,7 @@ class FuzzyType(
|
||||
val type: KotlinType,
|
||||
freeParameters: Collection<TypeParameterDescriptor>
|
||||
) {
|
||||
public val freeParameters: Set<TypeParameterDescriptor>
|
||||
val freeParameters: Set<TypeParameterDescriptor>
|
||||
|
||||
init {
|
||||
if (freeParameters.isNotEmpty()) {
|
||||
@@ -70,29 +70,29 @@ class FuzzyType(
|
||||
override fun hashCode() = type.hashCode()
|
||||
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: KotlinType) {
|
||||
val typeParameter = type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParameter = type.constructor.declarationDescriptor as? TypeParameterDescriptor
|
||||
if (typeParameter != null && add(typeParameter)) {
|
||||
typeParameter.getLowerBounds().forEach { addUsedTypeParameters(it) }
|
||||
typeParameter.getUpperBounds().forEach { addUsedTypeParameters(it) }
|
||||
typeParameter.lowerBounds.forEach { addUsedTypeParameters(it) }
|
||||
typeParameter.upperBounds.forEach { addUsedTypeParameters(it) }
|
||||
}
|
||||
|
||||
for (argument in type.getArguments()) {
|
||||
for (argument in type.arguments) {
|
||||
if (!argument.isStarProjection) { // otherwise we can fall into infinite recursion
|
||||
addUsedTypeParameters(argument.getType())
|
||||
addUsedTypeParameters(argument.type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun checkIsSubtypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
fun checkIsSubtypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
= matchedSubstitutor(otherType, MatchKind.IS_SUBTYPE)
|
||||
|
||||
public fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
= matchedSubstitutor(otherType, MatchKind.IS_SUPERTYPE)
|
||||
|
||||
public fun checkIsSubtypeOf(otherType: KotlinType): TypeSubstitutor?
|
||||
fun checkIsSubtypeOf(otherType: KotlinType): TypeSubstitutor?
|
||||
= checkIsSubtypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
public fun checkIsSuperTypeOf(otherType: KotlinType): TypeSubstitutor?
|
||||
fun checkIsSuperTypeOf(otherType: KotlinType): TypeSubstitutor?
|
||||
= checkIsSuperTypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
private enum class MatchKind {
|
||||
@@ -101,8 +101,8 @@ class FuzzyType(
|
||||
}
|
||||
|
||||
private fun matchedSubstitutor(otherType: FuzzyType, matchKind: MatchKind): TypeSubstitutor? {
|
||||
if (type.isError()) return null
|
||||
if (otherType.type.isError()) return null
|
||||
if (type.isError) return null
|
||||
if (otherType.type.isError) return null
|
||||
|
||||
fun KotlinType.checkInheritance(otherType: KotlinType): Boolean {
|
||||
return when (matchKind) {
|
||||
|
||||
@@ -24,12 +24,10 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
public object IdeDescriptorRenderers {
|
||||
@JvmField
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, true) }
|
||||
object IdeDescriptorRenderers {
|
||||
@JvmField val APPROXIMATE_FLEXIBLE_TYPES: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, true) }
|
||||
|
||||
@JvmField
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, false) }
|
||||
@JvmField val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, false) }
|
||||
|
||||
private fun unwrapAnonymousType(type: KotlinType): KotlinType {
|
||||
if (type.isDynamic()) return type
|
||||
@@ -55,20 +53,17 @@ public object IdeDescriptorRenderers {
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
|
||||
@JvmField val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
|
||||
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
||||
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
|
||||
@JvmField val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
|
||||
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
||||
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS(unwrapAnonymousType(it)) }
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
|
||||
@JvmField val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
|
||||
nameShortness = NameShortness.SHORT
|
||||
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
||||
}
|
||||
|
||||
@@ -28,36 +28,36 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public val DeclarationDescriptor.importableFqName: FqName?
|
||||
val DeclarationDescriptor.importableFqName: FqName?
|
||||
get() {
|
||||
if (!canBeReferencedViaImport()) return null
|
||||
return getImportableDescriptor().fqNameSafe
|
||||
}
|
||||
|
||||
public fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||
fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||
if (this is PackageViewDescriptor ||
|
||||
DescriptorUtils.isTopLevelDeclaration(this) ||
|
||||
this is CallableDescriptor && DescriptorUtils.isStaticDeclaration(this)) {
|
||||
return !name.isSpecial
|
||||
}
|
||||
|
||||
val parentClass = getContainingDeclaration() as? ClassDescriptor ?: return false
|
||||
val parentClass = containingDeclaration as? ClassDescriptor ?: return false
|
||||
if (!parentClass.canBeReferencedViaImport()) return false
|
||||
|
||||
return when (this) {
|
||||
is ConstructorDescriptor -> !parentClass.isInner() // inner class constructors can't be referenced via import
|
||||
is ConstructorDescriptor -> !parentClass.isInner // inner class constructors can't be referenced via import
|
||||
is ClassDescriptor -> true
|
||||
else -> parentClass.kind == ClassKind.OBJECT
|
||||
}
|
||||
}
|
||||
|
||||
public fun KotlinType.canBeReferencedViaImport(): Boolean {
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
fun KotlinType.canBeReferencedViaImport(): Boolean {
|
||||
val descriptor = constructor.declarationDescriptor
|
||||
return descriptor != null && descriptor.canBeReferencedViaImport()
|
||||
}
|
||||
|
||||
// for cases when class qualifier refers companion object treats it like reference to class itself
|
||||
public fun KtReferenceExpression.getImportableTargets(bindingContext: BindingContext): Collection<DeclarationDescriptor> {
|
||||
fun KtReferenceExpression.getImportableTargets(bindingContext: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val targets = bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, this]?.let { listOf(it) }
|
||||
?: getReferenceTargets(bindingContext)
|
||||
return targets.map { it.getImportableDescriptor() }.toSet()
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
|
||||
import java.util.*
|
||||
|
||||
public class ShadowedDeclarationsFilter(
|
||||
class ShadowedDeclarationsFilter(
|
||||
private val bindingContext: BindingContext,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val context: PsiElement,
|
||||
@@ -72,14 +72,14 @@ public class ShadowedDeclarationsFilter(
|
||||
private val psiFactory = KtPsiFactory(resolutionFacade.project)
|
||||
private val dummyExpressionFactory = DummyExpressionFactory(psiFactory)
|
||||
|
||||
public fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> {
|
||||
fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> {
|
||||
return declarations
|
||||
.groupBy { signature(it) }
|
||||
.values
|
||||
.flatMap { group -> filterEqualSignatureGroup(group) }
|
||||
}
|
||||
|
||||
public fun <TDescriptor : DeclarationDescriptor> createNonImportedDeclarationsFilter(
|
||||
fun <TDescriptor : DeclarationDescriptor> createNonImportedDeclarationsFilter(
|
||||
importedDeclarations: Collection<DeclarationDescriptor>
|
||||
): (Collection<TDescriptor>) -> Collection<TDescriptor> {
|
||||
val importedDeclarationsSet = importedDeclarations.toSet()
|
||||
@@ -126,14 +126,14 @@ public class ShadowedDeclarationsFilter(
|
||||
}
|
||||
|
||||
val isFunction = first is FunctionDescriptor
|
||||
val name = first.getName()
|
||||
val parameters = (first as CallableDescriptor).getValueParameters()
|
||||
val name = first.name
|
||||
val parameters = (first as CallableDescriptor).valueParameters
|
||||
|
||||
val dummyArgumentExpressions = dummyExpressionFactory.createDummyExpressions(parameters.size)
|
||||
|
||||
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace for filtering shadowed declarations")
|
||||
for ((expression, parameter) in dummyArgumentExpressions.zip(parameters)) {
|
||||
bindingTrace.recordType(expression, parameter.varargElementType ?: parameter.getType())
|
||||
bindingTrace.recordType(expression, parameter.varargElementType ?: parameter.type)
|
||||
bindingTrace.record(BindingContext.PROCESSED, expression, true)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ShadowedDeclarationsFilter(
|
||||
|
||||
private val argumentName: ValueArgumentName? = if (isNamed()) {
|
||||
object : ValueArgumentName {
|
||||
override val asName = parameters[index].getName()
|
||||
override val asName = parameters[index].name
|
||||
override val referenceExpression = null
|
||||
}
|
||||
}
|
||||
@@ -206,11 +206,11 @@ public class ShadowedDeclarationsFilter(
|
||||
CallChecker.DoNothing, false)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||
val results = if (isFunction) callResolver.resolveFunctionCall(context) else callResolver.resolveSimpleProperty(context)
|
||||
val resultingDescriptors = results.getResultingCalls().map { it.getResultingDescriptor() }
|
||||
val resultingOriginals = resultingDescriptors.mapTo(HashSet<DeclarationDescriptor>()) { it.getOriginal() }
|
||||
val resultingDescriptors = results.resultingCalls.map { it.resultingDescriptor }
|
||||
val resultingOriginals = resultingDescriptors.mapTo(HashSet<DeclarationDescriptor>()) { it.original }
|
||||
val filtered = descriptors.filter { candidateDescriptor ->
|
||||
candidateDescriptor.getOriginal() in resultingOriginals /* optimization */
|
||||
&& resultingDescriptors.any { descriptorsEqualWithSubstitution(it, candidateDescriptor) }
|
||||
candidateDescriptor.original in resultingOriginals /* optimization */
|
||||
&& resultingDescriptors.any { descriptorsEqualWithSubstitution(it, candidateDescriptor) }
|
||||
}
|
||||
return if (filtered.isNotEmpty()) filtered else descriptors /* something went wrong, none of our declarations among resolve candidates, let's not filter anything */
|
||||
}
|
||||
@@ -230,19 +230,19 @@ public class ShadowedDeclarationsFilter(
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is FunctionSignature) return false
|
||||
if (function.getName() != other.function.getName()) return false
|
||||
val parameters1 = function.getValueParameters()
|
||||
val parameters2 = other.function.getValueParameters()
|
||||
if (function.name != other.function.name) return false
|
||||
val parameters1 = function.valueParameters
|
||||
val parameters2 = other.function.valueParameters
|
||||
if (parameters1.size != parameters2.size) return false
|
||||
for (i in parameters1.indices) {
|
||||
val p1 = parameters1[i]
|
||||
val p2 = parameters2[i]
|
||||
if (p1.varargElementType != p2.varargElementType) return false // both should be vararg or or both not
|
||||
if (p1.getType() != p2.getType()) return false
|
||||
if (p1.type != p2.type) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode() = function.getName().hashCode() * 17 + function.getValueParameters().size
|
||||
override fun hashCode() = function.name.hashCode() * 17 + function.valueParameters.size
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,11 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
|
||||
public fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = true): KotlinType {
|
||||
fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = true): KotlinType {
|
||||
if (jetType.isDynamic()) return jetType
|
||||
if (jetType.isFlexible()) {
|
||||
val flexible = jetType.flexibility()
|
||||
val lowerClass = flexible.lowerBound.getConstructor().getDeclarationDescriptor() as? ClassDescriptor?
|
||||
val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
|
||||
val isCollection = lowerClass != null && JavaToKotlinClassMap.INSTANCE.isMutable(lowerClass)
|
||||
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
||||
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
||||
@@ -54,46 +54,46 @@ public fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = tr
|
||||
|
||||
approximation = if (jetType.isAnnotatedNotNull()) approximation.makeNotNullable() else approximation
|
||||
|
||||
if (approximation.isMarkedNullable() && !flexible.lowerBound.isMarkedNullable() && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
||||
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
||||
approximation = approximation.makeNotNullable()
|
||||
}
|
||||
|
||||
return approximation
|
||||
}
|
||||
return KotlinTypeImpl.create(
|
||||
jetType.getAnnotations(),
|
||||
jetType.getConstructor(),
|
||||
jetType.isMarkedNullable(),
|
||||
jetType.getArguments().map { it.substitute { type -> approximateFlexibleTypes(type, false)} },
|
||||
jetType.annotations,
|
||||
jetType.constructor,
|
||||
jetType.isMarkedNullable,
|
||||
jetType.arguments.map { it.substitute { type -> approximateFlexibleTypes(type, false)} },
|
||||
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
||||
)
|
||||
}
|
||||
|
||||
public fun KotlinType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
public fun KotlinType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
public fun KotlinType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
fun KotlinType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
fun KotlinType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
fun KotlinType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
|
||||
private fun KotlinType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnotations()) {
|
||||
private fun KotlinType.hasAnnotationMaybeExternal(fqName: FqName) = with (annotations) {
|
||||
findAnnotation(fqName) ?: findExternalAnnotation(fqName)
|
||||
} != null
|
||||
|
||||
fun KotlinType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
|
||||
if (canBeReferencedViaImport()) return true
|
||||
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
if (descriptor == null || descriptor.getName().isSpecial()) return false
|
||||
val descriptor = constructor.declarationDescriptor
|
||||
if (descriptor == null || descriptor.name.isSpecial) return false
|
||||
if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true
|
||||
|
||||
return scope != null && scope.findClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
|
||||
}
|
||||
|
||||
public fun KotlinType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KotlinType {
|
||||
if (isError() || isResolvableInScope(scope, checkTypeParameters)) return this
|
||||
fun KotlinType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KotlinType {
|
||||
if (isError || isResolvableInScope(scope, checkTypeParameters)) return this
|
||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
||||
?: builtIns.anyType
|
||||
}
|
||||
|
||||
public fun KotlinType.anonymousObjectSuperTypeOrNull(): KotlinType? {
|
||||
fun KotlinType.anonymousObjectSuperTypeOrNull(): KotlinType? {
|
||||
val classDescriptor = constructor.declarationDescriptor
|
||||
if (classDescriptor != null && DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
||||
return immediateSupertypes().firstOrNull() ?: classDescriptor.builtIns.anyType
|
||||
|
||||
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.idea.util
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
val literalParent = (this.getParent() as KtLambdaExpression).getParent()
|
||||
fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
val literalParent = (this.parent as KtLambdaExpression).parent
|
||||
|
||||
fun KtValueArgument.callExpression(): KtCallExpression? {
|
||||
val parent = getParent()
|
||||
return (if (parent is KtValueArgumentList) parent else this).getParent() as? KtCallExpression
|
||||
val parent = parent
|
||||
return (if (parent is KtValueArgumentList) parent else this).parent as? KtCallExpression
|
||||
}
|
||||
|
||||
when (literalParent) {
|
||||
@@ -35,7 +35,7 @@ public fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?>
|
||||
|
||||
is KtValueArgument -> {
|
||||
val callExpression = literalParent.callExpression()
|
||||
val label = (callExpression?.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedNameAsName()
|
||||
val label = (callExpression?.calleeExpression as? KtSimpleNameExpression)?.getReferencedNameAsName()
|
||||
return Pair(label, callExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
|
||||
public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
receivers: Collection<ReceiverValue>,
|
||||
context: BindingContext,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
@@ -42,7 +42,7 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
containingDeclarationOrModule: DeclarationDescriptor
|
||||
): Collection<TCallable> {
|
||||
val sequence = receivers.asSequence().flatMap { substituteExtensionIfCallable(it, callType, context, dataFlowInfo, containingDeclarationOrModule).asSequence() }
|
||||
if (getTypeParameters().isEmpty()) { // optimization for non-generic callables
|
||||
if (typeParameters.isEmpty()) { // optimization for non-generic callables
|
||||
return sequence.firstOrNull()?.let { listOf(it) } ?: listOf()
|
||||
}
|
||||
else {
|
||||
@@ -50,16 +50,16 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
}
|
||||
}
|
||||
|
||||
public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallableWithImplicitReceiver(
|
||||
fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallableWithImplicitReceiver(
|
||||
scope: LexicalScope,
|
||||
context: BindingContext,
|
||||
dataFlowInfo: DataFlowInfo
|
||||
): Collection<TCallable> {
|
||||
val receiverValues = scope.getImplicitReceiversWithInstance().map { it.getValue() }
|
||||
val receiverValues = scope.getImplicitReceiversWithInstance().map { it.value }
|
||||
return substituteExtensionIfCallable(receiverValues, context, dataFlowInfo, CallType.DEFAULT, scope.ownerDescriptor)
|
||||
}
|
||||
|
||||
public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
receiver: ReceiverValue,
|
||||
callType: CallType<*>,
|
||||
bindingContext: BindingContext,
|
||||
@@ -70,7 +70,7 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
return substituteExtensionIfCallable(types, callType)
|
||||
}
|
||||
|
||||
public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
||||
receiverTypes: Collection<KotlinType>,
|
||||
callType: CallType<*>
|
||||
): Collection<TCallable> {
|
||||
@@ -91,7 +91,7 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
}
|
||||
substitutor
|
||||
}
|
||||
if (getTypeParameters().isEmpty()) { // optimization for non-generic callables
|
||||
if (typeParameters.isEmpty()) { // optimization for non-generic callables
|
||||
return if (substitutors.any()) listOf(this) else listOf()
|
||||
}
|
||||
else {
|
||||
@@ -99,10 +99,10 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
}
|
||||
}
|
||||
|
||||
public fun ReceiverValue?.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
fun ReceiverValue?.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
return when (this) {
|
||||
is ExpressionReceiver -> {
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.expression) as? KtThisExpression)?.getInstanceReference() ?: return null
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.expression) as? KtThisExpression)?.instanceReference ?: return null
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,14 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import java.util.*
|
||||
|
||||
public fun LexicalScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
fun LexicalScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
= getImplicitReceiversWithInstanceToExpression().keys
|
||||
|
||||
public interface ReceiverExpressionFactory {
|
||||
public fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean = true): KtExpression
|
||||
interface ReceiverExpressionFactory {
|
||||
fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean = true): KtExpression
|
||||
}
|
||||
|
||||
public fun LexicalScope.getImplicitReceiversWithInstanceToExpression(): Map<ReceiverParameterDescriptor, ReceiverExpressionFactory?> {
|
||||
fun LexicalScope.getImplicitReceiversWithInstanceToExpression(): Map<ReceiverParameterDescriptor, ReceiverExpressionFactory?> {
|
||||
// we use a set to workaround a bug with receiver for companion object present twice in the result of getImplicitReceiversHierarchy()
|
||||
val receivers = LinkedHashSet(getImplicitReceiversHierarchy())
|
||||
|
||||
@@ -46,19 +46,19 @@ public fun LexicalScope.getImplicitReceiversWithInstanceToExpression(): Map<Rece
|
||||
var current: DeclarationDescriptor? = ownerDescriptor
|
||||
while (current != null) {
|
||||
if (current is PropertyAccessorDescriptor) {
|
||||
current = current.getCorrespondingProperty()
|
||||
current = current.correspondingProperty
|
||||
}
|
||||
outerDeclarationsWithInstance.add(current)
|
||||
|
||||
val classDescriptor = current as? ClassDescriptor
|
||||
if (classDescriptor != null && !classDescriptor.isInner() && !DescriptorUtils.isLocal(classDescriptor)) break
|
||||
if (classDescriptor != null && !classDescriptor.isInner && !DescriptorUtils.isLocal(classDescriptor)) break
|
||||
|
||||
current = current.getContainingDeclaration()
|
||||
current = current.containingDeclaration
|
||||
}
|
||||
|
||||
val result = LinkedHashMap<ReceiverParameterDescriptor, ReceiverExpressionFactory?>()
|
||||
for ((index, receiver) in receivers.withIndex()) {
|
||||
val owner = receiver.getContainingDeclaration()
|
||||
val owner = receiver.containingDeclaration
|
||||
val (expressionText, isImmediateThis) = if (owner in outerDeclarationsWithInstance) {
|
||||
val thisWithLabel = thisQualifierName(receiver)?.let { "this@${it.render()}" }
|
||||
if (index == 0)
|
||||
@@ -66,7 +66,7 @@ public fun LexicalScope.getImplicitReceiversWithInstanceToExpression(): Map<Rece
|
||||
else
|
||||
thisWithLabel to false
|
||||
}
|
||||
else if (owner is ClassDescriptor && owner.getKind().isSingleton()) {
|
||||
else if (owner is ClassDescriptor && owner.kind.isSingleton) {
|
||||
IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(owner) to false
|
||||
}
|
||||
else {
|
||||
@@ -86,9 +86,9 @@ public fun LexicalScope.getImplicitReceiversWithInstanceToExpression(): Map<Rece
|
||||
}
|
||||
|
||||
private fun thisQualifierName(receiver: ReceiverParameterDescriptor): Name? {
|
||||
val descriptor = receiver.getContainingDeclaration()
|
||||
val name = descriptor.getName()
|
||||
if (!name.isSpecial()) return name
|
||||
val descriptor = receiver.containingDeclaration
|
||||
val name = descriptor.name
|
||||
if (!name.isSpecial) return name
|
||||
|
||||
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? KtFunctionLiteral
|
||||
return functionLiteral?.findLabelAndCall()?.first
|
||||
|
||||
@@ -37,27 +37,27 @@ import org.jetbrains.kotlin.resolve.scopes.utils.collectFunctions
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectVariables
|
||||
|
||||
|
||||
public fun LexicalScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor> {
|
||||
fun LexicalScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor> {
|
||||
return getVariablesFromImplicitReceivers(name) + collectVariables(name, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
public fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
return getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_IDE) } +
|
||||
collectFunctions(name, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
public fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
public fun LexicalScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
fun LexicalScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
getImplicitReceiversWithInstance().forEach {
|
||||
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade/*TODO: get rid of this parameter*/): LexicalScope {
|
||||
fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade/*TODO: get rid of this parameter*/): LexicalScope {
|
||||
for (parent in parentsWithSelf) {
|
||||
if (parent is KtElement) {
|
||||
val scope = bindingContext[BindingContext.LEXICAL_SCOPE, parent]
|
||||
@@ -67,7 +67,7 @@ public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolut
|
||||
if (parent is KtClassBody) {
|
||||
val classDescriptor = bindingContext[BindingContext.CLASS, parent.getParent()] as? ClassDescriptorWithResolutionScopes
|
||||
if (classDescriptor != null) {
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution()
|
||||
return classDescriptor.scopeForMemberDeclarationResolution
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,6 @@ public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolut
|
||||
error("Not in KtFile")
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
||||
fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
||||
return frontendService<FileScopeProvider>().getFileResolutionScope(file)
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
public enum class BodyResolveMode {
|
||||
enum class BodyResolveMode {
|
||||
FULL,
|
||||
PARTIAL,
|
||||
PARTIAL_FOR_COMPLETION
|
||||
|
||||
@@ -54,8 +54,8 @@ class PartialBodyResolveFilter(
|
||||
assert(!KtPsiUtil.isLocal(declaration)) { "Should never be invoked on local declaration otherwise we may miss some local declarations with type Nothing" }
|
||||
|
||||
declaration.forEachDescendantOfType<KtCallableDeclaration> { declaration ->
|
||||
if (declaration.getTypeReference().containsProbablyNothing()) {
|
||||
val name = declaration.getName()
|
||||
if (declaration.typeReference.containsProbablyNothing()) {
|
||||
val name = declaration.name
|
||||
if (name != null) {
|
||||
if (declaration is KtNamedFunction) {
|
||||
nothingFunctionNames.add(name)
|
||||
@@ -91,8 +91,8 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
else if (statement is KtDestructuringDeclaration) {
|
||||
if (statement.getEntries().any {
|
||||
val name = it.getName()
|
||||
if (statement.entries.any {
|
||||
val name = it.name
|
||||
name != null && nameFilter(name)
|
||||
}) {
|
||||
statementMarks.mark(statement, MarkLevel.NEED_REFERENCE_RESOLVE)
|
||||
@@ -164,25 +164,25 @@ class PartialBodyResolveFilter(
|
||||
override fun visitPostfixExpression(expression: KtPostfixExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == KtTokens.EXCLEXCL) {
|
||||
addIfCanBeSmartCast(expression.getBaseExpression() ?: return)
|
||||
if (expression.operationToken == KtTokens.EXCLEXCL) {
|
||||
addIfCanBeSmartCast(expression.baseExpression ?: return)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: KtBinaryExpressionWithTypeRHS) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationReference().getReferencedNameElementType() == KtTokens.AS_KEYWORD) {
|
||||
addIfCanBeSmartCast(expression.getLeft())
|
||||
if (expression.operationReference.getReferencedNameElementType() == KtTokens.AS_KEYWORD) {
|
||||
addIfCanBeSmartCast(expression.left)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
val left = expression.getLeft()
|
||||
val right = expression.getRight()
|
||||
if (expression.operationToken == KtTokens.ELVIS) {
|
||||
val left = expression.left
|
||||
val right = expression.right
|
||||
if (left != null && right != null) {
|
||||
val smartCastName = left.smartCastExpressionName()
|
||||
if (smartCastName != null && filter(smartCastName)) {
|
||||
@@ -194,9 +194,9 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
val condition = expression.getCondition()
|
||||
val thenBranch = expression.getThen()
|
||||
val elseBranch = expression.getElse()
|
||||
val condition = expression.condition
|
||||
val thenBranch = expression.then
|
||||
val elseBranch = expression.`else`
|
||||
|
||||
val (thenSmartCastNames, elseSmartCastNames) = possiblySmartCastInCondition(condition)
|
||||
|
||||
@@ -239,11 +239,11 @@ class PartialBodyResolveFilter(
|
||||
|
||||
override fun visitForExpression(expression: KtForExpression) {
|
||||
// analyze only the loop-range expression, do not enter the loop body
|
||||
expression.getLoopRange()?.accept(this)
|
||||
expression.loopRange?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(expression: KtWhileExpression) {
|
||||
val condition = expression.getCondition()
|
||||
val condition = expression.condition
|
||||
// we need to enter the body only for "while(true)"
|
||||
if (condition.isTrueConstant()) {
|
||||
expression.acceptChildren(this)
|
||||
@@ -268,9 +268,9 @@ class PartialBodyResolveFilter(
|
||||
val emptyResult = Pair(setOf<SmartCastName>(), setOf<SmartCastName>())
|
||||
when (condition) {
|
||||
is KtBinaryExpression -> {
|
||||
val operation = condition.getOperationToken()
|
||||
val left = condition.getLeft() ?: return emptyResult
|
||||
val right = condition.getRight() ?: return emptyResult
|
||||
val operation = condition.operationToken
|
||||
val left = condition.left ?: return emptyResult
|
||||
val right = condition.right ?: return emptyResult
|
||||
|
||||
fun smartCastInEq(): Pair<Set<SmartCastName>, Set<SmartCastName>> {
|
||||
if (left.isNullLiteral()) {
|
||||
@@ -307,19 +307,19 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
is KtIsExpression -> {
|
||||
val cast = condition.getLeftHandSide().smartCastExpressionName().singletonOrEmptySet()
|
||||
return if (condition.isNegated()) Pair(setOf(), cast) else Pair(cast, setOf())
|
||||
val cast = condition.leftHandSide.smartCastExpressionName().singletonOrEmptySet()
|
||||
return if (condition.isNegated) Pair(setOf(), cast) else Pair(cast, setOf())
|
||||
}
|
||||
|
||||
is KtPrefixExpression -> {
|
||||
if (condition.getOperationToken() == KtTokens.EXCL) {
|
||||
val operand = condition.getBaseExpression() ?: return emptyResult
|
||||
if (condition.operationToken == KtTokens.EXCL) {
|
||||
val operand = condition.baseExpression ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand).swap()
|
||||
}
|
||||
}
|
||||
|
||||
is KtParenthesizedExpression -> {
|
||||
val operand = condition.getExpression() ?: return emptyResult
|
||||
val operand = condition.expression ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand)
|
||||
}
|
||||
}
|
||||
@@ -345,10 +345,10 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
expression.getCondition()?.accept(this)
|
||||
expression.condition?.accept(this)
|
||||
|
||||
val thenBranch = expression.getThen()
|
||||
val elseBranch = expression.getElse()
|
||||
val thenBranch = expression.then
|
||||
val elseBranch = expression.`else`
|
||||
if (thenBranch != null && elseBranch != null) { // if we have only one branch it makes no sense to search exits in it
|
||||
val thenExits = collectAlwaysExitPoints(thenBranch)
|
||||
if (thenExits.isNotEmpty()) {
|
||||
@@ -362,15 +362,15 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitForExpression(loop: KtForExpression) {
|
||||
loop.getLoopRange()?.accept(this)
|
||||
loop.loopRange?.accept(this)
|
||||
// do not make sense to search exits inside for as not necessary enter it at all
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(loop: KtWhileExpression) {
|
||||
val condition = loop.getCondition() ?: return
|
||||
val condition = loop.condition ?: return
|
||||
if (condition.isTrueConstant()) {
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
loop.body?.accept(this)
|
||||
insideLoopLevel--
|
||||
}
|
||||
else {
|
||||
@@ -380,9 +380,9 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitDoWhileExpression(loop: KtDoWhileExpression) {
|
||||
loop.getCondition()?.accept(this)
|
||||
loop.condition?.accept(this)
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
loop.body?.accept(this)
|
||||
insideLoopLevel--
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: KtCallExpression) {
|
||||
val name = (expression.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedName()
|
||||
val name = (expression.calleeExpression as? KtSimpleNameExpression)?.getReferencedName()
|
||||
if (name != null && name in nothingFunctionNames) {
|
||||
result.add(expression)
|
||||
}
|
||||
@@ -414,9 +414,9 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
if (expression.operationToken == KtTokens.ELVIS) {
|
||||
// do not search exits after "?:"
|
||||
expression.getLeft()?.accept(this)
|
||||
expression.left?.accept(this)
|
||||
}
|
||||
else {
|
||||
super.visitBinaryExpression(expression)
|
||||
@@ -462,9 +462,9 @@ class PartialBodyResolveFilter(
|
||||
is KtSimpleNameExpression -> SmartCastName(null, this.getReferencedName())
|
||||
|
||||
is KtQualifiedExpression -> {
|
||||
val selector = getSelectorExpression() as? KtSimpleNameExpression ?: return null
|
||||
val selector = selectorExpression as? KtSimpleNameExpression ?: return null
|
||||
val selectorName = selector.getReferencedName()
|
||||
val receiver = getReceiverExpression()
|
||||
val receiver = receiverExpression
|
||||
if (receiver is KtThisExpression) {
|
||||
return SmartCastName(null, selectorName)
|
||||
}
|
||||
@@ -518,7 +518,7 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun findStatementToResolve(element: KtElement, declaration: KtDeclaration): KtExpression? {
|
||||
fun findStatementToResolve(element: KtElement, declaration: KtDeclaration): KtExpression? {
|
||||
return element.parentsWithSelf.takeWhile { it != declaration }.firstOrNull { it.isStatement() } as KtExpression?
|
||||
}
|
||||
|
||||
@@ -526,16 +526,16 @@ class PartialBodyResolveFilter(
|
||||
forEachDescendantOfType(canGoInside = { it !is KtBlockExpression }, action = action)
|
||||
}
|
||||
|
||||
private fun KtExpression?.isNullLiteral() = this?.getNode()?.getElementType() == KtNodeTypes.NULL
|
||||
private fun KtExpression?.isNullLiteral() = this?.node?.elementType == KtNodeTypes.NULL
|
||||
|
||||
private fun KtExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == KtNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
= this != null && node?.elementType == KtNodeTypes.BOOLEAN_CONSTANT && text == "true"
|
||||
|
||||
private fun <T : Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) setOf(this) else setOf()
|
||||
|
||||
//TODO: review logic
|
||||
private fun isValueNeeded(expression: KtExpression): Boolean {
|
||||
val parent = expression.getParent()
|
||||
val parent = expression.parent
|
||||
return when (parent) {
|
||||
is KtBlockExpression -> expression == parent.lastStatement() && isValueNeeded(parent)
|
||||
|
||||
@@ -545,7 +545,7 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
is KtDeclarationWithBody -> {
|
||||
if (expression == parent.getBodyExpression())
|
||||
if (expression == parent.bodyExpression)
|
||||
!parent.hasBlockBody() && !parent.hasDeclaredReturnType()
|
||||
else
|
||||
true
|
||||
@@ -558,7 +558,7 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
private fun KtBlockExpression.lastStatement(): KtExpression?
|
||||
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<KtExpression>()
|
||||
= lastChild?.siblings(forward = false)?.firstIsInstanceOrNull<KtExpression>()
|
||||
|
||||
private fun PsiElement.isStatement() = this is KtExpression && getParent() is KtBlockExpression
|
||||
|
||||
@@ -576,7 +576,7 @@ class PartialBodyResolveFilter(
|
||||
if (e.isStatement()) {
|
||||
markStatement(e as KtExpression, level)
|
||||
}
|
||||
e = e.getParent()!!
|
||||
e = e.parent!!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ class PartialBodyResolveFilter(
|
||||
if (currentLevel < level) {
|
||||
statementMarks[statement] = level
|
||||
|
||||
val block = statement.getParent() as KtBlockExpression
|
||||
val block = statement.parent as KtBlockExpression
|
||||
val currentBlockLevel = blockLevels[block] ?: MarkLevel.NONE
|
||||
if (currentBlockLevel < level) {
|
||||
blockLevels[block] = level
|
||||
@@ -602,7 +602,7 @@ class PartialBodyResolveFilter(
|
||||
fun lastMarkedStatement(block: KtBlockExpression, minLevel: MarkLevel): KtExpression? {
|
||||
val level = blockLevels[block] ?: MarkLevel.NONE
|
||||
if (level < minLevel) return null // optimization
|
||||
return block.getLastChild().siblings(forward = false)
|
||||
return block.lastChild.siblings(forward = false)
|
||||
.filterIsInstance<KtExpression>()
|
||||
.first { statementMark(it) >= minLevel }
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
public interface ProbablyNothingCallableNames {
|
||||
public fun functionNames(): Collection<String>
|
||||
public fun propertyNames(): Collection<String>
|
||||
interface ProbablyNothingCallableNames {
|
||||
fun functionNames(): Collection<String>
|
||||
fun propertyNames(): Collection<String>
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : BaseImportingScope(null) {
|
||||
class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : BaseImportingScope(null) {
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation)
|
||||
= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
= descriptors.filter { it.name == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
|
||||
|
||||
override fun getContributedPackage(name: Name)
|
||||
= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<PackageViewDescriptor>()
|
||||
= descriptors.filter { it.name == name }.firstIsInstanceOrNull<PackageViewDescriptor>()
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation)
|
||||
= descriptors.filter { it.getName() == name }.filterIsInstance<VariableDescriptor>()
|
||||
= descriptors.filter { it.name == name }.filterIsInstance<VariableDescriptor>()
|
||||
|
||||
override fun getContributedFunctions(name: Name, location: LookupLocation)
|
||||
= descriptors.filter { it.getName() == name }.filterIsInstance<FunctionDescriptor>()
|
||||
= descriptors.filter { it.name == name }.filterIsInstance<FunctionDescriptor>()
|
||||
|
||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
||||
= descriptors
|
||||
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println(javaClass.getName())
|
||||
p.println(javaClass.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,15 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
|
||||
public fun KtUserType.aliasImportMap(): Multimap<String, String> {
|
||||
fun KtUserType.aliasImportMap(): Multimap<String, String> {
|
||||
// we need to access containing file via stub because getPsi() may return null when indexing and getContainingFile() will crash
|
||||
val file = getStub()?.getContainingFileStub()?.getPsi() ?: return HashMultimap.create()
|
||||
val file = stub?.getContainingFileStub()?.psi ?: return HashMultimap.create()
|
||||
return (file as KtFile).aliasImportMap()
|
||||
}
|
||||
|
||||
private fun KtFile.aliasImportMap(): Multimap<String, String> {
|
||||
val cached = getUserData(ALIAS_IMPORT_DATA_KEY)
|
||||
val modificationStamp = getModificationStamp()
|
||||
val modificationStamp = modificationStamp
|
||||
if (cached != null && modificationStamp == cached.fileModificationStamp) {
|
||||
return cached.map
|
||||
}
|
||||
@@ -45,10 +45,10 @@ private fun KtFile.aliasImportMap(): Multimap<String, String> {
|
||||
|
||||
private fun KtFile.buildAliasImportMap(): Multimap<String, String> {
|
||||
val map = HashMultimap.create<String, String>()
|
||||
val importList = getImportList() ?: return map
|
||||
for (import in importList.getImports()) {
|
||||
val aliasName = import.getAliasName() ?: continue
|
||||
val name = import.getImportPath()?.fqnPart()?.shortName()?.asString() ?: continue
|
||||
val importList = importList ?: return map
|
||||
for (import in importList.imports) {
|
||||
val aliasName = import.aliasName ?: continue
|
||||
val name = import.importPath?.fqnPart()?.shortName()?.asString() ?: continue
|
||||
map.put(aliasName, name)
|
||||
}
|
||||
return map
|
||||
@@ -58,14 +58,14 @@ private class CachedAliasImportData(val map: Multimap<String, String>, val fileM
|
||||
|
||||
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
|
||||
|
||||
public fun KtTypeReference?.isProbablyNothing(): Boolean {
|
||||
fun KtTypeReference?.isProbablyNothing(): Boolean {
|
||||
val userType = this?.typeElement as? KtUserType ?: return false
|
||||
return userType.isProbablyNothing()
|
||||
}
|
||||
|
||||
public fun KtUserType?.isProbablyNothing(): Boolean {
|
||||
fun KtUserType?.isProbablyNothing(): Boolean {
|
||||
if (this == null) return false
|
||||
val referencedName = getReferencedName()
|
||||
val referencedName = referencedName
|
||||
return referencedName == "Nothing" || aliasImportMap()[referencedName].contains("Nothing")
|
||||
}
|
||||
|
||||
@@ -73,5 +73,5 @@ private fun StubElement<*>.getContainingFileStub(): PsiFileStub<*> {
|
||||
return if (this is PsiFileStub)
|
||||
this
|
||||
else
|
||||
getParentStub().getContainingFileStub()
|
||||
parentStub.getContainingFileStub()
|
||||
}
|
||||
|
||||
@@ -25,51 +25,51 @@ import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.equalTypesOrNulls
|
||||
|
||||
public fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?, descriptor2: DeclarationDescriptor?): Boolean {
|
||||
fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?, descriptor2: DeclarationDescriptor?): Boolean {
|
||||
if (descriptor1 == descriptor2) return true
|
||||
if (descriptor1 == null || descriptor2 == null) return false
|
||||
if (descriptor1.getOriginal() != descriptor2.getOriginal()) return false
|
||||
if (descriptor1.original != descriptor2.original) return false
|
||||
if (descriptor1 !is CallableDescriptor) return true
|
||||
descriptor2 as CallableDescriptor
|
||||
|
||||
val typeChecker = KotlinTypeChecker.withAxioms(object: KotlinTypeChecker.TypeConstructorEquality {
|
||||
override fun equals(a: TypeConstructor, b: TypeConstructor): Boolean {
|
||||
val typeParam1 = a.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParam2 = b.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParam1 = a.declarationDescriptor as? TypeParameterDescriptor
|
||||
val typeParam2 = b.declarationDescriptor as? TypeParameterDescriptor
|
||||
if (typeParam1 != null
|
||||
&& typeParam2 != null
|
||||
&& typeParam1.getContainingDeclaration() == descriptor1
|
||||
&& typeParam2.getContainingDeclaration() == descriptor2) {
|
||||
return typeParam1.getIndex() == typeParam2.getIndex()
|
||||
&& typeParam1.containingDeclaration == descriptor1
|
||||
&& typeParam2.containingDeclaration == descriptor2) {
|
||||
return typeParam1.index == typeParam2.index
|
||||
}
|
||||
|
||||
return a == b
|
||||
}
|
||||
})
|
||||
|
||||
if (!typeChecker.equalTypesOrNulls(descriptor1.getReturnType(), descriptor2.getReturnType())) return false
|
||||
if (!typeChecker.equalTypesOrNulls(descriptor1.returnType, descriptor2.returnType)) return false
|
||||
|
||||
val parameters1 = descriptor1.getValueParameters()
|
||||
val parameters2 = descriptor2.getValueParameters()
|
||||
val parameters1 = descriptor1.valueParameters
|
||||
val parameters2 = descriptor2.valueParameters
|
||||
if (parameters1.size != parameters2.size) return false
|
||||
for ((param1, param2) in parameters1.zip(parameters2)) {
|
||||
if (!typeChecker.equalTypes(param1.getType(), param2.getType())) return false
|
||||
if (!typeChecker.equalTypes(param1.type, param2.type)) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public fun ClassDescriptor.findCallableMemberBySignature(signature: CallableMemberDescriptor): CallableMemberDescriptor? {
|
||||
fun ClassDescriptor.findCallableMemberBySignature(signature: CallableMemberDescriptor): CallableMemberDescriptor? {
|
||||
val descriptorKind = if (signature is FunctionDescriptor) DescriptorKindFilter.FUNCTIONS else DescriptorKindFilter.VARIABLES
|
||||
return getDefaultType().getMemberScope()
|
||||
return defaultType.memberScope
|
||||
.getContributedDescriptors(descriptorKind)
|
||||
.filterIsInstance<CallableMemberDescriptor>()
|
||||
.firstOrNull {
|
||||
it.getContainingDeclaration() == this
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(it as CallableDescriptor, signature, null).getResult() == OVERRIDABLE
|
||||
it.containingDeclaration == this
|
||||
&& OverridingUtil.DEFAULT.isOverridableBy(it as CallableDescriptor, signature, null).result == OVERRIDABLE
|
||||
} as? CallableMemberDescriptor
|
||||
}
|
||||
|
||||
public fun TypeConstructor.supertypesWithAny(): Collection<KotlinType> {
|
||||
fun TypeConstructor.supertypesWithAny(): Collection<KotlinType> {
|
||||
val supertypes = supertypes
|
||||
val noSuperClass = supertypes
|
||||
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
|
||||
@@ -22,39 +22,39 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
public fun getTypeSubstitution(baseType: KotlinType, derivedType: KotlinType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
fun getTypeSubstitution(baseType: KotlinType, derivedType: KotlinType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
val substitutedType = TypeCheckingProcedure.findCorrespondingSupertype(derivedType, baseType) ?: return null
|
||||
|
||||
val substitution = LinkedHashMap<TypeConstructor, TypeProjection>(substitutedType.getArguments().size)
|
||||
for ((param, arg) in baseType.getConstructor().getParameters().zip(substitutedType.getArguments())) {
|
||||
substitution[param.getTypeConstructor()] = arg
|
||||
val substitution = LinkedHashMap<TypeConstructor, TypeProjection>(substitutedType.arguments.size)
|
||||
for ((param, arg) in baseType.constructor.parameters.zip(substitutedType.arguments)) {
|
||||
substitution[param.typeConstructor] = arg
|
||||
}
|
||||
|
||||
return substitution
|
||||
}
|
||||
|
||||
public fun getCallableSubstitution(
|
||||
fun getCallableSubstitution(
|
||||
baseCallable: CallableDescriptor,
|
||||
derivedCallable: CallableDescriptor
|
||||
): MutableMap<TypeConstructor, TypeProjection>? {
|
||||
val baseClass = baseCallable.getContainingDeclaration() as? ClassDescriptor ?: return null
|
||||
val derivedClass = derivedCallable.getContainingDeclaration() as? ClassDescriptor ?: return null
|
||||
val substitution = getTypeSubstitution(baseClass.getDefaultType(), derivedClass.getDefaultType()) ?: return null
|
||||
val baseClass = baseCallable.containingDeclaration as? ClassDescriptor ?: return null
|
||||
val derivedClass = derivedCallable.containingDeclaration as? ClassDescriptor ?: return null
|
||||
val substitution = getTypeSubstitution(baseClass.defaultType, derivedClass.defaultType) ?: return null
|
||||
|
||||
for ((baseParam, derivedParam) in baseCallable.getTypeParameters().zip(derivedCallable.getTypeParameters())) {
|
||||
substitution[baseParam.getTypeConstructor()] = TypeProjectionImpl(derivedParam.getDefaultType())
|
||||
for ((baseParam, derivedParam) in baseCallable.typeParameters.zip(derivedCallable.typeParameters)) {
|
||||
substitution[baseParam.typeConstructor] = TypeProjectionImpl(derivedParam.defaultType)
|
||||
}
|
||||
|
||||
return substitution
|
||||
}
|
||||
|
||||
public fun getCallableSubstitutor(
|
||||
fun getCallableSubstitutor(
|
||||
baseCallable: CallableDescriptor,
|
||||
derivedCallable: CallableDescriptor
|
||||
): TypeSubstitutor? {
|
||||
return getCallableSubstitution(baseCallable, derivedCallable)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
public fun getTypeSubstitutor(baseType: KotlinType, derivedType: KotlinType): TypeSubstitutor? {
|
||||
fun getTypeSubstitutor(baseType: KotlinType, derivedType: KotlinType): TypeSubstitutor? {
|
||||
return getTypeSubstitution(baseType, derivedType)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user