rename Jet* classes to Kt*
This commit is contained in:
+30
-30
@@ -23,10 +23,10 @@ import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
@@ -35,14 +35,14 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ReferenceVariantsHelper(
|
||||
) {
|
||||
@JvmOverloads
|
||||
public fun getReferenceVariants(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *> = CallTypeAndReceiver.detect(expression),
|
||||
@@ -85,7 +85,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getReferenceVariantsNoVisibilityFilter(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>,
|
||||
@@ -96,7 +96,7 @@ public class ReferenceVariantsHelper(
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val kindFilter = kindFilter.intersect(callType.descriptorKindFilter)
|
||||
|
||||
val receiverExpression: JetExpression?
|
||||
val receiverExpression: KtExpression?
|
||||
when (callTypeAndReceiver) {
|
||||
is CallTypeAndReceiver.IMPORT_DIRECTIVE -> {
|
||||
return getVariantsForImportOrPackageDirective(callTypeAndReceiver.receiver, kindFilter, nameFilter)
|
||||
@@ -115,7 +115,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE -> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression.parent as JetExpression] ?: return emptyList()
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression.parent as KtExpression] ?: return emptyList()
|
||||
return getVariantsForCallableReference(callTypeAndReceiver.receiver, resolutionScope, kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForUserType(
|
||||
receiverExpression: JetExpression?,
|
||||
expression: JetSimpleNameExpression,
|
||||
receiverExpression: KtExpression?,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -178,7 +178,7 @@ public class ReferenceVariantsHelper(
|
||||
return qualifier.scope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
}
|
||||
else {
|
||||
val lexicalScope = expression.getParentOfType<JetTypeReference>(strict = true)?.let {
|
||||
val lexicalScope = expression.getParentOfType<KtTypeReference>(strict = true)?.let {
|
||||
context[BindingContext.LEXICAL_SCOPE, it]
|
||||
} ?: return emptyList()
|
||||
return lexicalScope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
@@ -186,8 +186,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForCallableReference(
|
||||
qualifierTypeRef: JetTypeReference?,
|
||||
resolutionScope: JetScope,
|
||||
qualifierTypeRef: KtTypeReference?,
|
||||
resolutionScope: KtScope,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -207,7 +207,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForImportOrPackageDirective(
|
||||
receiverExpression: JetExpression?,
|
||||
receiverExpression: KtExpression?,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -222,9 +222,9 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.processAll(
|
||||
implicitReceiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<JetType>,
|
||||
resolutionScope: JetScope,
|
||||
implicitReceiverTypes: Collection<KtType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
resolutionScope: KtScope,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -235,8 +235,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addMemberExtensions(
|
||||
dispatchReceiverTypes: Collection<JetType>,
|
||||
extensionReceiverTypes: Collection<JetType>,
|
||||
dispatchReceiverTypes: Collection<KtType>,
|
||||
extensionReceiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -250,7 +250,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addNonExtensionMembers(
|
||||
receiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
constructorFilter: (ClassDescriptor) -> Boolean
|
||||
@@ -261,7 +261,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addNonExtensionCallablesAndConstructors(
|
||||
scope: JetScope,
|
||||
scope: KtScope,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
constructorFilter: (ClassDescriptor) -> Boolean
|
||||
@@ -286,8 +286,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addScopeAndSyntheticExtensions(
|
||||
resolutionScope: JetScope,
|
||||
receiverTypes: Collection<JetType>,
|
||||
resolutionScope: KtScope,
|
||||
receiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -320,10 +320,10 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getQualifierRuntimeType(receiver: JetExpression): JetType? {
|
||||
private fun getQualifierRuntimeType(receiver: KtExpression): KtType? {
|
||||
val type = context.getType(receiver)
|
||||
if (type != null && TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, type)) {
|
||||
val evaluator = receiver.getContainingFile().getCopyableUserData(JetCodeFragment.RUNTIME_TYPE_EVALUATOR)
|
||||
if (type != null && TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, type)) {
|
||||
val evaluator = receiver.getContainingFile().getCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR)
|
||||
val runtimeType = evaluator?.invoke(receiver)
|
||||
if (runtimeType == type) return null
|
||||
return runtimeType
|
||||
@@ -332,7 +332,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
public fun getPackageReferenceVariants(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
|
||||
@@ -21,19 +21,19 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
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
|
||||
|
||||
public fun analyze(element: JetElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
public fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
|
||||
public fun analyzeFullyAndGetResult(elements: Collection<JetElement>): AnalysisResult
|
||||
public fun analyzeFullyAndGetResult(elements: Collection<KtElement>): AnalysisResult
|
||||
|
||||
public fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor
|
||||
public fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor
|
||||
|
||||
public val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isImportDirectiveExpression
|
||||
@@ -29,31 +29,31 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
|
||||
public sealed class CallType<TReceiver : JetElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
public sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
object UNKNOWN : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object DEFAULT : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object DOT : CallType<JetExpression>(DescriptorKindFilter.ALL)
|
||||
object DOT : CallType<KtExpression>(DescriptorKindFilter.ALL)
|
||||
|
||||
object SAFE : CallType<JetExpression>(DescriptorKindFilter.ALL)
|
||||
object SAFE : CallType<KtExpression>(DescriptorKindFilter.ALL)
|
||||
|
||||
object INFIX : CallType<JetExpression>(DescriptorKindFilter.FUNCTIONS exclude NonInfixExclude)
|
||||
object INFIX : CallType<KtExpression>(DescriptorKindFilter.FUNCTIONS exclude NonInfixExclude)
|
||||
|
||||
object OPERATOR : CallType<JetExpression>(DescriptorKindFilter.FUNCTIONS exclude NonOperatorExclude)
|
||||
object OPERATOR : CallType<KtExpression>(DescriptorKindFilter.FUNCTIONS exclude NonOperatorExclude)
|
||||
|
||||
object CALLABLE_REFERENCE : CallType<JetTypeReference?>(DescriptorKindFilter.CALLABLES exclude CallableReferenceExclude)
|
||||
object CALLABLE_REFERENCE : CallType<KtTypeReference?>(DescriptorKindFilter.CALLABLES exclude CallableReferenceExclude)
|
||||
|
||||
object IMPORT_DIRECTIVE : CallType<JetExpression?>(DescriptorKindFilter.ALL)
|
||||
object IMPORT_DIRECTIVE : CallType<KtExpression?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object PACKAGE_DIRECTIVE : CallType<JetExpression?>(DescriptorKindFilter.PACKAGES)
|
||||
object PACKAGE_DIRECTIVE : CallType<KtExpression?>(DescriptorKindFilter.PACKAGES)
|
||||
|
||||
object TYPE : CallType<JetExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK))
|
||||
object TYPE : CallType<KtExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK))
|
||||
|
||||
object ANNOTATION : CallType<JetExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude)
|
||||
object ANNOTATION : CallType<KtExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude)
|
||||
|
||||
private object NonInfixExclude : DescriptorKindExclude() {
|
||||
override fun excludes(descriptor: DeclarationDescriptor) =
|
||||
@@ -89,26 +89,26 @@ public sealed class CallType<TReceiver : JetElement?>(val descriptorKindFilter:
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : CallType<TReceiver>>(
|
||||
public sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : CallType<TReceiver>>(
|
||||
val callType: TCallType,
|
||||
val receiver: TReceiver
|
||||
) {
|
||||
object UNKNOWN : CallTypeAndReceiver<Nothing?, CallType.UNKNOWN>(CallType.UNKNOWN, null)
|
||||
object DEFAULT : CallTypeAndReceiver<Nothing?, CallType.DEFAULT>(CallType.DEFAULT, null)
|
||||
class DOT(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.DOT>(CallType.DOT, receiver)
|
||||
class SAFE(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.SAFE>(CallType.SAFE, receiver)
|
||||
class INFIX(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.INFIX>(CallType.INFIX, receiver)
|
||||
class OPERATOR(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.OPERATOR>(CallType.OPERATOR, receiver)
|
||||
class CALLABLE_REFERENCE(receiver: JetTypeReference?) : CallTypeAndReceiver<JetTypeReference?, CallType.CALLABLE_REFERENCE>(CallType.CALLABLE_REFERENCE, receiver)
|
||||
class IMPORT_DIRECTIVE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.IMPORT_DIRECTIVE>(CallType.IMPORT_DIRECTIVE, receiver)
|
||||
class PACKAGE_DIRECTIVE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.PACKAGE_DIRECTIVE>(CallType.PACKAGE_DIRECTIVE, receiver)
|
||||
class TYPE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.TYPE>(CallType.TYPE, receiver)
|
||||
class ANNOTATION(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.ANNOTATION>(CallType.ANNOTATION, receiver)
|
||||
class DOT(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.DOT>(CallType.DOT, receiver)
|
||||
class SAFE(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.SAFE>(CallType.SAFE, receiver)
|
||||
class INFIX(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.INFIX>(CallType.INFIX, receiver)
|
||||
class OPERATOR(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.OPERATOR>(CallType.OPERATOR, receiver)
|
||||
class CALLABLE_REFERENCE(receiver: KtTypeReference?) : CallTypeAndReceiver<KtTypeReference?, CallType.CALLABLE_REFERENCE>(CallType.CALLABLE_REFERENCE, receiver)
|
||||
class IMPORT_DIRECTIVE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.IMPORT_DIRECTIVE>(CallType.IMPORT_DIRECTIVE, receiver)
|
||||
class PACKAGE_DIRECTIVE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.PACKAGE_DIRECTIVE>(CallType.PACKAGE_DIRECTIVE, receiver)
|
||||
class TYPE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.TYPE>(CallType.TYPE, receiver)
|
||||
class ANNOTATION(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.ANNOTATION>(CallType.ANNOTATION, receiver)
|
||||
|
||||
companion object {
|
||||
public fun detect(expression: JetSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
public fun detect(expression: KtSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
val parent = expression.parent
|
||||
if (parent is JetCallableReferenceExpression) {
|
||||
if (parent is KtCallableReferenceExpression) {
|
||||
return CallTypeAndReceiver.CALLABLE_REFERENCE(parent.typeReference)
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
return CallTypeAndReceiver.PACKAGE_DIRECTIVE(receiverExpression)
|
||||
}
|
||||
|
||||
if (parent is JetUserType) {
|
||||
val constructorCallee = (parent.parent as? JetTypeReference)?.parent as? JetConstructorCalleeExpression
|
||||
if (constructorCallee != null && constructorCallee.parent is JetAnnotationEntry) {
|
||||
if (parent is KtUserType) {
|
||||
val constructorCallee = (parent.parent as? KtTypeReference)?.parent as? KtConstructorCalleeExpression
|
||||
if (constructorCallee != null && constructorCallee.parent is KtAnnotationEntry) {
|
||||
return CallTypeAndReceiver.ANNOTATION(receiverExpression)
|
||||
}
|
||||
|
||||
@@ -132,39 +132,39 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
}
|
||||
|
||||
when (expression) {
|
||||
is JetOperationReferenceExpression -> {
|
||||
is KtOperationReferenceExpression -> {
|
||||
if (receiverExpression == null) {
|
||||
return UNKNOWN // incomplete code
|
||||
}
|
||||
return when (parent) {
|
||||
is JetBinaryExpression -> {
|
||||
if (parent.operationToken == JetTokens.IDENTIFIER)
|
||||
is KtBinaryExpression -> {
|
||||
if (parent.operationToken == KtTokens.IDENTIFIER)
|
||||
CallTypeAndReceiver.INFIX(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
}
|
||||
|
||||
is JetUnaryExpression -> CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
is KtUnaryExpression -> CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
|
||||
else -> error("Unknown parent for JetOperationReferenceExpression: $parent")
|
||||
}
|
||||
}
|
||||
|
||||
is JetNameReferenceExpression -> {
|
||||
is KtNameReferenceExpression -> {
|
||||
if (receiverExpression == null) {
|
||||
return CallTypeAndReceiver.DEFAULT
|
||||
}
|
||||
|
||||
return when (parent) {
|
||||
is JetCallExpression -> {
|
||||
if ((parent.parent as JetQualifiedExpression).operationSign == JetTokens.SAFE_ACCESS)
|
||||
is KtCallExpression -> {
|
||||
if ((parent.parent as KtQualifiedExpression).operationSign == KtTokens.SAFE_ACCESS)
|
||||
CallTypeAndReceiver.SAFE(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.DOT(receiverExpression)
|
||||
}
|
||||
|
||||
is JetQualifiedExpression -> {
|
||||
if (parent.operationSign == JetTokens.SAFE_ACCESS)
|
||||
is KtQualifiedExpression -> {
|
||||
if (parent.operationSign == KtTokens.SAFE_ACCESS)
|
||||
CallTypeAndReceiver.SAFE(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.DOT(receiverExpression)
|
||||
@@ -182,11 +182,11 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
|
||||
public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
bindingContext: BindingContext,
|
||||
position: JetExpression,
|
||||
position: KtExpression,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
predictableSmartCastsOnly: Boolean
|
||||
): Collection<JetType>? {
|
||||
val receiverExpression: JetExpression?
|
||||
): Collection<KtType>? {
|
||||
val receiverExpression: KtExpression?
|
||||
when (this) {
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE -> {
|
||||
return receiver?.let { bindingContext[BindingContext.TYPE, it] }.singletonOrEmptyList()
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.registerTypeVariables
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
@@ -51,7 +51,7 @@ fun FuzzyType.isAlmostEverything(): Boolean {
|
||||
}
|
||||
|
||||
class FuzzyType(
|
||||
val type: JetType,
|
||||
val type: KtType,
|
||||
freeParameters: Collection<TypeParameterDescriptor>
|
||||
) {
|
||||
public val freeParameters: Set<TypeParameterDescriptor>
|
||||
@@ -71,7 +71,7 @@ class FuzzyType(
|
||||
|
||||
override fun hashCode() = type.hashCode()
|
||||
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: JetType) {
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: KtType) {
|
||||
val typeParameter = type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
if (typeParameter != null && add(typeParameter)) {
|
||||
typeParameter.getLowerBounds().forEach { addUsedTypeParameters(it) }
|
||||
@@ -91,10 +91,10 @@ class FuzzyType(
|
||||
public fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
= matchedSubstitutor(otherType, MatchKind.IS_SUPERTYPE)
|
||||
|
||||
public fun checkIsSubtypeOf(otherType: JetType): TypeSubstitutor?
|
||||
public fun checkIsSubtypeOf(otherType: KtType): TypeSubstitutor?
|
||||
= checkIsSubtypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
public fun checkIsSuperTypeOf(otherType: JetType): TypeSubstitutor?
|
||||
public fun checkIsSuperTypeOf(otherType: KtType): TypeSubstitutor?
|
||||
= checkIsSuperTypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
private enum class MatchKind {
|
||||
@@ -106,7 +106,7 @@ class FuzzyType(
|
||||
if (type.isError()) return null
|
||||
if (otherType.type.isError()) return null
|
||||
|
||||
fun JetType.checkInheritance(otherType: JetType): Boolean {
|
||||
fun KtType.checkInheritance(otherType: KtType): Boolean {
|
||||
return when (matchKind) {
|
||||
MatchKind.IS_SUBTYPE -> this.isSubtypeOf(otherType)
|
||||
MatchKind.IS_SUPERTYPE -> otherType.isSubtypeOf(this)
|
||||
|
||||
@@ -20,16 +20,16 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
public object IdeDescriptorRenderers {
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES: (JetType) -> JetType = { approximateFlexibleTypes(it, true) }
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES: (KtType) -> KtType = { approximateFlexibleTypes(it, true) }
|
||||
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (JetType) -> JetType = { approximateFlexibleTypes(it, false) }
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (KtType) -> KtType = { approximateFlexibleTypes(it, false) }
|
||||
|
||||
private fun unwrapAnonymousType(type: JetType): JetType {
|
||||
private fun unwrapAnonymousType(type: KtType): KtType {
|
||||
if (type.isDynamic()) return type
|
||||
|
||||
val classifier = type.constructor.declarationDescriptor
|
||||
|
||||
@@ -20,13 +20,13 @@ package org.jetbrains.kotlin.idea.imports
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public val DeclarationDescriptor.importableFqName: FqName?
|
||||
get() {
|
||||
@@ -51,13 +51,13 @@ public fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetType.canBeReferencedViaImport(): Boolean {
|
||||
public fun KtType.canBeReferencedViaImport(): Boolean {
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
return descriptor != null && descriptor.canBeReferencedViaImport()
|
||||
}
|
||||
|
||||
// for cases when class qualifier refers companion object treats it like reference to class itself
|
||||
public fun JetReferenceExpression.getImportableTargets(bindingContext: BindingContext): Collection<DeclarationDescriptor> {
|
||||
public 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()
|
||||
|
||||
@@ -40,14 +40,14 @@ import java.util.*
|
||||
public class ShadowedDeclarationsFilter private constructor(
|
||||
private val bindingContext: BindingContext,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val context: JetExpression,
|
||||
private val context: KtExpression,
|
||||
private val explicitReceiverValue: ReceiverValue
|
||||
) {
|
||||
companion object {
|
||||
fun create(
|
||||
bindingContext: BindingContext,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
context: JetExpression,
|
||||
context: KtExpression,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
||||
): ShadowedDeclarationsFilter? {
|
||||
val receiverExpression = when (callTypeAndReceiver) {
|
||||
@@ -67,7 +67,7 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private val psiFactory = JetPsiFactory(resolutionFacade.project)
|
||||
private val psiFactory = KtPsiFactory(resolutionFacade.project)
|
||||
private val dummyExpressionFactory = DummyExpressionFactory(psiFactory)
|
||||
|
||||
public fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> {
|
||||
@@ -173,7 +173,7 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
|
||||
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
|
||||
|
||||
override fun getTypeArguments() = emptyList<JetTypeProjection>()
|
||||
override fun getTypeArguments() = emptyList<KtTypeProjection>()
|
||||
|
||||
override fun getTypeArgumentList() = null
|
||||
|
||||
@@ -209,10 +209,10 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
return if (filtered.isNotEmpty()) filtered else descriptors /* something went wrong, none of our declarations among resolve candidates, let's not filter anything */
|
||||
}
|
||||
|
||||
private class DummyExpressionFactory(val factory: JetPsiFactory) {
|
||||
private val expressions = ArrayList<JetExpression>()
|
||||
private class DummyExpressionFactory(val factory: KtPsiFactory) {
|
||||
private val expressions = ArrayList<KtExpression>()
|
||||
|
||||
fun createDummyExpressions(count: Int): List<JetExpression> {
|
||||
fun createDummyExpressions(count: Int): List<KtExpression> {
|
||||
while (expressions.size() < count) {
|
||||
expressions.add(factory.createExpression("dummy"))
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
|
||||
public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType {
|
||||
public fun approximateFlexibleTypes(jetType: KtType, outermost: Boolean = true): KtType {
|
||||
if (jetType.isDynamic()) return jetType
|
||||
if (jetType.isFlexible()) {
|
||||
val flexible = jetType.flexibility()
|
||||
@@ -60,7 +60,7 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
||||
|
||||
return approximation
|
||||
}
|
||||
return JetTypeImpl.create(
|
||||
return KtTypeImpl.create(
|
||||
jetType.getAnnotations(),
|
||||
jetType.getConstructor(),
|
||||
jetType.isMarkedNullable(),
|
||||
@@ -69,15 +69,15 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
||||
)
|
||||
}
|
||||
|
||||
public fun JetType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
public fun JetType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
public fun JetType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
public fun KtType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
public fun KtType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
public fun KtType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
|
||||
private fun JetType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnotations()) {
|
||||
private fun KtType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnotations()) {
|
||||
findAnnotation(fqName) ?: findExternalAnnotation(fqName)
|
||||
} != null
|
||||
|
||||
fun JetType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
|
||||
fun KtType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
|
||||
if (canBeReferencedViaImport()) return true
|
||||
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
@@ -87,13 +87,13 @@ fun JetType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boole
|
||||
return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
|
||||
}
|
||||
|
||||
public fun JetType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): JetType {
|
||||
public fun KtType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KtType {
|
||||
if (isError() || isResolvableInScope(scope, checkTypeParameters)) return this
|
||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
||||
?: builtIns.anyType
|
||||
}
|
||||
|
||||
public fun JetType.anonymousObjectSuperTypeOrNull(): JetType? {
|
||||
public fun KtType.anonymousObjectSuperTypeOrNull(): KtType? {
|
||||
val classDescriptor = constructor.declarationDescriptor
|
||||
if (classDescriptor != null && DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
||||
return immediateSupertypes().firstOrNull() ?: classDescriptor.builtIns.anyType
|
||||
|
||||
@@ -19,23 +19,23 @@ package org.jetbrains.kotlin.idea.util
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public fun JetFunctionLiteral.findLabelAndCall(): Pair<Name?, JetCallExpression?> {
|
||||
val literalParent = (this.getParent() as JetFunctionLiteralExpression).getParent()
|
||||
public fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
val literalParent = (this.getParent() as KtFunctionLiteralExpression).getParent()
|
||||
|
||||
fun JetValueArgument.callExpression(): JetCallExpression? {
|
||||
fun KtValueArgument.callExpression(): KtCallExpression? {
|
||||
val parent = getParent()
|
||||
return (if (parent is JetValueArgumentList) parent else this).getParent() as? JetCallExpression
|
||||
return (if (parent is KtValueArgumentList) parent else this).getParent() as? KtCallExpression
|
||||
}
|
||||
|
||||
when (literalParent) {
|
||||
is JetLabeledExpression -> {
|
||||
val callExpression = (literalParent.getParent() as? JetValueArgument)?.callExpression()
|
||||
is KtLabeledExpression -> {
|
||||
val callExpression = (literalParent.getParent() as? KtValueArgument)?.callExpression()
|
||||
return Pair(literalParent.getLabelNameAsName(), callExpression)
|
||||
}
|
||||
|
||||
is JetValueArgument -> {
|
||||
is KtValueArgument -> {
|
||||
val callExpression = literalParent.callExpression()
|
||||
val label = (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedNameAsName()
|
||||
val label = (callExpression?.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedNameAsName()
|
||||
return Pair(label, callExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@ package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||
import org.jetbrains.kotlin.psi.JetThisExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
@@ -51,7 +51,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.substituteExtensionIfCallableWithImplicitReceiver(
|
||||
scope: JetScope,
|
||||
scope: KtScope,
|
||||
context: BindingContext,
|
||||
dataFlowInfo: DataFlowInfo
|
||||
): Collection<CallableDescriptor> {
|
||||
@@ -73,7 +73,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
receiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>
|
||||
): Collection<CallableDescriptor> {
|
||||
if (!callType.descriptorKindFilter.accepts(this)) return listOf()
|
||||
@@ -105,7 +105,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
public fun ReceiverValue.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
return when (this) {
|
||||
is ExpressionReceiver -> {
|
||||
val thisRef = (JetPsiUtil.deparenthesize(this.getExpression()) as? JetThisExpression)?.getInstanceReference() ?: return null
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.getExpression()) as? KtThisExpression)?.getInstanceReference() ?: return null
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
||||
}
|
||||
|
||||
|
||||
@@ -21,24 +21,24 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import java.util.LinkedHashMap
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public fun JetScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
public fun KtScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
= getImplicitReceiversWithInstanceToExpression().keySet()
|
||||
|
||||
public interface ReceiverExpressionFactory {
|
||||
public fun createExpression(psiFactory: JetPsiFactory, shortThis: Boolean = true): JetExpression
|
||||
public fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean = true): KtExpression
|
||||
}
|
||||
|
||||
public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<ReceiverParameterDescriptor, ReceiverExpressionFactory?> {
|
||||
public fun KtScope.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())
|
||||
|
||||
@@ -74,7 +74,7 @@ public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<Receiver
|
||||
}
|
||||
val factory = if (expressionText != null)
|
||||
object : ReceiverExpressionFactory {
|
||||
override fun createExpression(psiFactory: JetPsiFactory, shortThis: Boolean): JetExpression {
|
||||
override fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean): KtExpression {
|
||||
return psiFactory.createExpression(if (shortThis && isImmediateThis) "this" else expressionText)
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,6 @@ private fun thisQualifierName(receiver: ReceiverParameterDescriptor): Name? {
|
||||
val name = descriptor.getName()
|
||||
if (!name.isSpecial()) return name
|
||||
|
||||
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral
|
||||
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? KtFunctionLiteral
|
||||
return functionLiteral?.findLabelAndCall()?.first
|
||||
}
|
||||
|
||||
@@ -22,21 +22,21 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
|
||||
|
||||
public fun JetScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
||||
public fun KtScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
||||
= getVariablesFromImplicitReceivers(name) + getProperties(name, NoLookupLocation.FROM_IDE) + listOfNotNull(getLocalVariable(name))
|
||||
|
||||
public fun JetScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor>
|
||||
public fun KtScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor>
|
||||
= getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) } +
|
||||
getFunctions(name, NoLookupLocation.FROM_IDE)
|
||||
|
||||
public fun JetScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
public fun KtScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
public fun JetScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
public fun KtScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
getImplicitReceiversWithInstance().forEach {
|
||||
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.JetNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.StatementFilter
|
||||
@@ -33,8 +33,8 @@ import java.util.HashSet
|
||||
//TODO: do resolve anonymous object's body
|
||||
|
||||
class PartialBodyResolveFilter(
|
||||
elementToResolve: JetElement,
|
||||
private val declaration: JetDeclaration,
|
||||
elementToResolve: KtElement,
|
||||
private val declaration: KtDeclaration,
|
||||
probablyNothingCallableNames: ProbablyNothingCallableNames,
|
||||
forCompletion: Boolean
|
||||
) : StatementFilter() {
|
||||
@@ -44,20 +44,20 @@ class PartialBodyResolveFilter(
|
||||
private val nothingFunctionNames = HashSet(probablyNothingCallableNames.functionNames())
|
||||
private val nothingVariableNames = HashSet(probablyNothingCallableNames.propertyNames())
|
||||
|
||||
override val filter: ((JetExpression) -> Boolean)? = { statementMarks.statementMark(it) != MarkLevel.NONE }
|
||||
override val filter: ((KtExpression) -> Boolean)? = { statementMarks.statementMark(it) != MarkLevel.NONE }
|
||||
|
||||
val allStatementsToResolve: Collection<JetExpression>
|
||||
val allStatementsToResolve: Collection<KtExpression>
|
||||
get() = statementMarks.allMarkedStatements()
|
||||
|
||||
init {
|
||||
assert(declaration.isAncestor(elementToResolve))
|
||||
assert(!JetPsiUtil.isLocal(declaration)) { "Should never be invoked on local declaration otherwise we may miss some local declarations with type Nothing" }
|
||||
assert(!KtPsiUtil.isLocal(declaration)) { "Should never be invoked on local declaration otherwise we may miss some local declarations with type Nothing" }
|
||||
|
||||
declaration.forEachDescendantOfType<JetCallableDeclaration> { declaration ->
|
||||
declaration.forEachDescendantOfType<KtCallableDeclaration> { declaration ->
|
||||
if (declaration.getTypeReference().containsProbablyNothing()) {
|
||||
val name = declaration.getName()
|
||||
if (name != null) {
|
||||
if (declaration is JetNamedFunction) {
|
||||
if (declaration is KtNamedFunction) {
|
||||
nothingFunctionNames.add(name)
|
||||
}
|
||||
else {
|
||||
@@ -73,7 +73,7 @@ class PartialBodyResolveFilter(
|
||||
|
||||
//TODO: do..while is special case
|
||||
|
||||
private fun processBlock(block: JetBlockExpression): NameFilter {
|
||||
private fun processBlock(block: KtBlockExpression): NameFilter {
|
||||
if (isValueNeeded(block)) {
|
||||
block.lastStatement()?.let { statementMarks.mark(it, MarkLevel.NEED_REFERENCE_RESOLVE) }
|
||||
}
|
||||
@@ -82,15 +82,15 @@ class PartialBodyResolveFilter(
|
||||
val startStatement = statementMarks.lastMarkedStatement(block, MarkLevel.NEED_REFERENCE_RESOLVE) ?: return nameFilter
|
||||
|
||||
for (statement in startStatement.siblings(forward = false)) {
|
||||
if (statement !is JetExpression) continue
|
||||
if (statement !is KtExpression) continue
|
||||
|
||||
if (statement is JetNamedDeclaration) {
|
||||
if (statement is KtNamedDeclaration) {
|
||||
val name = statement.getName()
|
||||
if (name != null && nameFilter(name)) {
|
||||
statementMarks.mark(statement, MarkLevel.NEED_REFERENCE_RESOLVE)
|
||||
}
|
||||
}
|
||||
else if (statement is JetMultiDeclaration) {
|
||||
else if (statement is KtMultiDeclaration) {
|
||||
if (statement.getEntries().any {
|
||||
val name = it.getName()
|
||||
name != null && nameFilter(name)
|
||||
@@ -138,22 +138,22 @@ class PartialBodyResolveFilter(
|
||||
* Returns map from smart-cast expression names (variable name or qualified variable name) to places.
|
||||
*/
|
||||
private fun potentialSmartCastPlaces(
|
||||
statement: JetExpression,
|
||||
statement: KtExpression,
|
||||
filter: (SmartCastName) -> Boolean = { true }
|
||||
): Map<SmartCastName, List<JetExpression>> {
|
||||
val map = HashMap<SmartCastName, ArrayList<JetExpression>>(0)
|
||||
): Map<SmartCastName, List<KtExpression>> {
|
||||
val map = HashMap<SmartCastName, ArrayList<KtExpression>>(0)
|
||||
|
||||
fun addPlace(name: SmartCastName, place: JetExpression) {
|
||||
fun addPlace(name: SmartCastName, place: KtExpression) {
|
||||
map.getOrPut(name, { ArrayList(1) }).add(place)
|
||||
}
|
||||
|
||||
fun addPlaces(name: SmartCastName, places: Collection<JetExpression>) {
|
||||
fun addPlaces(name: SmartCastName, places: Collection<KtExpression>) {
|
||||
if (places.isNotEmpty()) {
|
||||
map.getOrPut(name, { ArrayList(places.size()) }).addAll(places)
|
||||
}
|
||||
}
|
||||
|
||||
fun addIfCanBeSmartCast(expression: JetExpression) {
|
||||
fun addIfCanBeSmartCast(expression: KtExpression) {
|
||||
val name = expression.smartCastExpressionName() ?: return
|
||||
if (filter(name)) {
|
||||
addPlace(name, expression)
|
||||
@@ -161,26 +161,26 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
statement.accept(object : ControlFlowVisitor() {
|
||||
override fun visitPostfixExpression(expression: JetPostfixExpression) {
|
||||
override fun visitPostfixExpression(expression: KtPostfixExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == JetTokens.EXCLEXCL) {
|
||||
if (expression.getOperationToken() == KtTokens.EXCLEXCL) {
|
||||
addIfCanBeSmartCast(expression.getBaseExpression() ?: return)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: JetBinaryExpressionWithTypeRHS) {
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: KtBinaryExpressionWithTypeRHS) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.AS_KEYWORD) {
|
||||
if (expression.getOperationReference().getReferencedNameElementType() == KtTokens.AS_KEYWORD) {
|
||||
addIfCanBeSmartCast(expression.getLeft())
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: JetBinaryExpression) {
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == JetTokens.ELVIS) {
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
val left = expression.getLeft()
|
||||
val right = expression.getRight()
|
||||
if (left != null && right != null) {
|
||||
@@ -193,14 +193,14 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: JetIfExpression) {
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
val condition = expression.getCondition()
|
||||
val thenBranch = expression.getThen()
|
||||
val elseBranch = expression.getElse()
|
||||
|
||||
val (thenSmartCastNames, elseSmartCastNames) = possiblySmartCastInCondition(condition)
|
||||
|
||||
fun processBranchExits(smartCastNames: Collection<SmartCastName>, branch: JetExpression?) {
|
||||
fun processBranchExits(smartCastNames: Collection<SmartCastName>, branch: KtExpression?) {
|
||||
if (branch == null) return
|
||||
val filteredNames = smartCastNames.filter(filter)
|
||||
if (filteredNames.isNotEmpty()) {
|
||||
@@ -237,12 +237,12 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitForExpression(expression: JetForExpression) {
|
||||
override fun visitForExpression(expression: KtForExpression) {
|
||||
// analyze only the loop-range expression, do not enter the loop body
|
||||
expression.getLoopRange()?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(expression: JetWhileExpression) {
|
||||
override fun visitWhileExpression(expression: KtWhileExpression) {
|
||||
val condition = expression.getCondition()
|
||||
// we need to enter the body only for "while(true)"
|
||||
if (condition.isTrueConstant()) {
|
||||
@@ -264,10 +264,10 @@ class PartialBodyResolveFilter(
|
||||
* in then (first component) and else (second component)
|
||||
* branches of an if-statement with such condition
|
||||
*/
|
||||
private fun possiblySmartCastInCondition(condition: JetExpression?): Pair<Set<SmartCastName>, Set<SmartCastName>> {
|
||||
private fun possiblySmartCastInCondition(condition: KtExpression?): Pair<Set<SmartCastName>, Set<SmartCastName>> {
|
||||
val emptyResult = Pair(setOf<SmartCastName>(), setOf<SmartCastName>())
|
||||
when (condition) {
|
||||
is JetBinaryExpression -> {
|
||||
is KtBinaryExpression -> {
|
||||
val operation = condition.getOperationToken()
|
||||
val left = condition.getLeft() ?: return emptyResult
|
||||
val right = condition.getRight() ?: return emptyResult
|
||||
@@ -288,17 +288,17 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
when (operation) {
|
||||
JetTokens.EQEQ, JetTokens.EQEQEQ -> return smartCastInEq()
|
||||
KtTokens.EQEQ, KtTokens.EQEQEQ -> return smartCastInEq()
|
||||
|
||||
JetTokens.EXCLEQ, JetTokens.EXCLEQEQEQ -> return smartCastInEq().swap()
|
||||
KtTokens.EXCLEQ, KtTokens.EXCLEQEQEQ -> return smartCastInEq().swap()
|
||||
|
||||
JetTokens.ANDAND -> {
|
||||
KtTokens.ANDAND -> {
|
||||
val casts1 = possiblySmartCastInCondition(left)
|
||||
val casts2 = possiblySmartCastInCondition(right)
|
||||
return Pair(casts1.first.union(casts2.first), casts1.second.intersect(casts2.second))
|
||||
}
|
||||
|
||||
JetTokens.OROR -> {
|
||||
KtTokens.OROR -> {
|
||||
val casts1 = possiblySmartCastInCondition(left)
|
||||
val casts2 = possiblySmartCastInCondition(right)
|
||||
return Pair(casts1.first.intersect(casts2.first), casts1.second.union(casts2.second))
|
||||
@@ -306,19 +306,19 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
is JetIsExpression -> {
|
||||
is KtIsExpression -> {
|
||||
val cast = condition.getLeftHandSide().smartCastExpressionName().singletonOrEmptySet()
|
||||
return if (condition.isNegated()) Pair(setOf(), cast) else Pair(cast, setOf())
|
||||
}
|
||||
|
||||
is JetPrefixExpression -> {
|
||||
if (condition.getOperationToken() == JetTokens.EXCL) {
|
||||
is KtPrefixExpression -> {
|
||||
if (condition.getOperationToken() == KtTokens.EXCL) {
|
||||
val operand = condition.getBaseExpression() ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand).swap()
|
||||
}
|
||||
}
|
||||
|
||||
is JetParenthesizedExpression -> {
|
||||
is KtParenthesizedExpression -> {
|
||||
val operand = condition.getExpression() ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand)
|
||||
}
|
||||
@@ -331,20 +331,20 @@ class PartialBodyResolveFilter(
|
||||
* If it's possible that the given statement never passes the execution to the next statement (that is, always exits somewhere)
|
||||
* then this function returns a collection of all places in code that are necessary to be kept to preserve this behaviour.
|
||||
*/
|
||||
private fun collectAlwaysExitPoints(statement: JetExpression?): Collection<JetExpression> {
|
||||
val result = ArrayList<JetExpression>()
|
||||
private fun collectAlwaysExitPoints(statement: KtExpression?): Collection<KtExpression> {
|
||||
val result = ArrayList<KtExpression>()
|
||||
statement?.accept(object : ControlFlowVisitor() {
|
||||
var insideLoopLevel: Int = 0
|
||||
|
||||
override fun visitReturnExpression(expression: JetReturnExpression) {
|
||||
override fun visitReturnExpression(expression: KtReturnExpression) {
|
||||
result.add(expression)
|
||||
}
|
||||
|
||||
override fun visitThrowExpression(expression: JetThrowExpression) {
|
||||
override fun visitThrowExpression(expression: KtThrowExpression) {
|
||||
result.add(expression)
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: JetIfExpression) {
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
expression.getCondition()?.accept(this)
|
||||
|
||||
val thenBranch = expression.getThen()
|
||||
@@ -361,12 +361,12 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitForExpression(loop: JetForExpression) {
|
||||
override fun visitForExpression(loop: KtForExpression) {
|
||||
loop.getLoopRange()?.accept(this)
|
||||
// do not make sense to search exits inside for as not necessary enter it at all
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(loop: JetWhileExpression) {
|
||||
override fun visitWhileExpression(loop: KtWhileExpression) {
|
||||
val condition = loop.getCondition() ?: return
|
||||
if (condition.isTrueConstant()) {
|
||||
insideLoopLevel++
|
||||
@@ -379,42 +379,42 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitDoWhileExpression(loop: JetDoWhileExpression) {
|
||||
override fun visitDoWhileExpression(loop: KtDoWhileExpression) {
|
||||
loop.getCondition()?.accept(this)
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
insideLoopLevel--
|
||||
}
|
||||
|
||||
override fun visitBreakExpression(expression: JetBreakExpression) {
|
||||
override fun visitBreakExpression(expression: KtBreakExpression) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitContinueExpression(expression: JetContinueExpression) {
|
||||
override fun visitContinueExpression(expression: KtContinueExpression) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: JetCallExpression) {
|
||||
val name = (expression.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName()
|
||||
override fun visitCallExpression(expression: KtCallExpression) {
|
||||
val name = (expression.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedName()
|
||||
if (name != null && name in nothingFunctionNames) {
|
||||
result.add(expression)
|
||||
}
|
||||
super.visitCallExpression(expression)
|
||||
}
|
||||
|
||||
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
|
||||
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
|
||||
val name = expression.getReferencedName()
|
||||
if (name in nothingVariableNames) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: JetBinaryExpression) {
|
||||
if (expression.getOperationToken() == JetTokens.ELVIS) {
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
// do not search exits after "?:"
|
||||
expression.getLeft()?.accept(this)
|
||||
}
|
||||
@@ -429,13 +429,13 @@ class PartialBodyResolveFilter(
|
||||
/**
|
||||
* Recursively visits code but does not enter constructs that may not affect smart casts/control flow
|
||||
*/
|
||||
private abstract class ControlFlowVisitor : JetVisitorVoid() {
|
||||
override fun visitJetElement(element: JetElement) {
|
||||
private abstract class ControlFlowVisitor : KtVisitorVoid() {
|
||||
override fun visitJetElement(element: KtElement) {
|
||||
if (element.noControlFlowInside()) return
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
private fun JetElement.noControlFlowInside() = this is JetFunction || this is JetClass || this is JetClassBody
|
||||
private fun KtElement.noControlFlowInside() = this is KtFunction || this is KtClass || this is KtClassBody
|
||||
}
|
||||
|
||||
private data class SmartCastName(
|
||||
@@ -457,22 +457,22 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetExpression.smartCastExpressionName(): SmartCastName? {
|
||||
private fun KtExpression.smartCastExpressionName(): SmartCastName? {
|
||||
return when (this) {
|
||||
is JetSimpleNameExpression -> SmartCastName(null, this.getReferencedName())
|
||||
is KtSimpleNameExpression -> SmartCastName(null, this.getReferencedName())
|
||||
|
||||
is JetQualifiedExpression -> {
|
||||
val selector = getSelectorExpression() as? JetSimpleNameExpression ?: return null
|
||||
is KtQualifiedExpression -> {
|
||||
val selector = getSelectorExpression() as? KtSimpleNameExpression ?: return null
|
||||
val selectorName = selector.getReferencedName()
|
||||
val receiver = getReceiverExpression()
|
||||
if (receiver is JetThisExpression) {
|
||||
if (receiver is KtThisExpression) {
|
||||
return SmartCastName(null, selectorName)
|
||||
}
|
||||
val receiverName = receiver.smartCastExpressionName() ?: return null
|
||||
return SmartCastName(receiverName, selectorName)
|
||||
}
|
||||
|
||||
is JetThisExpression -> SmartCastName(null, null)
|
||||
is KtThisExpression -> SmartCastName(null, null)
|
||||
|
||||
else -> null
|
||||
}
|
||||
@@ -487,9 +487,9 @@ class PartialBodyResolveFilter(
|
||||
val isEmpty: Boolean
|
||||
get() = names?.isEmpty() ?: false
|
||||
|
||||
fun addUsedNames(statement: JetExpression) {
|
||||
fun addUsedNames(statement: KtExpression) {
|
||||
if (names != null) {
|
||||
statement.forEachDescendantOfType<JetSimpleNameExpression>(canGoInside = { it !is JetBlockExpression }) {
|
||||
statement.forEachDescendantOfType<KtSimpleNameExpression>(canGoInside = { it !is KtBlockExpression }) {
|
||||
names!!.add(it.getReferencedName())
|
||||
}
|
||||
}
|
||||
@@ -518,74 +518,74 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun findStatementToResolve(element: JetElement, declaration: JetDeclaration): JetExpression? {
|
||||
return element.parentsWithSelf.takeWhile { it != declaration }.firstOrNull { it.isStatement() } as JetExpression?
|
||||
public fun findStatementToResolve(element: KtElement, declaration: KtDeclaration): KtExpression? {
|
||||
return element.parentsWithSelf.takeWhile { it != declaration }.firstOrNull { it.isStatement() } as KtExpression?
|
||||
}
|
||||
|
||||
private fun JetElement.forTopLevelBlocksInside(action: (JetBlockExpression) -> Unit) {
|
||||
forEachDescendantOfType(canGoInside = { it !is JetBlockExpression }, action = action)
|
||||
private fun KtElement.forTopLevelBlocksInside(action: (KtBlockExpression) -> Unit) {
|
||||
forEachDescendantOfType(canGoInside = { it !is KtBlockExpression }, action = action)
|
||||
}
|
||||
|
||||
private fun JetExpression?.isNullLiteral() = this?.getNode()?.getElementType() == JetNodeTypes.NULL
|
||||
private fun KtExpression?.isNullLiteral() = this?.getNode()?.getElementType() == KtNodeTypes.NULL
|
||||
|
||||
private fun JetExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == JetNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
private fun KtExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == KtNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
|
||||
private fun <T : Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) setOf(this) else setOf()
|
||||
|
||||
//TODO: review logic
|
||||
private fun isValueNeeded(expression: JetExpression): Boolean {
|
||||
private fun isValueNeeded(expression: KtExpression): Boolean {
|
||||
val parent = expression.getParent()
|
||||
return when (parent) {
|
||||
is JetBlockExpression -> expression == parent.lastStatement() && isValueNeeded(parent)
|
||||
is KtBlockExpression -> expression == parent.lastStatement() && isValueNeeded(parent)
|
||||
|
||||
is JetContainerNode -> { //TODO - not quite correct
|
||||
val pparent = parent.getParent() as? JetExpression
|
||||
is KtContainerNode -> { //TODO - not quite correct
|
||||
val pparent = parent.getParent() as? KtExpression
|
||||
pparent != null && isValueNeeded(pparent)
|
||||
}
|
||||
|
||||
is JetDeclarationWithBody -> {
|
||||
is KtDeclarationWithBody -> {
|
||||
if (expression == parent.getBodyExpression())
|
||||
!parent.hasBlockBody() && !parent.hasDeclaredReturnType()
|
||||
else
|
||||
true
|
||||
}
|
||||
|
||||
is JetClassInitializer -> false
|
||||
is KtClassInitializer -> false
|
||||
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetBlockExpression.lastStatement(): JetExpression?
|
||||
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<JetExpression>()
|
||||
private fun KtBlockExpression.lastStatement(): KtExpression?
|
||||
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<KtExpression>()
|
||||
|
||||
private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression
|
||||
private fun PsiElement.isStatement() = this is KtExpression && getParent() is KtBlockExpression
|
||||
|
||||
private fun JetTypeReference?.containsProbablyNothing()
|
||||
= this?.typeElement?.anyDescendantOfType<JetUserType> { it.isProbablyNothing() } ?: false
|
||||
private fun KtTypeReference?.containsProbablyNothing()
|
||||
= this?.typeElement?.anyDescendantOfType<KtUserType> { it.isProbablyNothing() } ?: false
|
||||
}
|
||||
|
||||
private inner class StatementMarks {
|
||||
private val statementMarks = HashMap<JetExpression, MarkLevel>()
|
||||
private val blockLevels = HashMap<JetBlockExpression, MarkLevel>()
|
||||
private val statementMarks = HashMap<KtExpression, MarkLevel>()
|
||||
private val blockLevels = HashMap<KtBlockExpression, MarkLevel>()
|
||||
|
||||
fun mark(element: PsiElement, level: MarkLevel) {
|
||||
var e = element
|
||||
while (e != declaration) {
|
||||
if (e.isStatement()) {
|
||||
markStatement(e as JetExpression, level)
|
||||
markStatement(e as KtExpression, level)
|
||||
}
|
||||
e = e.getParent()!!
|
||||
}
|
||||
}
|
||||
|
||||
private fun markStatement(statement: JetExpression, level: MarkLevel) {
|
||||
private fun markStatement(statement: KtExpression, level: MarkLevel) {
|
||||
val currentLevel = statementMark(statement)
|
||||
if (currentLevel < level) {
|
||||
statementMarks[statement] = level
|
||||
|
||||
val block = statement.getParent() as JetBlockExpression
|
||||
val block = statement.getParent() as KtBlockExpression
|
||||
val currentBlockLevel = blockLevels[block] ?: MarkLevel.NONE
|
||||
if (currentBlockLevel < level) {
|
||||
blockLevels[block] = level
|
||||
@@ -593,17 +593,17 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
fun statementMark(statement: JetExpression): MarkLevel
|
||||
fun statementMark(statement: KtExpression): MarkLevel
|
||||
= statementMarks[statement] ?: MarkLevel.NONE
|
||||
|
||||
fun allMarkedStatements(): Collection<JetExpression>
|
||||
fun allMarkedStatements(): Collection<KtExpression>
|
||||
= statementMarks.keySet()
|
||||
|
||||
fun lastMarkedStatement(block: JetBlockExpression, minLevel: MarkLevel): JetExpression? {
|
||||
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)
|
||||
.filterIsInstance<JetExpression>()
|
||||
.filterIsInstance<KtExpression>()
|
||||
.first { statementMark(it) >= minLevel }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ import com.google.common.collect.Multimap
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.JetUserType
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
|
||||
public fun JetUserType.aliasImportMap(): Multimap<String, String> {
|
||||
public 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()
|
||||
return (file as JetFile).aliasImportMap()
|
||||
return (file as KtFile).aliasImportMap()
|
||||
}
|
||||
|
||||
private fun JetFile.aliasImportMap(): Multimap<String, String> {
|
||||
private fun KtFile.aliasImportMap(): Multimap<String, String> {
|
||||
val cached = getUserData(ALIAS_IMPORT_DATA_KEY)
|
||||
val modificationStamp = getModificationStamp()
|
||||
if (cached != null && modificationStamp == cached.fileModificationStamp) {
|
||||
@@ -43,7 +43,7 @@ private fun JetFile.aliasImportMap(): Multimap<String, String> {
|
||||
return data.map
|
||||
}
|
||||
|
||||
private fun JetFile.buildAliasImportMap(): 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()) {
|
||||
@@ -58,12 +58,12 @@ private class CachedAliasImportData(val map: Multimap<String, String>, val fileM
|
||||
|
||||
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
|
||||
|
||||
public fun JetTypeReference?.isProbablyNothing(): Boolean {
|
||||
val userType = this?.typeElement as? JetUserType ?: return false
|
||||
public fun KtTypeReference?.isProbablyNothing(): Boolean {
|
||||
val userType = this?.typeElement as? KtUserType ?: return false
|
||||
return userType.isProbablyNothing()
|
||||
}
|
||||
|
||||
public fun JetUserType?.isProbablyNothing(): Boolean {
|
||||
public fun KtUserType?.isProbablyNothing(): Boolean {
|
||||
if (this == null) return false
|
||||
val referencedName = getReferencedName()
|
||||
return referencedName == "Nothing" || aliasImportMap()[referencedName].contains("Nothing")
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import org.jetbrains.kotlin.types.typeUtil.equalTypesOrNulls
|
||||
|
||||
@@ -32,7 +32,7 @@ public fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?,
|
||||
if (descriptor1 !is CallableDescriptor) return true
|
||||
descriptor2 as CallableDescriptor
|
||||
|
||||
val typeChecker = JetTypeChecker.withAxioms(object: JetTypeChecker.TypeConstructorEquality {
|
||||
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
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
public fun getTypeSubstitution(baseType: JetType, derivedType: JetType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
public fun getTypeSubstitution(baseType: KtType, derivedType: KtType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
val substitutedType = TypeCheckingProcedure.findCorrespondingSupertype(derivedType, baseType) ?: return null
|
||||
|
||||
val substitution = LinkedHashMap<TypeConstructor, TypeProjection>(substitutedType.getArguments().size())
|
||||
@@ -55,6 +55,6 @@ public fun getCallableSubstitutor(
|
||||
return getCallableSubstitution(baseCallable, derivedCallable)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
public fun getTypeSubstitutor(baseType: JetType, derivedType: JetType): TypeSubstitutor? {
|
||||
public fun getTypeSubstitutor(baseType: KtType, derivedType: KtType): TypeSubstitutor? {
|
||||
return getTypeSubstitution(baseType, derivedType)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user