rename Jet* classes to Kt*
This commit is contained in:
+4
-4
@@ -26,9 +26,9 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
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
|
||||
|
||||
class AllClassesCompletion(private val parameters: CompletionParameters,
|
||||
@@ -51,12 +51,12 @@ class AllClassesCompletion(private val parameters: CompletionParameters,
|
||||
.getKotlinClasses({ prefixMatcher.prefixMatches(it) }, kindFilter)
|
||||
.forEach { classDescriptorCollector(it) }
|
||||
|
||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.originalFile as JetFile)) {
|
||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.originalFile as KtFile)) {
|
||||
addAdaptedJavaCompletion(javaClassCollector)
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectClassesFromScope(scope: JetScope, collector: (ClassDescriptor) -> Unit) {
|
||||
private fun collectClassesFromScope(scope: KtScope, collector: (ClassDescriptor) -> Unit) {
|
||||
for (descriptor in scope.getDescriptorsFiltered(DescriptorKindFilter.CLASSIFIERS)) {
|
||||
if (descriptor is ClassDescriptor) {
|
||||
if (kindFilter(descriptor.kind) && prefixMatcher.prefixMatches(descriptor.name.asString())) {
|
||||
|
||||
+12
-12
@@ -110,7 +110,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
if (nameExpression == null) {
|
||||
val parameter = position.getParent() as? JetParameter
|
||||
val parameter = position.getParent() as? KtParameter
|
||||
return if (parameter != null && position == parameter.getNameIdentifier())
|
||||
CompletionKind.PARAMETER_NAME
|
||||
else
|
||||
@@ -119,13 +119,13 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
|
||||
// Check that completion in the type annotation context and if there's a qualified
|
||||
// expression we are at first of it
|
||||
val typeReference = position.getStrictParentOfType<JetTypeReference>()
|
||||
val typeReference = position.getStrictParentOfType<KtTypeReference>()
|
||||
if (typeReference != null) {
|
||||
if (typeReference.parent is JetSuperExpression) {
|
||||
if (typeReference.parent is KtSuperExpression) {
|
||||
return CompletionKind.SUPER_QUALIFIER
|
||||
}
|
||||
|
||||
val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass<JetSimpleNameExpression>())
|
||||
val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass<KtSimpleNameExpression>())
|
||||
if (firstPartReference == nameExpression) {
|
||||
return CompletionKind.TYPES
|
||||
}
|
||||
@@ -137,13 +137,13 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
private fun shouldCompleteParameterNameAndType(): Boolean {
|
||||
if (completionKind != CompletionKind.PARAMETER_NAME) return false
|
||||
|
||||
val parameter = position.getNonStrictParentOfType<JetParameter>()!!
|
||||
val list = parameter.parent as? JetParameterList ?: return false
|
||||
val parameter = position.getNonStrictParentOfType<KtParameter>()!!
|
||||
val list = parameter.parent as? KtParameterList ?: return false
|
||||
val owner = list.parent
|
||||
return when (owner) {
|
||||
is JetCatchClause, is JetPropertyAccessor, is JetFunctionLiteral -> false
|
||||
is JetNamedFunction -> owner.nameIdentifier != null
|
||||
is JetPrimaryConstructor -> !owner.getContainingClassOrObject().isAnnotation()
|
||||
is KtCatchClause, is KtPropertyAccessor, is KtFunctionLiteral -> false
|
||||
is KtNamedFunction -> owner.nameIdentifier != null
|
||||
is KtPrimaryConstructor -> !owner.getContainingClassOrObject().isAnnotation()
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
val packageNames = PackageIndexUtil.getSubPackageFqNames(FqName.ROOT, originalSearchScope, project, prefixMatcher.asNameFilter())
|
||||
.toMutableSet()
|
||||
|
||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as JetFile)) {
|
||||
if (!ProjectStructureUtil.isJsKotlinModule(parameters.getOriginalFile() as KtFile)) {
|
||||
JavaPsiFacade.getInstance(project).findPackage("")?.getSubPackages(originalSearchScope)?.forEach { psiPackage ->
|
||||
val name = psiPackage.getName()
|
||||
if (Name.isValidIdentifier(name!!)) {
|
||||
@@ -242,7 +242,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
|
||||
completeNonImported()
|
||||
|
||||
if (position.getContainingFile() is JetCodeFragment) {
|
||||
if (position.getContainingFile() is KtCodeFragment) {
|
||||
flushToResultSet()
|
||||
collector.addDescriptorElements(getRuntimeReceiverTypeReferenceVariants(), withReceiverCast = true)
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
private fun completeSuperQualifier() {
|
||||
val classOrObject = position.parents.firstIsInstanceOrNull<JetClassOrObject>() ?: return
|
||||
val classOrObject = position.parents.firstIsInstanceOrNull<KtClassOrObject>() ?: return
|
||||
val classDescriptor = resolutionFacade.resolveToDescriptor(classOrObject) as ClassDescriptor
|
||||
var superClasses = classDescriptor.defaultType.constructor.supertypes
|
||||
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
|
||||
+18
-18
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
@@ -68,21 +68,21 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
protected val parameters: CompletionParameters,
|
||||
resultSet: CompletionResultSet) {
|
||||
protected val position = parameters.getPosition()
|
||||
private val file = position.getContainingFile() as JetFile
|
||||
private val file = position.getContainingFile() as KtFile
|
||||
protected val resolutionFacade = file.getResolutionFacade()
|
||||
protected val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
protected val project = position.getProject()
|
||||
protected val isJvmModule = !ProjectStructureUtil.isJsKotlinModule(parameters.originalFile as JetFile)
|
||||
protected val isJvmModule = !ProjectStructureUtil.isJsKotlinModule(parameters.originalFile as KtFile)
|
||||
|
||||
protected val nameExpression: JetSimpleNameExpression?
|
||||
protected val expression: JetExpression?
|
||||
protected val nameExpression: KtSimpleNameExpression?
|
||||
protected val expression: KtExpression?
|
||||
|
||||
init {
|
||||
val reference = (position.getParent() as? JetSimpleNameExpression)?.mainReference
|
||||
val reference = (position.getParent() as? KtSimpleNameExpression)?.mainReference
|
||||
if (reference != null) {
|
||||
if (reference.expression is JetLabelReferenceExpression) {
|
||||
if (reference.expression is KtLabelReferenceExpression) {
|
||||
this.nameExpression = null
|
||||
this.expression = reference.expression.getParent().getParent() as? JetExpressionWithLabel
|
||||
this.expression = reference.expression.getParent().getParent() as? KtExpressionWithLabel
|
||||
}
|
||||
else {
|
||||
this.nameExpression = reference.expression
|
||||
@@ -95,7 +95,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
}
|
||||
}
|
||||
|
||||
protected val bindingContext = resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance<JetElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
protected val bindingContext = resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance<KtElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
protected val inDescriptor = position.getResolutionScope(bindingContext, resolutionFacade).ownerDescriptor
|
||||
|
||||
private val kotlinIdentifierStartPattern = StandardPatterns.character().javaIdentifierStart() andNot singleCharPattern('$')
|
||||
@@ -139,7 +139,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
LookupElementsCollector(prefixMatcher, parameters, resultSet, lookupElementFactory, createSorter())
|
||||
}
|
||||
|
||||
protected val originalSearchScope: GlobalSearchScope = getResolveScope(parameters.getOriginalFile() as JetFile)
|
||||
protected val originalSearchScope: GlobalSearchScope = getResolveScope(parameters.getOriginalFile() as KtFile)
|
||||
|
||||
// we need to exclude the original file from scope because our resolve session is built with this file replaced by synthetic one
|
||||
protected val searchScope: GlobalSearchScope = object : DelegatingGlobalSearchScope(originalSearchScope) {
|
||||
@@ -150,7 +150,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
get() = KotlinIndicesHelper(resolutionFacade, searchScope, isVisibleFilter, true)
|
||||
|
||||
protected val toFromOriginalFileMapper: ToFromOriginalFileMapper
|
||||
= ToFromOriginalFileMapper(parameters.originalFile as JetFile, position.containingFile as JetFile, parameters.offset)
|
||||
= ToFromOriginalFileMapper(parameters.originalFile as KtFile, position.containingFile as KtFile, parameters.offset)
|
||||
|
||||
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor): Boolean {
|
||||
if (!configuration.completeJavaClassesNotToBeUsed && descriptor is ClassDescriptor) {
|
||||
@@ -257,14 +257,14 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
}
|
||||
|
||||
// filters out variable inside its initializer
|
||||
private fun Collection<DeclarationDescriptor>.excludeNonInitializedVariable(expression: JetExpression): Collection<DeclarationDescriptor> {
|
||||
private fun Collection<DeclarationDescriptor>.excludeNonInitializedVariable(expression: KtExpression): Collection<DeclarationDescriptor> {
|
||||
for (element in expression.parentsWithSelf) {
|
||||
val parent = element.getParent()
|
||||
if (parent is JetVariableDeclaration && element == parent.getInitializer()) {
|
||||
if (parent is KtVariableDeclaration && element == parent.getInitializer()) {
|
||||
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, parent]
|
||||
return this.filter { it != descriptor }
|
||||
}
|
||||
if (element is JetDeclaration) break // we can use variable inside lambda or anonymous object located in its initializer
|
||||
if (element is KtDeclaration) break // we can use variable inside lambda or anonymous object located in its initializer
|
||||
}
|
||||
return this
|
||||
}
|
||||
@@ -287,7 +287,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
|
||||
protected fun isNoQualifierContext(): Boolean {
|
||||
val parent = position.getParent()
|
||||
return parent is JetSimpleNameExpression && !JetPsiUtil.isSelectorInQualified(parent)
|
||||
return parent is KtSimpleNameExpression && !KtPsiUtil.isSelectorInQualified(parent)
|
||||
}
|
||||
|
||||
protected fun getTopLevelCallables(): Collection<DeclarationDescriptor> {
|
||||
@@ -313,7 +313,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
)
|
||||
}
|
||||
|
||||
private fun createLookupElementFactory(callType: CallType<*>?, receiverTypes: Collection<JetType>?): LookupElementFactory {
|
||||
private fun createLookupElementFactory(callType: CallType<*>?, receiverTypes: Collection<KtType>?): LookupElementFactory {
|
||||
val contextVariablesProvider = {
|
||||
nameExpression?.let {
|
||||
referenceVariantsHelper.getReferenceVariants(it, DescriptorKindFilter.VARIABLES, { true }, CallTypeAndReceiver.DEFAULT)
|
||||
@@ -323,11 +323,11 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
|
||||
val insertHandlerProvider = InsertHandlerProvider(callType) { expectedInfos }
|
||||
return LookupElementFactory(resolutionFacade, receiverTypes,
|
||||
callType, expression?.parent is JetSimpleNameStringTemplateEntry,
|
||||
callType, expression?.parent is KtSimpleNameStringTemplateEntry,
|
||||
insertHandlerProvider, contextVariablesProvider)
|
||||
}
|
||||
|
||||
private fun detectCallTypeAndReceiverTypes(): Pair<CallTypeAndReceiver<*, *>, Collection<JetType>?> {
|
||||
private fun detectCallTypeAndReceiverTypes(): Pair<CallTypeAndReceiver<*, *>, Collection<KtType>?> {
|
||||
if (nameExpression == null) {
|
||||
return CallTypeAndReceiver.UNKNOWN to null
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.JetIcons
|
||||
import org.jetbrains.kotlin.idea.KtIcons
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.CastReceiverInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
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.nullability
|
||||
import java.util.*
|
||||
@@ -188,35 +188,35 @@ class ThisItemLookupObject(val receiverParameter: ReceiverParameterDescriptor, v
|
||||
fun ThisItemLookupObject.createLookupElement() = createKeywordElement("this", labelName.labelNameToTail(), lookupObject = this)
|
||||
.withTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(receiverParameter.type))
|
||||
|
||||
fun thisExpressionItems(bindingContext: BindingContext, position: JetExpression, prefix: String, resolutionFacade: ResolutionFacade): Collection<ThisItemLookupObject> {
|
||||
fun thisExpressionItems(bindingContext: BindingContext, position: KtExpression, prefix: String, resolutionFacade: ResolutionFacade): Collection<ThisItemLookupObject> {
|
||||
val scope = position.getResolutionScope(bindingContext, resolutionFacade)
|
||||
|
||||
val psiFactory = JetPsiFactory(position)
|
||||
val psiFactory = KtPsiFactory(position)
|
||||
|
||||
val result = ArrayList<ThisItemLookupObject>()
|
||||
for ((receiver, expressionFactory) in scope.asJetScope().getImplicitReceiversWithInstanceToExpression()) {
|
||||
if (expressionFactory == null) continue
|
||||
// if prefix does not start with "this@" do not include immediate this in the form with label
|
||||
val expression = expressionFactory.createExpression(psiFactory, shortThis = !prefix.startsWith("this@")) as? JetThisExpression ?: continue
|
||||
val expression = expressionFactory.createExpression(psiFactory, shortThis = !prefix.startsWith("this@")) as? KtThisExpression ?: continue
|
||||
result.add(ThisItemLookupObject(receiver, expression.getLabelNameAsName()))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun returnExpressionItems(bindingContext: BindingContext, position: JetElement): Collection<LookupElement> {
|
||||
fun returnExpressionItems(bindingContext: BindingContext, position: KtElement): Collection<LookupElement> {
|
||||
val result = ArrayList<LookupElement>()
|
||||
for (parent in position.parentsWithSelf) {
|
||||
if (parent is JetDeclarationWithBody) {
|
||||
if (parent is KtDeclarationWithBody) {
|
||||
val returnType = parent.returnType(bindingContext)
|
||||
val isUnit = returnType == null || KotlinBuiltIns.isUnit(returnType)
|
||||
if (parent is JetFunctionLiteral) {
|
||||
if (parent is KtFunctionLiteral) {
|
||||
val (label, call) = parent.findLabelAndCall()
|
||||
if (label != null) {
|
||||
result.add(createKeywordElementWithSpace("return", tail = label.labelNameToTail(), addSpaceAfter = !isUnit))
|
||||
}
|
||||
|
||||
// check if the current function literal is inlined and stop processing outer declarations if it's not
|
||||
val callee = call?.getCalleeExpression() as? JetReferenceExpression ?: break // not inlined
|
||||
val callee = call?.getCalleeExpression() as? KtReferenceExpression ?: break // not inlined
|
||||
if (!InlineUtil.isInline(bindingContext[BindingContext.REFERENCE_TARGET, callee])) break // not inlined
|
||||
}
|
||||
else {
|
||||
@@ -247,7 +247,7 @@ fun returnExpressionItems(bindingContext: BindingContext, position: JetElement):
|
||||
return result
|
||||
}
|
||||
|
||||
private fun JetDeclarationWithBody.returnType(bindingContext: BindingContext): JetType? {
|
||||
private fun KtDeclarationWithBody.returnType(bindingContext: BindingContext): KtType? {
|
||||
val callable = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? CallableDescriptor ?: return null
|
||||
return callable.getReturnType()
|
||||
}
|
||||
@@ -287,35 +287,35 @@ private fun createKeywordElement(
|
||||
return element
|
||||
}
|
||||
|
||||
fun breakOrContinueExpressionItems(position: JetElement, breakOrContinue: String): Collection<LookupElement> {
|
||||
fun breakOrContinueExpressionItems(position: KtElement, breakOrContinue: String): Collection<LookupElement> {
|
||||
val result = ArrayList<LookupElement>()
|
||||
|
||||
parentsLoop@
|
||||
for (parent in position.parentsWithSelf) {
|
||||
when (parent) {
|
||||
is JetLoopExpression -> {
|
||||
is KtLoopExpression -> {
|
||||
if (result.isEmpty()) {
|
||||
result.add(createKeywordElement(breakOrContinue))
|
||||
}
|
||||
|
||||
val label = (parent.getParent() as? JetLabeledExpression)?.getLabelNameAsName()
|
||||
val label = (parent.getParent() as? KtLabeledExpression)?.getLabelNameAsName()
|
||||
if (label != null) {
|
||||
result.add(createKeywordElement(breakOrContinue, tail = label.labelNameToTail()))
|
||||
}
|
||||
}
|
||||
|
||||
is JetDeclarationWithBody -> break@parentsLoop //TODO: support non-local break's&continue's when they are supported by compiler
|
||||
is KtDeclarationWithBody -> break@parentsLoop //TODO: support non-local break's&continue's when they are supported by compiler
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun LookupElementFactory.createLookupElementForType(type: JetType): LookupElement? {
|
||||
fun LookupElementFactory.createLookupElementForType(type: KtType): LookupElement? {
|
||||
if (type.isError()) return null
|
||||
|
||||
if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
|
||||
val text = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type)
|
||||
val baseLookupElement = LookupElementBuilder.create(text).withIcon(JetIcons.LAMBDA)
|
||||
val baseLookupElement = LookupElementBuilder.create(text).withIcon(KtIcons.LAMBDA)
|
||||
return BaseTypeLookupElement(type, baseLookupElement)
|
||||
}
|
||||
else {
|
||||
@@ -339,7 +339,7 @@ fun LookupElementFactory.createLookupElementForType(type: JetType): LookupElemen
|
||||
}
|
||||
}
|
||||
|
||||
private open class BaseTypeLookupElement(type: JetType, baseLookupElement: LookupElement) : LookupElementDecorator<LookupElement>(baseLookupElement) {
|
||||
private open class BaseTypeLookupElement(type: KtType, baseLookupElement: LookupElement) : LookupElementDecorator<LookupElement>(baseLookupElement) {
|
||||
val fullText = IdeDescriptorRenderers.SOURCE_CODE.renderType(type)
|
||||
|
||||
override fun equals(other: Any?) = other is BaseTypeLookupElement && fullText == other.fullText
|
||||
@@ -358,7 +358,7 @@ private open class BaseTypeLookupElement(type: JetType, baseLookupElement: Looku
|
||||
|
||||
fun shortenReferences(context: InsertionContext, startOffset: Int, endOffset: Int) {
|
||||
PsiDocumentManager.getInstance(context.project).commitAllDocuments()
|
||||
ShortenReferences.DEFAULT.process(context.file as JetFile, startOffset, endOffset)
|
||||
ShortenReferences.DEFAULT.process(context.file as KtFile, startOffset, endOffset)
|
||||
}
|
||||
|
||||
fun <T> ElementPattern<T>.and(rhs: ElementPattern<T>) = StandardPatterns.and(this, rhs)
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
|
||||
@@ -28,7 +28,7 @@ fun renderDataFlowValue(value: DataFlowValue): String? {
|
||||
|
||||
fun renderId(id: Any?): String? {
|
||||
return when (id) {
|
||||
is JetExpression -> id.getText()
|
||||
is KtExpression -> id.getText()
|
||||
is ThisReceiver -> "this@${id.getDeclarationDescriptor().getName()}"
|
||||
is VariableDescriptor -> id.getName().asString()
|
||||
is PackageViewDescriptor -> id.fqName.asString()
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.ideService
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.containsError
|
||||
@@ -97,15 +97,15 @@ class ExpectedInfo(
|
||||
constructor(fuzzyType: FuzzyType, expectedName: String?, tail: Tail?, itemOptions: ItemOptions = ItemOptions.DEFAULT, additionalData: ExpectedInfo.AdditionalData? = null)
|
||||
: this(ByExpectedTypeFilter(fuzzyType), expectedName, tail, itemOptions, additionalData)
|
||||
|
||||
constructor(type: JetType, expectedName: String?, tail: Tail?, itemOptions: ItemOptions = ItemOptions.DEFAULT, additionalData: ExpectedInfo.AdditionalData? = null)
|
||||
constructor(type: KtType, expectedName: String?, tail: Tail?, itemOptions: ItemOptions = ItemOptions.DEFAULT, additionalData: ExpectedInfo.AdditionalData? = null)
|
||||
: this(FuzzyType(type, emptyList()), expectedName, tail, itemOptions, additionalData)
|
||||
|
||||
fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? = filter.matchingSubstitutor(descriptorType)
|
||||
|
||||
fun matchingSubstitutor(descriptorType: JetType): TypeSubstitutor? = matchingSubstitutor(FuzzyType(descriptorType, emptyList()))
|
||||
fun matchingSubstitutor(descriptorType: KtType): TypeSubstitutor? = matchingSubstitutor(FuzzyType(descriptorType, emptyList()))
|
||||
|
||||
companion object {
|
||||
fun createForArgument(type: JetType, expectedName: String?, tail: Tail?, argumentData: ArgumentPositionData, itemOptions: ItemOptions = ItemOptions.DEFAULT): ExpectedInfo {
|
||||
fun createForArgument(type: KtType, expectedName: String?, tail: Tail?, argumentData: ArgumentPositionData, itemOptions: ItemOptions = ItemOptions.DEFAULT): ExpectedInfo {
|
||||
return ExpectedInfo(FuzzyType(type, argumentData.function.typeParameters), expectedName, tail, itemOptions, argumentData)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class ExpectedInfo(
|
||||
return ExpectedInfo(ByTypeFilter.None, null, null/*TODO?*/, ItemOptions.DEFAULT, argumentData)
|
||||
}
|
||||
|
||||
fun createForReturnValue(type: JetType?, callable: CallableDescriptor): ExpectedInfo {
|
||||
fun createForReturnValue(type: KtType?, callable: CallableDescriptor): ExpectedInfo {
|
||||
val filter = if (type != null) ByExpectedTypeFilter(FuzzyType(type, emptyList())) else ByTypeFilter.All
|
||||
return ExpectedInfo(filter, callable.name.asString(), null, additionalData = ReturnValueAdditionalData(callable))
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class ExpectedInfos(
|
||||
val useHeuristicSignatures: Boolean = true,
|
||||
val useOuterCallsExpectedTypeCount: Int = 0
|
||||
) {
|
||||
public fun calculate(expressionWithType: JetExpression): Collection<ExpectedInfo> {
|
||||
public fun calculate(expressionWithType: KtExpression): Collection<ExpectedInfo> {
|
||||
val expectedInfos = calculateForArgument(expressionWithType)
|
||||
?: calculateForFunctionLiteralArgument(expressionWithType)
|
||||
?: calculateForIndexingArgument(expressionWithType)
|
||||
@@ -167,31 +167,31 @@ class ExpectedInfos(
|
||||
return expectedInfos.filterNot { it.fuzzyType?.type?.isError ?: false }
|
||||
}
|
||||
|
||||
private fun calculateForArgument(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val argument = expressionWithType.getParent() as? JetValueArgument ?: return null
|
||||
val argumentList = argument.getParent() as? JetValueArgumentList ?: return null
|
||||
val callElement = argumentList.getParent() as? JetCallElement ?: return null
|
||||
private fun calculateForArgument(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val argument = expressionWithType.getParent() as? KtValueArgument ?: return null
|
||||
val argumentList = argument.getParent() as? KtValueArgumentList ?: return null
|
||||
val callElement = argumentList.getParent() as? KtCallElement ?: return null
|
||||
return calculateForArgument(callElement, argument)
|
||||
}
|
||||
|
||||
private fun calculateForFunctionLiteralArgument(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val functionLiteralArgument = expressionWithType.getParent() as? JetFunctionLiteralArgument
|
||||
val callExpression = functionLiteralArgument?.getParent() as? JetCallExpression ?: return null
|
||||
private fun calculateForFunctionLiteralArgument(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val functionLiteralArgument = expressionWithType.getParent() as? KtFunctionLiteralArgument
|
||||
val callExpression = functionLiteralArgument?.getParent() as? KtCallExpression ?: return null
|
||||
val literalArgument = callExpression.getFunctionLiteralArguments().firstOrNull() ?: return null
|
||||
if (literalArgument.getArgumentExpression() != expressionWithType) return null
|
||||
return calculateForArgument(callExpression, literalArgument)
|
||||
}
|
||||
|
||||
private fun calculateForIndexingArgument(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val containerNode = expressionWithType.parent as? JetContainerNode ?: return null
|
||||
val arrayAccessExpression = containerNode.parent as? JetArrayAccessExpression ?: return null
|
||||
private fun calculateForIndexingArgument(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val containerNode = expressionWithType.parent as? KtContainerNode ?: return null
|
||||
val arrayAccessExpression = containerNode.parent as? KtArrayAccessExpression ?: return null
|
||||
if (containerNode != arrayAccessExpression.indicesNode) return null
|
||||
val call = arrayAccessExpression.getCall(bindingContext) ?: return null
|
||||
val argument = call.valueArguments.firstOrNull { it.getArgumentExpression() == expressionWithType } ?: return null
|
||||
return calculateForArgument(call, argument)
|
||||
}
|
||||
|
||||
private fun calculateForArgument(callElement: JetCallElement, argument: ValueArgument): Collection<ExpectedInfo>? {
|
||||
private fun calculateForArgument(callElement: KtCallElement, argument: ValueArgument): Collection<ExpectedInfo>? {
|
||||
val call = callElement.getCall(bindingContext) ?: return null
|
||||
return calculateForArgument(call, argument)
|
||||
}
|
||||
@@ -207,7 +207,7 @@ class ExpectedInfos(
|
||||
}
|
||||
|
||||
if (useOuterCallsExpectedTypeCount > 0 && results.any(::makesSenseToUseOuterCallExpectedType)) {
|
||||
val callExpression = (call.callElement as? JetExpression)?.getQualifiedExpressionForSelectorOrThis() ?: return results
|
||||
val callExpression = (call.callElement as? KtExpression)?.getQualifiedExpressionForSelectorOrThis() ?: return results
|
||||
val expectedFuzzyTypes = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures, useOuterCallsExpectedTypeCount - 1)
|
||||
.calculate(callExpression)
|
||||
.map { it.fuzzyType }
|
||||
@@ -223,7 +223,7 @@ class ExpectedInfos(
|
||||
return results
|
||||
}
|
||||
|
||||
private fun calculateForArgument(call: Call, callExpectedType: JetType, argument: ValueArgument): Collection<ExpectedInfo> {
|
||||
private fun calculateForArgument(call: Call, callExpectedType: KtType, argument: ValueArgument): Collection<ExpectedInfo> {
|
||||
val argumentIndex = call.getValueArguments().indexOf(argument)
|
||||
assert(argumentIndex >= 0) {
|
||||
"Could not find argument '$argument(${argument.asElement().text})' among arguments of call: $call"
|
||||
@@ -394,11 +394,11 @@ class ExpectedInfos(
|
||||
Tail.COMMA
|
||||
}
|
||||
|
||||
private fun calculateForEqAndAssignment(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.getParent() as? JetBinaryExpression
|
||||
private fun calculateForEqAndAssignment(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.getParent() as? KtBinaryExpression
|
||||
if (binaryExpression != null) {
|
||||
val operationToken = binaryExpression.getOperationToken()
|
||||
if (operationToken == JetTokens.EQ || operationToken in COMPARISON_TOKENS) {
|
||||
if (operationToken == KtTokens.EQ || operationToken in COMPARISON_TOKENS) {
|
||||
val otherOperand = if (expressionWithType == binaryExpression.getRight()) binaryExpression.getLeft() else binaryExpression.getRight()
|
||||
if (otherOperand != null) {
|
||||
var expectedType = bindingContext.getType(otherOperand) ?: return null
|
||||
@@ -415,8 +415,8 @@ class ExpectedInfos(
|
||||
return null
|
||||
}
|
||||
|
||||
private fun calculateForIf(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val ifExpression = (expressionWithType.getParent() as? JetContainerNode)?.getParent() as? JetIfExpression ?: return null
|
||||
private fun calculateForIf(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val ifExpression = (expressionWithType.getParent() as? KtContainerNode)?.getParent() as? KtIfExpression ?: return null
|
||||
return when (expressionWithType) {
|
||||
ifExpression.getCondition() -> listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH, additionalData = IfConditionAdditionalData))
|
||||
|
||||
@@ -436,11 +436,11 @@ class ExpectedInfos(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateForElvis(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.getParent() as? JetBinaryExpression
|
||||
private fun calculateForElvis(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.getParent() as? KtBinaryExpression
|
||||
if (binaryExpression != null) {
|
||||
val operationToken = binaryExpression.getOperationToken()
|
||||
if (operationToken == JetTokens.ELVIS && expressionWithType == binaryExpression.getRight()) {
|
||||
if (operationToken == KtTokens.ELVIS && expressionWithType == binaryExpression.getRight()) {
|
||||
val leftExpression = binaryExpression.getLeft() ?: return null
|
||||
val leftType = bindingContext.getType(leftExpression)
|
||||
val leftTypeNotNullable = leftType?.makeNotNullable()
|
||||
@@ -460,13 +460,13 @@ class ExpectedInfos(
|
||||
return null
|
||||
}
|
||||
|
||||
private fun calculateForBlockExpression(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val block = expressionWithType.parent as? JetBlockExpression ?: return null
|
||||
private fun calculateForBlockExpression(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val block = expressionWithType.parent as? KtBlockExpression ?: return null
|
||||
if (expressionWithType != block.statements.last()) return null
|
||||
|
||||
val functionLiteral = block.parent as? JetFunctionLiteral
|
||||
val functionLiteral = block.parent as? KtFunctionLiteral
|
||||
if (functionLiteral != null) {
|
||||
val literalExpression = functionLiteral.parent as JetFunctionLiteralExpression
|
||||
val literalExpression = functionLiteral.parent as KtFunctionLiteralExpression
|
||||
return calculate(literalExpression)
|
||||
.map { it.fuzzyType }
|
||||
.filterNotNull()
|
||||
@@ -481,10 +481,10 @@ class ExpectedInfos(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateForWhenEntryValue(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val condition = expressionWithType.getParent() as? JetWhenConditionWithExpression ?: return null
|
||||
val entry = condition.getParent() as JetWhenEntry
|
||||
val whenExpression = entry.getParent() as JetWhenExpression
|
||||
private fun calculateForWhenEntryValue(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val condition = expressionWithType.getParent() as? KtWhenConditionWithExpression ?: return null
|
||||
val entry = condition.getParent() as KtWhenEntry
|
||||
val whenExpression = entry.getParent() as KtWhenExpression
|
||||
val subject = whenExpression.getSubjectExpression()
|
||||
if (subject != null) {
|
||||
val subjectType = bindingContext.getType(subject) ?: return null
|
||||
@@ -495,14 +495,14 @@ class ExpectedInfos(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateForExclOperand(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val prefixExpression = expressionWithType.getParent() as? JetPrefixExpression ?: return null
|
||||
if (prefixExpression.getOperationToken() != JetTokens.EXCL) return null
|
||||
private fun calculateForExclOperand(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val prefixExpression = expressionWithType.getParent() as? KtPrefixExpression ?: return null
|
||||
if (prefixExpression.getOperationToken() != KtTokens.EXCL) return null
|
||||
return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, null))
|
||||
}
|
||||
|
||||
private fun calculateForInitializer(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val property = expressionWithType.getParent() as? JetProperty ?: return null
|
||||
private fun calculateForInitializer(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val property = expressionWithType.getParent() as? KtProperty ?: return null
|
||||
if (expressionWithType != property.getInitializer()) return null
|
||||
val propertyDescriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? VariableDescriptor ?: return null
|
||||
val expectedName = propertyDescriptor.name.asString()
|
||||
@@ -513,15 +513,15 @@ class ExpectedInfos(
|
||||
return listOf(expectedInfo)
|
||||
}
|
||||
|
||||
private fun calculateForExpressionBody(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val declaration = expressionWithType.getParent() as? JetDeclarationWithBody ?: return null
|
||||
private fun calculateForExpressionBody(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val declaration = expressionWithType.getParent() as? KtDeclarationWithBody ?: return null
|
||||
if (expressionWithType != declaration.getBodyExpression() || declaration.hasBlockBody()) return null
|
||||
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] as? FunctionDescriptor ?: return null
|
||||
return functionReturnValueExpectedInfo(descriptor, expectType = declaration.hasDeclaredReturnType()).singletonOrEmptyList()
|
||||
}
|
||||
|
||||
private fun calculateForReturn(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val returnExpression = expressionWithType.getParent() as? JetReturnExpression ?: return null
|
||||
private fun calculateForReturn(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val returnExpression = expressionWithType.getParent() as? KtReturnExpression ?: return null
|
||||
val descriptor = returnExpression.getTargetFunctionDescriptor(bindingContext) ?: return null
|
||||
return functionReturnValueExpectedInfo(descriptor, expectType = true).singletonOrEmptyList()
|
||||
}
|
||||
@@ -544,9 +544,9 @@ class ExpectedInfos(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateForLoopRange(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val forExpression = (expressionWithType.parent as? JetContainerNode)
|
||||
?.parent as? JetForExpression ?: return null
|
||||
private fun calculateForLoopRange(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val forExpression = (expressionWithType.parent as? KtContainerNode)
|
||||
?.parent as? KtForExpression ?: return null
|
||||
if (expressionWithType != forExpression.loopRange) return null
|
||||
|
||||
val loopVar = forExpression.loopParameter
|
||||
@@ -566,10 +566,10 @@ class ExpectedInfos(
|
||||
return listOf(ExpectedInfo(byTypeFilter, null, Tail.RPARENTH))
|
||||
}
|
||||
|
||||
private fun calculateForInOperatorArgument(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.parent as? JetBinaryExpression ?: return null
|
||||
private fun calculateForInOperatorArgument(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val binaryExpression = expressionWithType.parent as? KtBinaryExpression ?: return null
|
||||
val operationToken = binaryExpression.operationToken
|
||||
if (operationToken != JetTokens.IN_KEYWORD && operationToken != JetTokens.NOT_IN || expressionWithType != binaryExpression.right) return null
|
||||
if (operationToken != KtTokens.IN_KEYWORD && operationToken != KtTokens.NOT_IN || expressionWithType != binaryExpression.right) return null
|
||||
|
||||
val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null
|
||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!!
|
||||
@@ -583,17 +583,17 @@ class ExpectedInfos(
|
||||
return listOf(ExpectedInfo(byTypeFilter, null, null))
|
||||
}
|
||||
|
||||
private fun getFromBindingContext(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
|
||||
private fun getFromBindingContext(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType] ?: return null
|
||||
return listOf(ExpectedInfo(expectedType, null, null))
|
||||
}
|
||||
|
||||
private fun expectedNameFromExpression(expression: JetExpression?): String? {
|
||||
private fun expectedNameFromExpression(expression: KtExpression?): String? {
|
||||
return when (expression) {
|
||||
is JetSimpleNameExpression -> expression.getReferencedName()
|
||||
is JetQualifiedExpression -> expectedNameFromExpression(expression.getSelectorExpression())
|
||||
is JetCallExpression -> expectedNameFromExpression(expression.getCalleeExpression())
|
||||
is JetArrayAccessExpression -> expectedNameFromExpression(expression.getArrayExpression())?.unpluralize()
|
||||
is KtSimpleNameExpression -> expression.getReferencedName()
|
||||
is KtQualifiedExpression -> expectedNameFromExpression(expression.getSelectorExpression())
|
||||
is KtCallExpression -> expectedNameFromExpression(expression.getCalleeExpression())
|
||||
is KtArrayAccessExpression -> expectedNameFromExpression(expression.getArrayExpression())?.unpluralize()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -604,5 +604,5 @@ class ExpectedInfos(
|
||||
private fun Collection<ExpectedInfo>.copyWithNoAdditionalData() = map { it.copy(additionalData = null, itemOptions = ItemOptions.DEFAULT) }
|
||||
}
|
||||
|
||||
val COMPARISON_TOKENS = setOf(JetTokens.EQEQ, JetTokens.EXCLEQ, JetTokens.EQEQEQ, JetTokens.EXCLEQEQEQ)
|
||||
val COMPARISON_TOKENS = setOf(KtTokens.EQEQ, KtTokens.EXCLEQ, KtTokens.EQEQEQ, KtTokens.EXCLEQEQEQ)
|
||||
|
||||
|
||||
+6
-6
@@ -24,14 +24,14 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.SubstitutionUtils
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.util.*
|
||||
@@ -41,13 +41,13 @@ public class HeuristicSignatures(
|
||||
private val project: Project,
|
||||
private val typeResolver: TypeResolver
|
||||
) {
|
||||
public fun correctedParameterType(function: FunctionDescriptor, parameter: ValueParameterDescriptor): JetType? {
|
||||
public fun correctedParameterType(function: FunctionDescriptor, parameter: ValueParameterDescriptor): KtType? {
|
||||
val parameterIndex = function.getValueParameters().indexOf(parameter)
|
||||
assert(parameterIndex >= 0)
|
||||
return correctedParameterType(function, parameterIndex)
|
||||
}
|
||||
|
||||
private fun correctedParameterType(function: FunctionDescriptor, parameterIndex: Int): JetType? {
|
||||
private fun correctedParameterType(function: FunctionDescriptor, parameterIndex: Int): KtType? {
|
||||
val ownerType = function.getDispatchReceiverParameter()?.getType() ?: return null
|
||||
|
||||
val superFunctions = function.getOverriddenDescriptors()
|
||||
@@ -74,8 +74,8 @@ public class HeuristicSignatures(
|
||||
}
|
||||
}
|
||||
|
||||
private fun typeFromText(text: String, typeParameters: Collection<TypeParameterDescriptor>): JetType {
|
||||
val typeRef = JetPsiFactory(project).createType(text)
|
||||
private fun typeFromText(text: String, typeParameters: Collection<TypeParameterDescriptor>): KtType {
|
||||
val typeRef = KtPsiFactory(project).createType(text)
|
||||
val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsFileScope()
|
||||
val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, "Root packages + type parameters") {
|
||||
typeParameters.forEach { addClassifierDescriptor(it) }
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.*
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import java.util.*
|
||||
|
||||
class InsertHandlerProvider(
|
||||
@@ -85,7 +85,7 @@ class InsertHandlerProvider(
|
||||
|
||||
val potentiallyInferred = HashSet<TypeParameterDescriptor>()
|
||||
|
||||
fun addPotentiallyInferred(type: JetType) {
|
||||
fun addPotentiallyInferred(type: KtType) {
|
||||
val descriptor = type.constructor.declarationDescriptor as? TypeParameterDescriptor
|
||||
if (descriptor != null && descriptor in typeParameters) {
|
||||
potentiallyInferred.add(descriptor)
|
||||
|
||||
+35
-35
@@ -32,9 +32,9 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinKeywordInsertHandler
|
||||
import org.jetbrains.kotlin.lexer.JetKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens.*
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.ModifierCheckerCore
|
||||
@@ -46,14 +46,14 @@ object KeywordCompletion {
|
||||
TYPE_ALIAS_KEYWORD)
|
||||
private val ALL_KEYWORDS = (KEYWORDS.getTypes() + SOFT_KEYWORDS.getTypes())
|
||||
.filter { it !in NON_ACTUAL_KEYWORDS }
|
||||
.map { it as JetKeywordToken }
|
||||
.map { it as KtKeywordToken }
|
||||
|
||||
private val DEFAULT_DUMMY_POSTFIX = " X"
|
||||
private val KEYWORD_TO_DUMMY_POSTFIX = mapOf(FILE_KEYWORD to ":")
|
||||
|
||||
private val KEYWORDS_TO_IGNORE_PREFIX = TokenSet.create(OVERRIDE_KEYWORD /* it's needed to complete overrides that should be work by member name too */)
|
||||
|
||||
private val COMPOUND_KEYWORDS = mapOf<JetKeywordToken, JetKeywordToken>(
|
||||
private val COMPOUND_KEYWORDS = mapOf<KtKeywordToken, KtKeywordToken>(
|
||||
COMPANION_KEYWORD to OBJECT_KEYWORD,
|
||||
ENUM_KEYWORD to CLASS_KEYWORD,
|
||||
ANNOTATION_KEYWORD to CLASS_KEYWORD
|
||||
@@ -100,15 +100,15 @@ object KeywordCompletion {
|
||||
|
||||
private val GENERAL_FILTER = NotFilter(OrFilter(
|
||||
CommentFilter(),
|
||||
ParentFilter(ClassFilter(javaClass<JetLiteralStringTemplateEntry>())),
|
||||
ParentFilter(ClassFilter(javaClass<JetConstantExpression>())),
|
||||
ParentFilter(ClassFilter(javaClass<KtLiteralStringTemplateEntry>())),
|
||||
ParentFilter(ClassFilter(javaClass<KtConstantExpression>())),
|
||||
LeftNeighbour(TextFilter(".")),
|
||||
LeftNeighbour(TextFilter("?."))
|
||||
))
|
||||
|
||||
private class CommentFilter() : ElementFilter {
|
||||
override fun isAcceptable(element : Any?, context : PsiElement?)
|
||||
= (element is PsiElement) && JetPsiUtil.isInComment(element)
|
||||
= (element is PsiElement) && KtPsiUtil.isInComment(element)
|
||||
|
||||
override fun isClassAcceptable(hintClass: Class<out Any?>)
|
||||
= true
|
||||
@@ -125,23 +125,23 @@ object KeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildFilter(position: PsiElement): (JetKeywordToken) -> Boolean {
|
||||
private fun buildFilter(position: PsiElement): (KtKeywordToken) -> Boolean {
|
||||
var parent = position.getParent()
|
||||
var prevParent = position
|
||||
while (parent != null) {
|
||||
when (parent) {
|
||||
is JetBlockExpression -> {
|
||||
is KtBlockExpression -> {
|
||||
return buildFilterWithContext("fun foo() { ", prevParent, position)
|
||||
}
|
||||
|
||||
is JetWithExpressionInitializer -> {
|
||||
is KtWithExpressionInitializer -> {
|
||||
val initializer = parent.getInitializer()
|
||||
if (prevParent == initializer) {
|
||||
return buildFilterWithContext("val v = ", initializer!!, position)
|
||||
}
|
||||
}
|
||||
|
||||
is JetParameter -> {
|
||||
is KtParameter -> {
|
||||
val default = parent.getDefaultValue()
|
||||
if (prevParent == default) {
|
||||
return buildFilterWithContext("val v = ", default!!, position)
|
||||
@@ -149,11 +149,11 @@ object KeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
if (parent is JetDeclaration) {
|
||||
if (parent is KtDeclaration) {
|
||||
val scope = parent.parent
|
||||
when (scope) {
|
||||
is JetClassOrObject -> {
|
||||
if (parent is JetPrimaryConstructor) {
|
||||
is KtClassOrObject -> {
|
||||
if (parent is KtPrimaryConstructor) {
|
||||
return buildFilterWithReducedContext("class X ", parent, position)
|
||||
}
|
||||
else {
|
||||
@@ -161,7 +161,7 @@ object KeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
is JetFile -> return buildFilterWithReducedContext("", parent, position)
|
||||
is KtFile -> return buildFilterWithReducedContext("", parent, position)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ object KeywordCompletion {
|
||||
|
||||
private fun buildFilterWithContext(prefixText: String,
|
||||
contextElement: PsiElement,
|
||||
position: PsiElement): (JetKeywordToken) -> Boolean {
|
||||
position: PsiElement): (KtKeywordToken) -> Boolean {
|
||||
val offset = position.getStartOffsetInAncestor(contextElement)
|
||||
val truncatedContext = contextElement.getText()!!.substring(0, offset)
|
||||
return buildFilterByText(prefixText + truncatedContext, contextElement.getProject())
|
||||
@@ -182,15 +182,15 @@ object KeywordCompletion {
|
||||
|
||||
private fun buildFilterWithReducedContext(prefixText: String,
|
||||
contextElement: PsiElement?,
|
||||
position: PsiElement): (JetKeywordToken) -> Boolean {
|
||||
position: PsiElement): (KtKeywordToken) -> Boolean {
|
||||
val builder = StringBuilder()
|
||||
buildReducedContextBefore(builder, position, contextElement)
|
||||
return buildFilterByText(prefixText + builder.toString(), position.getProject())
|
||||
}
|
||||
|
||||
|
||||
private fun buildFilterByText(prefixText: String, project: Project): (JetKeywordToken) -> Boolean {
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
private fun buildFilterByText(prefixText: String, project: Project): (KtKeywordToken) -> Boolean {
|
||||
val psiFactory = KtPsiFactory(project)
|
||||
return fun (keywordTokenType): Boolean {
|
||||
val postfix = KEYWORD_TO_DUMMY_POSTFIX[keywordTokenType] ?: DEFAULT_DUMMY_POSTFIX
|
||||
val file = psiFactory.createFile(prefixText + keywordTokenType.getValue() + postfix)
|
||||
@@ -203,37 +203,37 @@ object KeywordCompletion {
|
||||
|
||||
elementAt.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment }?.parentsWithSelf?.any { it is PsiErrorElement } ?: false -> return false
|
||||
|
||||
keywordTokenType !is JetModifierKeywordToken -> return true
|
||||
keywordTokenType !is KtModifierKeywordToken -> return true
|
||||
|
||||
else -> {
|
||||
if (elementAt.parent !is JetModifierList) return true
|
||||
if (elementAt.parent !is KtModifierList) return true
|
||||
val container = elementAt.parent.parent
|
||||
val possibleTargets = when (container) {
|
||||
is JetParameter -> {
|
||||
if (container.ownerFunction is JetPrimaryConstructor)
|
||||
is KtParameter -> {
|
||||
if (container.ownerFunction is KtPrimaryConstructor)
|
||||
listOf(VALUE_PARAMETER, MEMBER_PROPERTY)
|
||||
else
|
||||
listOf(VALUE_PARAMETER)
|
||||
}
|
||||
|
||||
is JetTypeParameter -> listOf(TYPE_PARAMETER)
|
||||
is KtTypeParameter -> listOf(TYPE_PARAMETER)
|
||||
|
||||
is JetEnumEntry -> listOf(ENUM_ENTRY)
|
||||
is KtEnumEntry -> listOf(ENUM_ENTRY)
|
||||
|
||||
is JetClassBody -> listOf(CLASS_ONLY, INTERFACE, OBJECT, ENUM_CLASS, ANNOTATION_CLASS, INNER_CLASS, MEMBER_FUNCTION, MEMBER_PROPERTY, FUNCTION, PROPERTY)
|
||||
is KtClassBody -> listOf(CLASS_ONLY, INTERFACE, OBJECT, ENUM_CLASS, ANNOTATION_CLASS, INNER_CLASS, MEMBER_FUNCTION, MEMBER_PROPERTY, FUNCTION, PROPERTY)
|
||||
|
||||
is JetFile -> listOf(CLASS_ONLY, INTERFACE, OBJECT, ENUM_CLASS, ANNOTATION_CLASS, TOP_LEVEL_FUNCTION, TOP_LEVEL_PROPERTY, FUNCTION, PROPERTY)
|
||||
is KtFile -> listOf(CLASS_ONLY, INTERFACE, OBJECT, ENUM_CLASS, ANNOTATION_CLASS, TOP_LEVEL_FUNCTION, TOP_LEVEL_PROPERTY, FUNCTION, PROPERTY)
|
||||
|
||||
else -> null
|
||||
}
|
||||
val modifierTargets = ModifierCheckerCore.possibleTargetMap[keywordTokenType]
|
||||
if (modifierTargets != null && possibleTargets != null && possibleTargets.none { it in modifierTargets }) return false
|
||||
|
||||
val ownerDeclaration = container?.getParentOfType<JetDeclaration>(strict = true)
|
||||
val ownerDeclaration = container?.getParentOfType<KtDeclaration>(strict = true)
|
||||
val parentTarget = when (ownerDeclaration) {
|
||||
null -> KotlinTarget.FILE
|
||||
|
||||
is JetClass -> {
|
||||
is KtClass -> {
|
||||
when {
|
||||
ownerDeclaration.isInterface() -> KotlinTarget.INTERFACE
|
||||
ownerDeclaration.isEnum() -> KotlinTarget.ENUM_CLASS
|
||||
@@ -243,7 +243,7 @@ object KeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
is JetObjectDeclaration -> if (ownerDeclaration.isObjectLiteral()) KotlinTarget.OBJECT_LITERAL else KotlinTarget.OBJECT
|
||||
is KtObjectDeclaration -> if (ownerDeclaration.isObjectLiteral()) KotlinTarget.OBJECT_LITERAL else KotlinTarget.OBJECT
|
||||
|
||||
else -> return true
|
||||
}
|
||||
@@ -260,7 +260,7 @@ object KeywordCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
private fun IElementType.matchesKeyword(keywordType: JetKeywordToken): Boolean {
|
||||
private fun IElementType.matchesKeyword(keywordType: KtKeywordToken): Boolean {
|
||||
return when(this) {
|
||||
keywordType -> true
|
||||
NOT_IN -> keywordType == IN_KEYWORD
|
||||
@@ -276,11 +276,11 @@ object KeywordCompletion {
|
||||
|
||||
buildReducedContextBefore(builder, parent, scope)
|
||||
|
||||
val prevDeclaration = position.siblings(forward = false, withItself = false).firstOrNull { it is JetDeclaration }
|
||||
val prevDeclaration = position.siblings(forward = false, withItself = false).firstOrNull { it is KtDeclaration }
|
||||
|
||||
var child = parent.getFirstChild()
|
||||
while (child != position) {
|
||||
if (child is JetDeclaration) {
|
||||
if (child is KtDeclaration) {
|
||||
if (child == prevDeclaration) {
|
||||
builder.appendReducedText(child)
|
||||
}
|
||||
@@ -301,7 +301,7 @@ object KeywordCompletion {
|
||||
else {
|
||||
while (child != null) {
|
||||
when (child) {
|
||||
is JetBlockExpression, is JetClassBody -> append("{}")
|
||||
is KtBlockExpression, is KtClassBody -> append("{}")
|
||||
else -> appendReducedText(child)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.JetTypeImpl
|
||||
import org.jetbrains.kotlin.types.KtTypeImpl
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
|
||||
@@ -92,7 +92,7 @@ object KeywordValues {
|
||||
val qualifierType = bindingContext[BindingContext.TYPE, callTypeAndReceiver.receiver]
|
||||
if (qualifierType != null) {
|
||||
val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass
|
||||
val classLiteralType = JetTypeImpl.create(Annotations.EMPTY, kClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val classLiteralType = KtTypeImpl.create(Annotations.EMPTY, kClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val kClassTypes = listOf(FuzzyType(classLiteralType, emptyList()))
|
||||
val kClassMatcher = { info: ExpectedInfo -> kClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", kClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
@@ -104,7 +104,7 @@ object KeywordValues {
|
||||
.singleOrNull() as? ClassDescriptor
|
||||
|
||||
if (javaLangClassDescriptor != null) {
|
||||
val javaLangClassType = JetTypeImpl.create(Annotations.EMPTY, javaLangClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val javaLangClassType = KtTypeImpl.create(Annotations.EMPTY, javaLangClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val javaClassTypes = listOf(FuzzyType(javaLangClassType, emptyList()))
|
||||
val javaClassMatcher = { info: ExpectedInfo -> javaClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", javaClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
|
||||
+7
-7
@@ -25,9 +25,9 @@ import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteral
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
|
||||
|
||||
public class KotlinCompletionCharFilter() : CharFilter() {
|
||||
@@ -41,7 +41,7 @@ public class KotlinCompletionCharFilter() : CharFilter() {
|
||||
}
|
||||
|
||||
override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? {
|
||||
if (lookup.getPsiFile() !is JetFile) return null
|
||||
if (lookup.getPsiFile() !is KtFile) return null
|
||||
if (!lookup.isCompletion()) return null
|
||||
// it does not work in tests, so we use other way
|
||||
// val isAutopopup = CompletionService.getCompletionService().getCurrentCompletion().isAutopopupCompletion()
|
||||
@@ -97,11 +97,11 @@ public class KotlinCompletionCharFilter() : CharFilter() {
|
||||
|
||||
private fun isInFunctionLiteralStart(position: PsiElement): Boolean {
|
||||
var prev = position.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment }
|
||||
if (prev?.getNode()?.getElementType() == JetTokens.LPAR) {
|
||||
if (prev?.getNode()?.getElementType() == KtTokens.LPAR) {
|
||||
prev = prev?.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment }
|
||||
}
|
||||
if (prev?.getNode()?.getElementType() != JetTokens.LBRACE) return false
|
||||
val functionLiteral = prev!!.getParent() as? JetFunctionLiteral ?: return false
|
||||
if (prev?.getNode()?.getElementType() != KtTokens.LBRACE) return false
|
||||
val functionLiteral = prev!!.getParent() as? KtFunctionLiteral ?: return false
|
||||
return functionLiteral.getLBrace() == prev
|
||||
}
|
||||
}
|
||||
|
||||
+52
-52
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.performCompletionWithOutOfBlockTracking
|
||||
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion
|
||||
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionSession
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||
@@ -43,11 +43,11 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public var JetFile.doNotComplete: Boolean? by UserDataProperty(Key.create("DO_NOT_COMPLETE"))
|
||||
public var KtFile.doNotComplete: Boolean? by UserDataProperty(Key.create("DO_NOT_COMPLETE"))
|
||||
|
||||
public class KotlinCompletionContributor : CompletionContributor() {
|
||||
private val AFTER_NUMBER_LITERAL = psiElement().afterLeafSkipping(psiElement().withText(""), psiElement().withElementType(elementType().oneOf(JetTokens.FLOAT_LITERAL, JetTokens.INTEGER_LITERAL)))
|
||||
private val AFTER_INTEGER_LITERAL_AND_DOT = psiElement().afterLeafSkipping(psiElement().withText("."), psiElement().withElementType(elementType().oneOf(JetTokens.INTEGER_LITERAL)))
|
||||
private val AFTER_NUMBER_LITERAL = psiElement().afterLeafSkipping(psiElement().withText(""), psiElement().withElementType(elementType().oneOf(KtTokens.FLOAT_LITERAL, KtTokens.INTEGER_LITERAL)))
|
||||
private val AFTER_INTEGER_LITERAL_AND_DOT = psiElement().afterLeafSkipping(psiElement().withText("."), psiElement().withElementType(elementType().oneOf(KtTokens.INTEGER_LITERAL)))
|
||||
|
||||
companion object {
|
||||
public val DEFAULT_DUMMY_IDENTIFIER: String = CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "$" // add '$' to ignore context after the caret
|
||||
@@ -65,7 +65,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
override fun beforeCompletion(context: CompletionInitializationContext) {
|
||||
val psiFile = context.getFile()
|
||||
if (psiFile !is JetFile) return
|
||||
if (psiFile !is KtFile) return
|
||||
|
||||
val offset = context.getStartOffset()
|
||||
val tokenBefore = psiFile.findElementAt(Math.max(0, offset - 1))
|
||||
@@ -96,11 +96,11 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
val tokenAt = psiFile.findElementAt(Math.max(0, offset))
|
||||
if (tokenAt != null) {
|
||||
var parent = tokenAt.getParent()
|
||||
if (parent is JetExpression && parent !is JetBlockExpression) {
|
||||
if (parent is KtExpression && parent !is KtBlockExpression) {
|
||||
// search expression to be replaced - go up while we are the first child of parent expression
|
||||
var expression: JetExpression = parent
|
||||
var expression: KtExpression = parent
|
||||
parent = expression.getParent()
|
||||
while (parent is JetExpression && parent.getFirstChild() == expression) {
|
||||
while (parent is KtExpression && parent.getFirstChild() == expression) {
|
||||
expression = parent
|
||||
parent = expression.getParent()
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
context.getOffsetMap().addOffset(SmartCompletion.OLD_ARGUMENTS_REPLACEMENT_OFFSET, expression.endOffset)
|
||||
|
||||
val argumentList = (expression.getParent() as? JetValueArgument)?.getParent() as? JetValueArgumentList
|
||||
val argumentList = (expression.getParent() as? KtValueArgument)?.getParent() as? KtValueArgumentList
|
||||
if (argumentList != null) {
|
||||
context.getOffsetMap().addOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET,
|
||||
argumentList.getRightParenthesis()?.getTextRange()?.getStartOffset() ?: argumentList.endOffset)
|
||||
@@ -122,16 +122,16 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun replacementOffsetByExpression(expression: JetExpression): Int {
|
||||
private fun replacementOffsetByExpression(expression: KtExpression): Int {
|
||||
when (expression) {
|
||||
is JetCallExpression -> {
|
||||
is KtCallExpression -> {
|
||||
val calleeExpression = expression.getCalleeExpression()
|
||||
if (calleeExpression != null) {
|
||||
return calleeExpression.getTextRange()!!.getEndOffset()
|
||||
}
|
||||
}
|
||||
|
||||
is JetQualifiedExpression -> {
|
||||
is KtQualifiedExpression -> {
|
||||
val selector = expression.getSelectorExpression()
|
||||
if (selector != null) {
|
||||
return replacementOffsetByExpression(selector)
|
||||
@@ -142,7 +142,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
|
||||
private fun isInClassHeader(tokenBefore: PsiElement?): Boolean {
|
||||
val classOrObject = tokenBefore?.parents?.firstIsInstanceOrNull<JetClassOrObject>() ?: return false
|
||||
val classOrObject = tokenBefore?.parents?.firstIsInstanceOrNull<KtClassOrObject>() ?: return false
|
||||
val name = classOrObject.getNameIdentifier() ?: return false
|
||||
val body = classOrObject.getBody() ?: return false
|
||||
val offset = tokenBefore!!.startOffset
|
||||
@@ -155,12 +155,12 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
leaf = leaf.prevLeaf(true)
|
||||
}
|
||||
|
||||
val lambda = leaf?.parents?.firstOrNull { it is JetFunctionLiteral } ?: return null
|
||||
val lambda = leaf?.parents?.firstOrNull { it is KtFunctionLiteral } ?: return null
|
||||
|
||||
val lambdaChild = leaf!!.parents.takeWhile { it != lambda }.lastOrNull() ?: return null
|
||||
if (lambdaChild is JetParameterList) return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED
|
||||
if (lambdaChild is KtParameterList) return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED
|
||||
|
||||
if (lambdaChild !is JetBlockExpression) return null
|
||||
if (lambdaChild !is KtBlockExpression) return null
|
||||
val blockChild = leaf.parents.takeWhile { it != lambdaChild }.lastOrNull()
|
||||
if (blockChild !is PsiErrorElement) return null
|
||||
val inIncompleteSignature = blockChild.siblings(forward = false, withItself = false).all {
|
||||
@@ -173,13 +173,13 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
}
|
||||
|
||||
private val declarationKeywords = TokenSet.create(JetTokens.FUN_KEYWORD, JetTokens.VAL_KEYWORD, JetTokens.VAR_KEYWORD)
|
||||
private val declarationTokens = TokenSet.orSet(TokenSet.create(JetTokens.IDENTIFIER, JetTokens.LT, JetTokens.GT,
|
||||
JetTokens.COMMA, JetTokens.DOT, JetTokens.QUEST, JetTokens.COLON,
|
||||
JetTokens.IN_KEYWORD, JetTokens.OUT_KEYWORD,
|
||||
JetTokens.LPAR, JetTokens.RPAR, JetTokens.ARROW,
|
||||
private val declarationKeywords = TokenSet.create(KtTokens.FUN_KEYWORD, KtTokens.VAL_KEYWORD, KtTokens.VAR_KEYWORD)
|
||||
private val declarationTokens = TokenSet.orSet(TokenSet.create(KtTokens.IDENTIFIER, KtTokens.LT, KtTokens.GT,
|
||||
KtTokens.COMMA, KtTokens.DOT, KtTokens.QUEST, KtTokens.COLON,
|
||||
KtTokens.IN_KEYWORD, KtTokens.OUT_KEYWORD,
|
||||
KtTokens.LPAR, KtTokens.RPAR, KtTokens.ARROW,
|
||||
TokenType.ERROR_ELEMENT),
|
||||
JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
|
||||
private fun specialExtensionReceiverDummyIdentifier(tokenBefore: PsiElement?): String? {
|
||||
var token = tokenBefore ?: return null
|
||||
@@ -195,21 +195,21 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
builder.reverse()
|
||||
|
||||
var tail = "X" + ">".repeat(balance) + ".f"
|
||||
if (tokenType == JetTokens.FUN_KEYWORD) {
|
||||
if (tokenType == KtTokens.FUN_KEYWORD) {
|
||||
tail += "()"
|
||||
}
|
||||
builder append tail
|
||||
|
||||
val text = builder.toString()
|
||||
val file = JetPsiFactory(tokenBefore.getProject()).createFile(text)
|
||||
val file = KtPsiFactory(tokenBefore.getProject()).createFile(text)
|
||||
val declaration = file.getDeclarations().singleOrNull() ?: return null
|
||||
if (declaration.getTextLength() != text.length()) return null
|
||||
val containsErrorElement = !PsiTreeUtil.processElements(file, PsiElementProcessor<PsiElement>{ it !is PsiErrorElement })
|
||||
return if (containsErrorElement) null else tail + "$"
|
||||
}
|
||||
if (tokenType !in declarationTokens) return null
|
||||
if (tokenType == JetTokens.LT) ltCount++
|
||||
if (tokenType == JetTokens.GT) gtCount++
|
||||
if (tokenType == KtTokens.LT) ltCount++
|
||||
if (tokenType == KtTokens.GT) gtCount++
|
||||
builder.append(token.getText()!!.reversed())
|
||||
token = PsiTreeUtil.prevLeaf(token) ?: return null
|
||||
}
|
||||
@@ -218,8 +218,8 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
private fun performCompletion(parameters: CompletionParameters, result: CompletionResultSet) {
|
||||
val position = parameters.getPosition()
|
||||
val positionFile = position.containingFile
|
||||
if (positionFile !is JetFile) return
|
||||
if ((positionFile.originalFile as JetFile).doNotComplete ?: false) return
|
||||
if (positionFile !is KtFile) return
|
||||
if ((positionFile.originalFile as KtFile).doNotComplete ?: false) return
|
||||
|
||||
performCompletionWithOutOfBlockTracking(position) {
|
||||
doComplete(parameters, position, result)
|
||||
@@ -291,7 +291,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
val callable = isInExtensionReceiverOf(position)
|
||||
if (callable != null) {
|
||||
return when (callable) {
|
||||
is JetNamedFunction -> prefixMatcher.prefix.let { it.isEmpty() || it[0].isLowerCase() /* function name usually starts with lower case letter */ }
|
||||
is KtNamedFunction -> prefixMatcher.prefix.let { it.isEmpty() || it[0].isLowerCase() /* function name usually starts with lower case letter */ }
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -300,15 +300,15 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun isInExtensionReceiverOf(position: PsiElement): JetCallableDeclaration? {
|
||||
val nameRef = position.getParent() as? JetNameReferenceExpression ?: return null
|
||||
val userType = nameRef.getParent() as? JetUserType ?: return null
|
||||
val typeRef = userType.getParent() as? JetTypeReference ?: return null
|
||||
private fun isInExtensionReceiverOf(position: PsiElement): KtCallableDeclaration? {
|
||||
val nameRef = position.getParent() as? KtNameReferenceExpression ?: return null
|
||||
val userType = nameRef.getParent() as? KtUserType ?: return null
|
||||
val typeRef = userType.getParent() as? KtTypeReference ?: return null
|
||||
if (userType != typeRef.typeElement) return null
|
||||
val parent = typeRef.getParent()
|
||||
return when (parent) {
|
||||
is JetNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
|
||||
is JetProperty -> parent.check { typeRef == it.receiverTypeReference }
|
||||
is KtNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
|
||||
is KtProperty -> parent.check { typeRef == it.receiverTypeReference }
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
private fun specialInTypeArgsDummyIdentifier(tokenBefore: PsiElement?): String? {
|
||||
if (tokenBefore == null) return null
|
||||
|
||||
if (tokenBefore.getParentOfType<JetTypeArgumentList>(true) != null) { // already parsed inside type argument list
|
||||
if (tokenBefore.getParentOfType<KtTypeArgumentList>(true) != null) { // already parsed inside type argument list
|
||||
return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED // do not insert '$' to not break type argument list parsing
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
val (nameToken, balance) = pair
|
||||
assert(balance > 0)
|
||||
|
||||
val nameRef = nameToken.getParent() as? JetNameReferenceExpression ?: return null
|
||||
val nameRef = nameToken.getParent() as? KtNameReferenceExpression ?: return null
|
||||
val bindingContext = nameRef.getResolutionFacade().analyze(nameRef, BodyResolveMode.PARTIAL)
|
||||
val targets = nameRef.getReferenceTargets(bindingContext)
|
||||
if (targets.isNotEmpty() && targets.all { it is FunctionDescriptor || it is ClassDescriptor && it.getKind() == ClassKind.CLASS }) {
|
||||
@@ -358,10 +358,10 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
}
|
||||
|
||||
private val callTypeArgsTokens = TokenSet.orSet(TokenSet.create(JetTokens.IDENTIFIER, JetTokens.LT, JetTokens.GT,
|
||||
JetTokens.COMMA, JetTokens.DOT, JetTokens.QUEST, JetTokens.COLON,
|
||||
JetTokens.LPAR, JetTokens.RPAR, JetTokens.ARROW),
|
||||
JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
private val callTypeArgsTokens = TokenSet.orSet(TokenSet.create(KtTokens.IDENTIFIER, KtTokens.LT, KtTokens.GT,
|
||||
KtTokens.COMMA, KtTokens.DOT, KtTokens.QUEST, KtTokens.COLON,
|
||||
KtTokens.LPAR, KtTokens.RPAR, KtTokens.ARROW),
|
||||
KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
|
||||
// if the leaf could be located inside type argument list of a call (if parsed properly)
|
||||
// then it returns the call name reference this type argument list would belong to
|
||||
@@ -371,13 +371,13 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
val tokenType = current.getNode()!!.getElementType()
|
||||
if (tokenType !in callTypeArgsTokens) return null
|
||||
|
||||
if (tokenType == JetTokens.LT) {
|
||||
if (tokenType == KtTokens.LT) {
|
||||
val nameToken = current.prevLeaf(skipEmptyElements = true) ?: return null
|
||||
if (nameToken.getNode()!!.getElementType() != JetTokens.IDENTIFIER) return null
|
||||
if (nameToken.getNode()!!.getElementType() != KtTokens.IDENTIFIER) return null
|
||||
return nameToken
|
||||
}
|
||||
|
||||
if (tokenType == JetTokens.GT) { // pass nested type argument list
|
||||
if (tokenType == KtTokens.GT) { // pass nested type argument list
|
||||
val prev = current.prevLeaf(skipEmptyElements = true) ?: return null
|
||||
val typeRef = findCallNameTokenIfInTypeArgs(prev) ?: return null
|
||||
current = typeRef
|
||||
@@ -392,8 +392,8 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
// If we insert $ in the argument list of a delegation specifier, this will break parsing
|
||||
// and the following block will not be attached as a body to the constructor. Therefore
|
||||
// we need to use a regular identifier.
|
||||
val argumentList = tokenBefore?.getNonStrictParentOfType<JetValueArgumentList>() ?: return null
|
||||
if (argumentList.getParent() is JetConstructorDelegationCall) return CompletionUtil.DUMMY_IDENTIFIER_TRIMMED
|
||||
val argumentList = tokenBefore?.getNonStrictParentOfType<KtValueArgumentList>() ?: return null
|
||||
if (argumentList.getParent() is KtConstructorDelegationCall) return CompletionUtil.DUMMY_IDENTIFIER_TRIMMED
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -403,8 +403,8 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
var balance = 0
|
||||
while (current != stopAt) {
|
||||
when (current!!.getNode().getElementType()) {
|
||||
JetTokens.LPAR -> balance++
|
||||
JetTokens.RPAR -> balance--
|
||||
KtTokens.LPAR -> balance++
|
||||
KtTokens.RPAR -> balance--
|
||||
}
|
||||
current = current.prevLeaf()
|
||||
}
|
||||
@@ -413,15 +413,15 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
private fun isInUnclosedSuperQualifier(tokenBefore: PsiElement?): Boolean {
|
||||
if (tokenBefore == null) return false
|
||||
val tokensToSkip = TokenSet.orSet(TokenSet.create(JetTokens.IDENTIFIER, JetTokens.DOT ), JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
val tokensToSkip = TokenSet.orSet(TokenSet.create(KtTokens.IDENTIFIER, KtTokens.DOT ), KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
val tokens = sequence(tokenBefore) { it.prevLeaf() }
|
||||
val ltToken = tokens.firstOrNull { it.node.elementType !in tokensToSkip } ?: return false
|
||||
if (ltToken.node.elementType != JetTokens.LT) return false
|
||||
if (ltToken.node.elementType != KtTokens.LT) return false
|
||||
val superToken = ltToken.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment }
|
||||
return superToken?.node?.elementType == JetTokens.SUPER_KEYWORD
|
||||
return superToken?.node?.elementType == KtTokens.SUPER_KEYWORD
|
||||
}
|
||||
|
||||
private fun isInSimpleStringTemplate(tokenBefore: PsiElement?): Boolean {
|
||||
return tokenBefore?.parents?.firstIsInstanceOrNull<JetStringTemplateExpression>()?.isPlain() ?: false
|
||||
return tokenBefore?.parents?.firstIsInstanceOrNull<KtStringTemplateExpression>()?.isPlain() ?: false
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -38,13 +38,13 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
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.typeUtil.isSubtypeOf
|
||||
|
||||
class LookupElementFactory(
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val receiverTypes: Collection<JetType>?,
|
||||
private val receiverTypes: Collection<KtType>?,
|
||||
private val callType: CallType<*>?,
|
||||
private val isInStringTemplateAfterDollar: Boolean,
|
||||
public val insertHandlerProvider: InsertHandlerProvider,
|
||||
@@ -104,7 +104,7 @@ class LookupElementFactory(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFunctionCallElementWithLambda(descriptor: FunctionDescriptor, parameterType: JetType, explicitLambdaParameters: Boolean, useReceiverTypes: Boolean): LookupElement {
|
||||
private fun createFunctionCallElementWithLambda(descriptor: FunctionDescriptor, parameterType: KtType, explicitLambdaParameters: Boolean, useReceiverTypes: Boolean): LookupElement {
|
||||
var lookupElement = createLookupElement(descriptor, useReceiverTypes)
|
||||
val inputTypeArguments = (insertHandlerProvider.insertHandler(descriptor) as KotlinFunctionInsertHandler.Normal).inputTypeArguments
|
||||
val lambdaInfo = GenerateLambdaInfo(parameterType, explicitLambdaParameters)
|
||||
|
||||
+10
-10
@@ -20,24 +20,24 @@ import com.intellij.codeInsight.completion.InsertHandler
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import org.jetbrains.kotlin.idea.JetIcons
|
||||
import org.jetbrains.kotlin.idea.KtIcons
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetCallElement
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.JetValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import java.util.*
|
||||
|
||||
object NamedArgumentCompletion {
|
||||
public fun isOnlyNamedArgumentExpected(nameExpression: JetSimpleNameExpression): Boolean {
|
||||
val thisArgument = nameExpression.parent as? JetValueArgument ?: return false
|
||||
public fun isOnlyNamedArgumentExpected(nameExpression: KtSimpleNameExpression): Boolean {
|
||||
val thisArgument = nameExpression.parent as? KtValueArgument ?: return false
|
||||
if (thisArgument.isNamed()) return false
|
||||
|
||||
val callElement = thisArgument.getStrictParentOfType<JetCallElement>() ?: return false
|
||||
val callElement = thisArgument.getStrictParentOfType<KtCallElement>() ?: return false
|
||||
|
||||
return callElement.valueArguments
|
||||
.takeWhile { it != thisArgument }
|
||||
@@ -45,7 +45,7 @@ object NamedArgumentCompletion {
|
||||
}
|
||||
|
||||
public fun complete(collector: LookupElementsCollector, expectedInfos: Collection<ExpectedInfo>) {
|
||||
val nameToParameterType = HashMap<Name, MutableSet<JetType>>()
|
||||
val nameToParameterType = HashMap<Name, MutableSet<KtType>>()
|
||||
for (expectedInfo in expectedInfos) {
|
||||
val argumentData = expectedInfo.additionalData as? ArgumentPositionData.Positional ?: continue
|
||||
for (parameter in argumentData.namedArgumentCandidates) {
|
||||
@@ -59,7 +59,7 @@ object NamedArgumentCompletion {
|
||||
val lookupElement = LookupElementBuilder.create(nameString)
|
||||
.withPresentableText("$nameString =")
|
||||
.withTailText(" $typeText")
|
||||
.withIcon(JetIcons.PARAMETER)
|
||||
.withIcon(KtIcons.PARAMETER)
|
||||
.withInsertHandler(NamedArgumentInsertHandler(name))
|
||||
.assignPriority(ItemPriority.NAMED_PARAMETER)
|
||||
collector.addElement(lookupElement)
|
||||
|
||||
+8
-8
@@ -38,10 +38,10 @@ import org.jetbrains.kotlin.idea.quickfix.moveCaret
|
||||
import org.jetbrains.kotlin.idea.quickfix.moveCaretIntoGeneratedElement
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
@@ -55,9 +55,9 @@ class OverridesCompletion(
|
||||
}
|
||||
|
||||
fun complete(position: PsiElement) {
|
||||
val isConstructorParameter = position.getNonStrictParentOfType<JetPrimaryConstructor>() != null
|
||||
val isConstructorParameter = position.getNonStrictParentOfType<KtPrimaryConstructor>() != null
|
||||
|
||||
val classOrObject = position.getNonStrictParentOfType<JetClassOrObject>() ?: return
|
||||
val classOrObject = position.getNonStrictParentOfType<KtClassOrObject>() ?: return
|
||||
|
||||
val members = OverrideMembersHandler().collectMembersToGenerate(classOrObject)
|
||||
|
||||
@@ -104,10 +104,10 @@ class OverridesCompletion(
|
||||
|
||||
PsiDocumentManager.getInstance(context.project).commitAllDocuments()
|
||||
|
||||
val dummyMember = context.file.findElementAt(context.startOffset)!!.getStrictParentOfType<JetNamedDeclaration>()!!
|
||||
val dummyMember = context.file.findElementAt(context.startOffset)!!.getStrictParentOfType<KtNamedDeclaration>()!!
|
||||
|
||||
// keep original modifiers
|
||||
val modifierList = JetPsiFactory(context.project).createModifierList(dummyMember.modifierList!!.text)
|
||||
val modifierList = KtPsiFactory(context.project).createModifierList(dummyMember.modifierList!!.text)
|
||||
|
||||
val prototype = memberObject.generateMember(context.project, isConstructorParameter)
|
||||
prototype.modifierList!!.replace(modifierList)
|
||||
|
||||
+6
-6
@@ -24,9 +24,9 @@ import com.intellij.patterns.PlatformPatterns
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetPackageDirective
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
|
||||
/**
|
||||
* Performs completion in package directive. Should suggest only packages and avoid showing fake package produced by
|
||||
@@ -34,15 +34,15 @@ import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
*/
|
||||
object PackageDirectiveCompletion {
|
||||
val DUMMY_IDENTIFIER = "___package___"
|
||||
val ACTIVATION_PATTERN = PlatformPatterns.psiElement().inside(javaClass<JetPackageDirective>())
|
||||
val ACTIVATION_PATTERN = PlatformPatterns.psiElement().inside(javaClass<KtPackageDirective>())
|
||||
|
||||
fun perform(parameters: CompletionParameters, result: CompletionResultSet): Boolean {
|
||||
val position = parameters.getPosition()
|
||||
if (!ACTIVATION_PATTERN.accepts(position)) return false
|
||||
|
||||
val file = position.getContainingFile() as JetFile
|
||||
val file = position.getContainingFile() as KtFile
|
||||
|
||||
val expression = file.findElementAt(parameters.getOffset())?.getParent() as? JetSimpleNameExpression ?: return false
|
||||
val expression = file.findElementAt(parameters.getOffset())?.getParent() as? KtSimpleNameExpression ?: return false
|
||||
|
||||
try {
|
||||
val prefixLength = parameters.getOffset() - expression.getTextOffset()
|
||||
|
||||
+8
-8
@@ -36,14 +36,14 @@ import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import java.util.*
|
||||
|
||||
class ParameterNameAndTypeCompletion(
|
||||
@@ -101,8 +101,8 @@ class ParameterNameAndTypeCompletion(
|
||||
|
||||
public fun addFromParametersInFile(position: PsiElement, resolutionFacade: ResolutionFacade, visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
val lookupElementToCount = LinkedHashMap<LookupElement, Int>()
|
||||
position.getContainingFile().forEachDescendantOfType<JetParameter>(
|
||||
canGoInside = { it !is JetExpression || it is JetDeclaration } // we analyze parameters inside bodies to not resolve too much
|
||||
position.getContainingFile().forEachDescendantOfType<KtParameter>(
|
||||
canGoInside = { it !is KtExpression || it is KtDeclaration } // we analyze parameters inside bodies to not resolve too much
|
||||
) { parameter ->
|
||||
ProgressManager.checkCanceled()
|
||||
|
||||
@@ -152,7 +152,7 @@ class ParameterNameAndTypeCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetType.isVisible(visibilityFilter: (DeclarationDescriptor) -> Boolean): Boolean {
|
||||
private fun KtType.isVisible(visibilityFilter: (DeclarationDescriptor) -> Boolean): Boolean {
|
||||
if (isError()) return false
|
||||
val classifier = getConstructor().getDeclarationDescriptor() ?: return false
|
||||
return visibilityFilter(classifier) && getArguments().all { it.isStarProjection || it.getType().isVisible(visibilityFilter) }
|
||||
@@ -175,7 +175,7 @@ class ParameterNameAndTypeCompletion(
|
||||
= lookupElementFactory.createLookupElementForJavaClass(psiClass, qualifyNestedClasses = true)
|
||||
}
|
||||
|
||||
private class ArbitraryType(private val type: JetType) : Type(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)) {
|
||||
private class ArbitraryType(private val type: KtType) : Type(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)) {
|
||||
override fun createTypeLookupElement(lookupElementFactory: LookupElementFactory)
|
||||
= lookupElementFactory.createLookupElementForType(type)
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import com.intellij.codeInsight.completion.CompletionParameters
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.lang.properties.references.PropertiesCompletionContributor
|
||||
import com.intellij.lang.properties.references.PropertyReference
|
||||
import org.jetbrains.kotlin.psi.JetStringTemplateExpression
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isPlain
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
object PropertyKeyCompletion {
|
||||
fun perform(parameters: CompletionParameters, result: CompletionResultSet): Boolean {
|
||||
val template = parameters.position.getStrictParentOfType<JetStringTemplateExpression>() ?: return false
|
||||
val template = parameters.position.getStrictParentOfType<KtStringTemplateExpression>() ?: return false
|
||||
if (!template.isPlain()) return false
|
||||
|
||||
val references = template.references
|
||||
|
||||
+12
-12
@@ -22,8 +22,8 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstance
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
@@ -31,9 +31,9 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
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.isSubtypeOf
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import java.util.HashMap
|
||||
@@ -41,26 +41,26 @@ import java.util.HashMap
|
||||
class SmartCastCalculator(
|
||||
val bindingContext: BindingContext,
|
||||
val containingDeclarationOrModule: DeclarationDescriptor,
|
||||
expression: JetExpression
|
||||
expression: KtExpression
|
||||
) {
|
||||
private val receiver = if (expression is JetSimpleNameExpression) expression.getReceiverExpression() else null
|
||||
private val receiver = if (expression is KtSimpleNameExpression) expression.getReceiverExpression() else null
|
||||
|
||||
// keys are VariableDescriptor's and ThisReceiver's
|
||||
private val entityToSmartCastInfo: Map<Any, SmartCastInfo>
|
||||
= processDataFlowInfo(bindingContext.getDataFlowInfo(expression), bindingContext[BindingContext.RESOLUTION_SCOPE, expression], receiver)
|
||||
|
||||
fun types(descriptor: VariableDescriptor): Collection<JetType> {
|
||||
fun types(descriptor: VariableDescriptor): Collection<KtType> {
|
||||
val type = descriptor.returnType ?: return emptyList()
|
||||
return entityType(descriptor, type)
|
||||
}
|
||||
|
||||
fun types(thisReceiverParameter: ReceiverParameterDescriptor): Collection<JetType> {
|
||||
fun types(thisReceiverParameter: ReceiverParameterDescriptor): Collection<KtType> {
|
||||
val type = thisReceiverParameter.type
|
||||
val thisReceiver = thisReceiverParameter.value as? ThisReceiver ?: return listOf(type)
|
||||
return entityType(thisReceiver, type)
|
||||
}
|
||||
|
||||
private fun entityType(entity: Any, ownType: JetType): Collection<JetType> {
|
||||
private fun entityType(entity: Any, ownType: KtType): Collection<KtType> {
|
||||
val smartCastInfo = entityToSmartCastInfo[entity] ?: return listOf(ownType)
|
||||
|
||||
var types = smartCastInfo.types + ownType
|
||||
@@ -72,11 +72,11 @@ class SmartCastCalculator(
|
||||
return types
|
||||
}
|
||||
|
||||
private data class SmartCastInfo(var types: Collection<JetType>, var notNull: Boolean) {
|
||||
private data class SmartCastInfo(var types: Collection<KtType>, var notNull: Boolean) {
|
||||
constructor() : this(emptyList(), false)
|
||||
}
|
||||
|
||||
private fun processDataFlowInfo(dataFlowInfo: DataFlowInfo, resolutionScope: JetScope?, receiver: JetExpression?): Map<Any, SmartCastInfo> {
|
||||
private fun processDataFlowInfo(dataFlowInfo: DataFlowInfo, resolutionScope: KtScope?, receiver: KtExpression?): Map<Any, SmartCastInfo> {
|
||||
if (dataFlowInfo == DataFlowInfo.EMPTY) return emptyMap()
|
||||
|
||||
val dataFlowValueToEntity: (DataFlowValue) -> Any?
|
||||
@@ -126,7 +126,7 @@ class SmartCastCalculator(
|
||||
return entityToInfo
|
||||
}
|
||||
|
||||
private fun JetScope.findNearestReceiverForVariable(variableDescriptor: VariableDescriptor): ReceiverParameterDescriptor? {
|
||||
private fun KtScope.findNearestReceiverForVariable(variableDescriptor: VariableDescriptor): ReceiverParameterDescriptor? {
|
||||
val classifier = variableDescriptor.containingDeclaration as? ClassifierDescriptor ?: return null
|
||||
val type = classifier.defaultType
|
||||
return getImplicitReceiversWithInstance().firstOrNull { it.type.isSubtypeOf(type) }
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||
|
||||
@@ -52,7 +52,7 @@ class KotlinCompletionStatistician : CompletionStatistician() {
|
||||
|
||||
class KotlinProximityStatistician : ProximityStatistician() {
|
||||
override fun serialize(element: PsiElement, location: ProximityLocation): StatisticsInfo? {
|
||||
if (element !is JetDeclaration) return null
|
||||
if (element !is KtDeclaration) return null
|
||||
val descriptor = element.resolveToDescriptor()
|
||||
return KotlinStatisticsInfo.forDescriptor(descriptor)
|
||||
}
|
||||
|
||||
+8
-8
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
class ToFromOriginalFileMapper(
|
||||
val originalFile: JetFile,
|
||||
val syntheticFile: JetFile,
|
||||
val originalFile: KtFile,
|
||||
val syntheticFile: KtFile,
|
||||
val completionOffset: Int
|
||||
) {
|
||||
private val syntheticLength: Int
|
||||
@@ -63,15 +63,15 @@ class ToFromOriginalFileMapper(
|
||||
}
|
||||
}
|
||||
|
||||
public fun toOriginalFile(declaration: JetDeclaration): JetDeclaration? {
|
||||
public fun toOriginalFile(declaration: KtDeclaration): KtDeclaration? {
|
||||
if (declaration.getContainingFile() != syntheticFile) return declaration
|
||||
val offset = toOriginalFile(declaration.startOffset) ?: return null
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, javaClass<JetDeclaration>(), true)
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, javaClass<KtDeclaration>(), true)
|
||||
}
|
||||
|
||||
public fun toSyntheticFile(declaration: JetDeclaration): JetDeclaration? {
|
||||
public fun toSyntheticFile(declaration: KtDeclaration): KtDeclaration? {
|
||||
if (declaration.getContainingFile() != originalFile) return declaration
|
||||
val offset = toSyntheticFile(declaration.startOffset) ?: return null
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, javaClass<JetDeclaration>(), true)
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, javaClass<KtDeclaration>(), true)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -34,17 +34,17 @@ public class UnfocusedPossibleFunctionParameter extends CompletionConfidence {
|
||||
// 2. The same but for the case when first expression is additionally surrounded with brackets
|
||||
|
||||
PsiElement position = parameters.getPosition();
|
||||
JetFunctionLiteralExpression functionLiteral = PsiTreeUtil.getParentOfType(
|
||||
position, JetFunctionLiteralExpression.class);
|
||||
KtFunctionLiteralExpression functionLiteral = PsiTreeUtil.getParentOfType(
|
||||
position, KtFunctionLiteralExpression.class);
|
||||
|
||||
if (functionLiteral != null) {
|
||||
PsiElement expectedReference = position.getParent();
|
||||
if (expectedReference instanceof JetSimpleNameExpression) {
|
||||
if (PsiTreeUtil.findChildOfType(functionLiteral, JetParameterList.class) == null) {
|
||||
if (expectedReference instanceof KtSimpleNameExpression) {
|
||||
if (PsiTreeUtil.findChildOfType(functionLiteral, KtParameterList.class) == null) {
|
||||
{
|
||||
// 1.
|
||||
PsiElement expectedBlock = expectedReference.getParent();
|
||||
if (expectedBlock instanceof JetBlockExpression) {
|
||||
if (expectedBlock instanceof KtBlockExpression) {
|
||||
if (expectedReference.getPrevSibling() == null) {
|
||||
return ThreeState.NO;
|
||||
}
|
||||
@@ -54,9 +54,9 @@ public class UnfocusedPossibleFunctionParameter extends CompletionConfidence {
|
||||
{
|
||||
// 2.
|
||||
PsiElement expectedParenthesized = expectedReference.getParent();
|
||||
if (expectedParenthesized instanceof JetParenthesizedExpression) {
|
||||
if (expectedParenthesized instanceof KtParenthesizedExpression) {
|
||||
PsiElement expectedBlock = expectedParenthesized.getParent();
|
||||
if (expectedBlock instanceof JetBlockExpression) {
|
||||
if (expectedBlock instanceof KtBlockExpression) {
|
||||
if (expectedParenthesized.getPrevSibling() == null) {
|
||||
return ThreeState.NO;
|
||||
}
|
||||
|
||||
+6
-6
@@ -28,8 +28,8 @@ import org.jetbrains.kotlin.psi.*
|
||||
|
||||
object CastReceiverInsertHandler {
|
||||
fun postHandleInsert(context: InsertionContext, item: LookupElement) {
|
||||
val expression = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), javaClass<JetSimpleNameExpression>(), false)
|
||||
val qualifiedExpression = PsiTreeUtil.getParentOfType(expression, javaClass<JetQualifiedExpression>(), true)
|
||||
val expression = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), javaClass<KtSimpleNameExpression>(), false)
|
||||
val qualifiedExpression = PsiTreeUtil.getParentOfType(expression, javaClass<KtQualifiedExpression>(), true)
|
||||
if (qualifiedExpression != null) {
|
||||
val receiver = qualifiedExpression.getReceiverExpression()
|
||||
|
||||
@@ -39,17 +39,17 @@ object CastReceiverInsertHandler {
|
||||
val thisObj = if (descriptor.getExtensionReceiverParameter() != null) descriptor.getExtensionReceiverParameter() else descriptor.getDispatchReceiverParameter()
|
||||
val fqName = IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(thisObj!!.getType().getConstructor().getDeclarationDescriptor()!!)
|
||||
|
||||
val parentCast = JetPsiFactory(project).createExpression("(expr as $fqName)") as JetParenthesizedExpression
|
||||
val cast = parentCast.getExpression() as JetBinaryExpressionWithTypeRHS
|
||||
val parentCast = KtPsiFactory(project).createExpression("(expr as $fqName)") as KtParenthesizedExpression
|
||||
val cast = parentCast.getExpression() as KtBinaryExpressionWithTypeRHS
|
||||
cast.getLeft().replace(receiver)
|
||||
|
||||
val psiDocumentManager = PsiDocumentManager.getInstance(project)
|
||||
psiDocumentManager.commitAllDocuments()
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(context.getDocument())
|
||||
|
||||
val expr = receiver.replace(parentCast) as JetParenthesizedExpression
|
||||
val expr = receiver.replace(parentCast) as KtParenthesizedExpression
|
||||
|
||||
ShortenReferences.DEFAULT.process((expr.getExpression() as JetBinaryExpressionWithTypeRHS).getRight()!!)
|
||||
ShortenReferences.DEFAULT.process((expr.getExpression() as KtBinaryExpressionWithTypeRHS).getRight()!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -32,12 +32,12 @@ import org.jetbrains.kotlin.idea.completion.fuzzyType
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
fun insertLambdaTemplate(context: InsertionContext, placeholderRange: TextRange, lambdaType: JetType) {
|
||||
fun insertLambdaTemplate(context: InsertionContext, placeholderRange: TextRange, lambdaType: KtType) {
|
||||
val explicitParameterTypes = needExplicitParameterTypes(context, placeholderRange, lambdaType)
|
||||
|
||||
// we start template later to not interfere with insertion of tail type
|
||||
@@ -64,17 +64,17 @@ fun insertLambdaTemplate(context: InsertionContext, placeholderRange: TextRange,
|
||||
}
|
||||
}
|
||||
|
||||
fun lambdaPresentation(lambdaType: JetType?): String {
|
||||
fun lambdaPresentation(lambdaType: KtType?): String {
|
||||
if (lambdaType == null) return "{...}"
|
||||
val parameterTypes = functionParameterTypes(lambdaType)
|
||||
val parametersPresentation = parameterTypes.map { IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(it) }.joinToString(", ")
|
||||
return "{ $parametersPresentation -> ... }"
|
||||
}
|
||||
|
||||
private fun needExplicitParameterTypes(context: InsertionContext, placeholderRange: TextRange, lambdaType: JetType): Boolean {
|
||||
private fun needExplicitParameterTypes(context: InsertionContext, placeholderRange: TextRange, lambdaType: KtType): Boolean {
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments()
|
||||
val file = context.getFile() as JetFile
|
||||
val expression = PsiTreeUtil.findElementOfClassAtRange(file, placeholderRange.getStartOffset(), placeholderRange.getEndOffset(), javaClass<JetExpression>())
|
||||
val file = context.getFile() as KtFile
|
||||
val expression = PsiTreeUtil.findElementOfClassAtRange(file, placeholderRange.getStartOffset(), placeholderRange.getEndOffset(), javaClass<KtExpression>())
|
||||
?: return false
|
||||
|
||||
val resolutionFacade = file.getResolutionFacade()
|
||||
@@ -92,7 +92,7 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
|
||||
return functionTypes.filter { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size() == lambdaParameterCount }.size() > 1
|
||||
}
|
||||
|
||||
private fun buildTemplate(lambdaType: JetType, explicitParameterTypes: Boolean, project: Project): Template {
|
||||
private fun buildTemplate(lambdaType: KtType, explicitParameterTypes: Boolean, project: Project): Template {
|
||||
val parameterTypes = functionParameterTypes(lambdaType)
|
||||
|
||||
val manager = TemplateManager.getInstance(project)
|
||||
@@ -128,5 +128,5 @@ private class ParameterNameExpression(val nameSuggestions: Array<String>) : Expr
|
||||
= Array<LookupElement>(nameSuggestions.size(), { LookupElementBuilder.create(nameSuggestions[it]) })
|
||||
}
|
||||
|
||||
fun functionParameterTypes(functionType: JetType): List<JetType>
|
||||
fun functionParameterTypes(functionType: KtType): List<KtType>
|
||||
= KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(functionType).map { it.getType() }
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.idea.completion.isAfterDot
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
abstract class KotlinCallableInsertHandler : BaseDeclarationInsertHandler() {
|
||||
@@ -39,7 +39,7 @@ abstract class KotlinCallableInsertHandler : BaseDeclarationInsertHandler() {
|
||||
|
||||
val file = context.getFile()
|
||||
val o = item.getObject()
|
||||
if (file is JetFile && o is DeclarationLookupObject) {
|
||||
if (file is KtFile && o is DeclarationLookupObject) {
|
||||
val descriptor = o.descriptor as? CallableDescriptor
|
||||
if (descriptor != null) {
|
||||
// for completion after dot, import insertion may be required only for extensions
|
||||
|
||||
+4
-4
@@ -29,8 +29,8 @@ import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -40,7 +40,7 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() {
|
||||
super.handleInsert(context, item)
|
||||
|
||||
val file = context.getFile()
|
||||
if (file is JetFile) {
|
||||
if (file is KtFile) {
|
||||
if (!context.isAfterDot()) {
|
||||
val psiDocumentManager = PsiDocumentManager.getInstance(context.getProject())
|
||||
psiDocumentManager.commitAllDocuments()
|
||||
@@ -52,7 +52,7 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() {
|
||||
|
||||
// first try to resolve short name for faster handling
|
||||
val token = file.findElementAt(startOffset)
|
||||
val nameRef = token!!.getParent() as? JetNameReferenceExpression
|
||||
val nameRef = token!!.getParent() as? KtNameReferenceExpression
|
||||
if (nameRef != null) {
|
||||
val bindingContext = nameRef.getResolutionFacade().analyze(nameRef, BodyResolveMode.PARTIAL)
|
||||
val target = bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, nameRef]
|
||||
|
||||
+6
-6
@@ -26,12 +26,12 @@ import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetTypeArgumentList
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtTypeArgumentList
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
class GenerateLambdaInfo(val lambdaType: JetType, val explicitParameters: Boolean)
|
||||
class GenerateLambdaInfo(val lambdaType: KtType, val explicitParameters: Boolean)
|
||||
|
||||
sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() {
|
||||
|
||||
@@ -97,9 +97,9 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() {
|
||||
if (chars[offset1] == '<') {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document)
|
||||
val token = context.getFile().findElementAt(offset1)!!
|
||||
if (token.getNode().getElementType() == JetTokens.LT) {
|
||||
if (token.getNode().getElementType() == KtTokens.LT) {
|
||||
val parent = token.getParent()
|
||||
if (parent is JetTypeArgumentList && parent.getText().indexOf('\n') < 0/* if type argument list is on multiple lines this is more likely wrong parsing*/) {
|
||||
if (parent is KtTypeArgumentList && parent.getText().indexOf('\n') < 0/* if type argument list is on multiple lines this is more likely wrong parsing*/) {
|
||||
offset = parent.endOffset
|
||||
insertTypeArguments = false
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.completion.handlers
|
||||
import com.intellij.codeInsight.completion.InsertHandler
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import org.jetbrains.kotlin.lexer.JetTokens.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
|
||||
object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
private val NO_SPACE_AFTER = listOf(THIS_KEYWORD,
|
||||
|
||||
+8
-8
@@ -20,10 +20,10 @@ import com.intellij.codeInsight.completion.InsertHandler
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
class WithExpressionPrefixInsertHandler(val prefix: String) : InsertHandler<LookupElement> {
|
||||
@@ -40,14 +40,14 @@ class WithExpressionPrefixInsertHandler(val prefix: String) : InsertHandler<Look
|
||||
|
||||
val offset = context.getStartOffset()
|
||||
val token = context.getFile().findElementAt(offset)!!
|
||||
var expression = token.getStrictParentOfType<JetExpression>() ?: return
|
||||
if (expression is JetSimpleNameExpression) {
|
||||
var expression = token.getStrictParentOfType<KtExpression>() ?: return
|
||||
if (expression is KtSimpleNameExpression) {
|
||||
var parent = expression.getParent()
|
||||
if (parent is JetCallExpression && expression == parent.getCalleeExpression()) {
|
||||
if (parent is KtCallExpression && expression == parent.getCalleeExpression()) {
|
||||
expression = parent
|
||||
parent = parent.getParent()
|
||||
}
|
||||
if (parent is JetDotQualifiedExpression && expression == parent.getSelectorExpression()) {
|
||||
if (parent is KtDotQualifiedExpression && expression == parent.getSelectorExpression()) {
|
||||
expression = parent
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.idea.completion.createLookupElementForType
|
||||
import org.jetbrains.kotlin.idea.completion.fuzzyType
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.quickfix.moveCaret
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.util.*
|
||||
|
||||
@@ -39,7 +39,7 @@ object ClassLiteralItems {
|
||||
lookupElementFactory: LookupElementFactory,
|
||||
isJvmModule: Boolean
|
||||
) {
|
||||
val typeAndSuffixToExpectedInfos = LinkedHashMap<Pair<JetType, String>, MutableList<ExpectedInfo>>()
|
||||
val typeAndSuffixToExpectedInfos = LinkedHashMap<Pair<KtType, String>, MutableList<ExpectedInfo>>()
|
||||
|
||||
for (expectedInfo in expectedInfos) {
|
||||
val fuzzyType = expectedInfo.fuzzyType ?: continue
|
||||
|
||||
+6
-6
@@ -30,12 +30,12 @@ import org.jetbrains.kotlin.idea.completion.Tail
|
||||
import org.jetbrains.kotlin.idea.util.getVariableFromImplicitReceivers
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.psi.Call
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import java.util.*
|
||||
|
||||
class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
|
||||
@@ -43,7 +43,7 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
|
||||
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>,
|
||||
expectedInfos: Collection<ExpectedInfo>,
|
||||
context: JetExpression) {
|
||||
context: KtExpression) {
|
||||
val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return
|
||||
|
||||
val added = HashSet<String>()
|
||||
@@ -96,12 +96,12 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
|
||||
.assignSmartCompletionPriority(SmartCompletionItemPriority.MULTIPLE_ARGUMENTS_ITEM)
|
||||
}
|
||||
|
||||
private fun variableInScope(parameter: ValueParameterDescriptor, scope: JetScope): VariableDescriptor? {
|
||||
private fun variableInScope(parameter: ValueParameterDescriptor, scope: KtScope): VariableDescriptor? {
|
||||
val name = parameter.getName()
|
||||
//TODO: there can be more than one property with such name in scope and we should be able to select one (but we need API for this)
|
||||
val variable = scope.getLocalVariable(name) ?: scope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull() ?:
|
||||
scope.getVariableFromImplicitReceivers(name) ?: return null
|
||||
return if (smartCastCalculator.types(variable).any { JetTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) })
|
||||
return if (smartCastCalculator.types(variable).any { KotlinTypeChecker.DEFAULT.isSubtypeOf(it, parameter.getType()) })
|
||||
variable
|
||||
else
|
||||
null
|
||||
|
||||
+28
-28
@@ -30,11 +30,11 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.isAlmostEverything
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
@@ -48,7 +48,7 @@ interface InheritanceItemsSearcher {
|
||||
}
|
||||
|
||||
class SmartCompletion(
|
||||
private val expression: JetExpression,
|
||||
private val expression: KtExpression,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val bindingContext: BindingContext,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
@@ -69,7 +69,7 @@ class SmartCompletion(
|
||||
is CallTypeAndReceiver.SAFE,
|
||||
is CallTypeAndReceiver.INFIX,
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE ->
|
||||
expression.parent as JetExpression
|
||||
expression.parent as KtExpression
|
||||
|
||||
else -> // actually no smart completion for such places
|
||||
expression
|
||||
@@ -104,26 +104,26 @@ class SmartCompletion(
|
||||
public val descriptorsToSkip: Set<DeclarationDescriptor> by lazy<Set<DeclarationDescriptor>>(LazyThreadSafetyMode.NONE) {
|
||||
val parent = expressionWithType.getParent()
|
||||
when (parent) {
|
||||
is JetBinaryExpression -> {
|
||||
is KtBinaryExpression -> {
|
||||
if (parent.getRight() == expressionWithType) {
|
||||
val operationToken = parent.getOperationToken()
|
||||
if (operationToken == JetTokens.EQ || operationToken in COMPARISON_TOKENS) {
|
||||
if (operationToken == KtTokens.EQ || operationToken in COMPARISON_TOKENS) {
|
||||
val left = parent.getLeft()
|
||||
if (left is JetReferenceExpression) {
|
||||
if (left is KtReferenceExpression) {
|
||||
return@lazy bindingContext[BindingContext.REFERENCE_TARGET, left].singletonOrEmptySet()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is JetWhenConditionWithExpression -> {
|
||||
val entry = parent.getParent() as JetWhenEntry
|
||||
val whenExpression = entry.getParent() as JetWhenExpression
|
||||
is KtWhenConditionWithExpression -> {
|
||||
val entry = parent.getParent() as KtWhenEntry
|
||||
val whenExpression = entry.getParent() as KtWhenExpression
|
||||
val subject = whenExpression.getSubjectExpression() ?: return@lazy emptySet()
|
||||
|
||||
val descriptorsToSkip = HashSet<DeclarationDescriptor>()
|
||||
|
||||
if (subject is JetSimpleNameExpression) {
|
||||
if (subject is KtSimpleNameExpression) {
|
||||
val variable = bindingContext[BindingContext.REFERENCE_TARGET, subject] as? VariableDescriptor
|
||||
if (variable != null) {
|
||||
descriptorsToSkip.add(variable)
|
||||
@@ -135,10 +135,10 @@ class SmartCompletion(
|
||||
if (classDescriptor != null && DescriptorUtils.isEnumClass(classDescriptor)) {
|
||||
val conditions = whenExpression.getEntries()
|
||||
.flatMap { it.getConditions().toList() }
|
||||
.filterIsInstance<JetWhenConditionWithExpression>()
|
||||
.filterIsInstance<KtWhenConditionWithExpression>()
|
||||
for (condition in conditions) {
|
||||
val selectorExpr = (condition.getExpression() as? JetDotQualifiedExpression)
|
||||
?.getSelectorExpression() as? JetReferenceExpression ?: continue
|
||||
val selectorExpr = (condition.getExpression() as? KtDotQualifiedExpression)
|
||||
?.getSelectorExpression() as? KtReferenceExpression ?: continue
|
||||
val target = bindingContext[BindingContext.REFERENCE_TARGET, selectorExpr] as? ClassDescriptor ?: continue
|
||||
if (DescriptorUtils.isEnumEntry(target)) {
|
||||
descriptorsToSkip.add(target)
|
||||
@@ -203,7 +203,7 @@ class SmartCompletion(
|
||||
TypeInstantiationItems(resolutionFacade, bindingContext, visibilityFilter, toFromOriginalFileMapper, inheritorSearchScope, lookupElementFactory, forBasicCompletion)
|
||||
.addTo(items, inheritanceSearchers, expectedInfos)
|
||||
|
||||
if (expression is JetSimpleNameExpression) {
|
||||
if (expression is KtSimpleNameExpression) {
|
||||
StaticMembers(bindingContext, lookupElementFactory).addToCollection(items, expectedInfos, expression, descriptorsToSkip)
|
||||
}
|
||||
|
||||
@@ -212,10 +212,10 @@ class SmartCompletion(
|
||||
if (!forBasicCompletion) {
|
||||
LambdaItems.addToCollection(items, expectedInfos)
|
||||
|
||||
val whenCondition = expressionWithType.parent as? JetWhenConditionWithExpression
|
||||
val whenCondition = expressionWithType.parent as? KtWhenConditionWithExpression
|
||||
if (whenCondition != null) {
|
||||
val entry = whenCondition.parent as JetWhenEntry
|
||||
val whenExpression = entry.parent as JetWhenExpression
|
||||
val entry = whenCondition.parent as KtWhenEntry
|
||||
val whenExpression = entry.parent as KtWhenExpression
|
||||
val entries = whenExpression.entries
|
||||
if (whenExpression.elseExpression == null && entry == entries.last() && entries.size() != 1) {
|
||||
val lookupElement = LookupElementBuilder.create("else").bold().withTailText(" ->")
|
||||
@@ -266,7 +266,7 @@ class SmartCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
private fun MutableCollection<LookupElement>.addThisItems(place: JetExpression, expectedInfos: Collection<ExpectedInfo>, smartCastCalculator: SmartCastCalculator) {
|
||||
private fun MutableCollection<LookupElement>.addThisItems(place: KtExpression, expectedInfos: Collection<ExpectedInfo>, smartCastCalculator: SmartCastCalculator) {
|
||||
if (shouldCompleteThisItems(prefixMatcher)) {
|
||||
val items = thisExpressionItems(bindingContext, place, prefixMatcher.getPrefix(), resolutionFacade)
|
||||
for (item in items) {
|
||||
@@ -279,7 +279,7 @@ class SmartCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calcExpectedInfos(expression: JetExpression): Collection<ExpectedInfo> {
|
||||
private fun calcExpectedInfos(expression: KtExpression): Collection<ExpectedInfo> {
|
||||
// if our expression is initializer of implicitly typed variable - take type of variable from original file (+ the same for function)
|
||||
val declaration = implicitlyTypedDeclarationFromInitializer(expression)
|
||||
if (declaration != null) {
|
||||
@@ -309,11 +309,11 @@ class SmartCompletion(
|
||||
//TODO: we could always give higher priority to results with outer call expected type used
|
||||
}
|
||||
|
||||
private fun implicitlyTypedDeclarationFromInitializer(expression: JetExpression): JetDeclaration? {
|
||||
private fun implicitlyTypedDeclarationFromInitializer(expression: KtExpression): KtDeclaration? {
|
||||
val parent = expression.getParent()
|
||||
when (parent) {
|
||||
is JetVariableDeclaration -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
|
||||
is JetNamedFunction -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
|
||||
is KtVariableDeclaration -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
|
||||
is KtNamedFunction -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -366,15 +366,15 @@ class SmartCompletion(
|
||||
}
|
||||
|
||||
private fun buildForAsTypePosition(): Collection<LookupElement>? {
|
||||
val binaryExpression = ((expression.getParent() as? JetUserType)
|
||||
?.getParent() as? JetTypeReference)
|
||||
?.getParent() as? JetBinaryExpressionWithTypeRHS
|
||||
val binaryExpression = ((expression.getParent() as? KtUserType)
|
||||
?.getParent() as? KtTypeReference)
|
||||
?.getParent() as? KtBinaryExpressionWithTypeRHS
|
||||
?: return null
|
||||
val elementType = binaryExpression.getOperationReference().getReferencedNameElementType()
|
||||
if (elementType != JetTokens.AS_KEYWORD && elementType != JetTokens.AS_SAFE) return null
|
||||
if (elementType != KtTokens.AS_KEYWORD && elementType != KtTokens.AS_SAFE) return null
|
||||
val expectedInfos = calcExpectedInfos(binaryExpression)
|
||||
|
||||
val expectedInfosGrouped: Map<JetType?, List<ExpectedInfo>> = expectedInfos.groupBy { it.fuzzyType?.type?.makeNotNullable() }
|
||||
val expectedInfosGrouped: Map<KtType?, List<ExpectedInfo>> = expectedInfos.groupBy { it.fuzzyType?.type?.makeNotNullable() }
|
||||
|
||||
val items = ArrayList<LookupElement>()
|
||||
for ((type, infos) in expectedInfosGrouped) {
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.idea.completion.*
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude
|
||||
import org.jetbrains.kotlin.psi.FunctionLiteralArgument
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.ValueArgumentName
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||
@@ -77,7 +77,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
processNonImported { collector.addElements(filter(it), notImported = true) }
|
||||
flushToResultSet()
|
||||
|
||||
if (position.getContainingFile() is JetCodeFragment) {
|
||||
if (position.getContainingFile() is KtCodeFragment) {
|
||||
getRuntimeReceiverTypeReferenceVariants().forEach {
|
||||
collector.addElements(filter(it).map { it.withReceiverCast() })
|
||||
}
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.completion.shortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.isVisible
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -45,7 +45,7 @@ class StaticMembers(
|
||||
) {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>,
|
||||
expectedInfos: Collection<ExpectedInfo>,
|
||||
context: JetSimpleNameExpression,
|
||||
context: KtSimpleNameExpression,
|
||||
enumEntriesToSkip: Set<DeclarationDescriptor>) {
|
||||
|
||||
val expectedInfosByClass = expectedInfos.groupBy {
|
||||
@@ -62,7 +62,7 @@ class StaticMembers(
|
||||
collection: MutableCollection<LookupElement>,
|
||||
classDescriptor: ClassDescriptor,
|
||||
expectedInfos: Collection<ExpectedInfo>,
|
||||
context: JetSimpleNameExpression,
|
||||
context: KtSimpleNameExpression,
|
||||
enumEntriesToSkip: Set<DeclarationDescriptor>) {
|
||||
|
||||
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return
|
||||
|
||||
+7
-7
@@ -40,8 +40,8 @@ import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -104,14 +104,14 @@ class TypeInstantiationItems(
|
||||
descriptor: ClassDescriptor, kotlinClassDescriptor: ClassDescriptor, typeArgs: List<TypeProjection>, freeParameters: Collection<TypeParameterDescriptor>, tail: Tail?
|
||||
) {
|
||||
val _declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(resolutionFacade.project, descriptor) ?: return
|
||||
val declaration = if (_declaration is JetDeclaration)
|
||||
val declaration = if (_declaration is KtDeclaration)
|
||||
toFromOriginalFileMapper.toOriginalFile(_declaration) ?: return
|
||||
else
|
||||
_declaration
|
||||
|
||||
val psiClass: PsiClass = when (declaration) {
|
||||
is PsiClass -> declaration
|
||||
is JetClassOrObject -> LightClassUtil.getPsiClass(declaration) ?: return
|
||||
is KtClassOrObject -> LightClassUtil.getPsiClass(declaration) ?: return
|
||||
else -> return
|
||||
}
|
||||
add(InheritanceSearcher(psiClass, kotlinClassDescriptor, typeArgs, freeParameters, tail))
|
||||
@@ -266,7 +266,7 @@ class TypeInstantiationItems(
|
||||
return InstantiationLookupElement(lookupElement).addTail(tail)
|
||||
}
|
||||
|
||||
private fun JetType.areTypeParametersUsedInside(freeParameters: Collection<TypeParameterDescriptor>): Boolean {
|
||||
private fun KtType.areTypeParametersUsedInside(freeParameters: Collection<TypeParameterDescriptor>): Boolean {
|
||||
return FuzzyType(this, freeParameters).freeParameters.isNotEmpty()
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ class TypeInstantiationItems(
|
||||
private val tail: Tail?) : InheritanceItemsSearcher {
|
||||
|
||||
private val baseHasTypeArgs = classDescriptor.typeConstructor.parameters.isNotEmpty()
|
||||
private val expectedType = JetTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArgs)
|
||||
private val expectedType = KtTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArgs)
|
||||
private val expectedFuzzyType = FuzzyType(expectedType, freeParameters)
|
||||
|
||||
override fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit) {
|
||||
@@ -304,7 +304,7 @@ class TypeInstantiationItems(
|
||||
for (inheritor in ClassInheritorsSearch.search(parameters)) {
|
||||
val descriptor = resolutionFacade.psiClassToDescriptor(
|
||||
inheritor,
|
||||
{ toFromOriginalFileMapper.toSyntheticFile(it) as JetClassOrObject? }) as? ClassDescriptor ?: continue
|
||||
{ toFromOriginalFileMapper.toSyntheticFile(it) as KtClassOrObject? }) as? ClassDescriptor ?: continue
|
||||
if (!visibilityFilter(descriptor)) continue
|
||||
|
||||
var inheritorFuzzyType = FuzzyType(descriptor.defaultType, descriptor.typeConstructor.parameters)
|
||||
|
||||
+5
-5
@@ -25,15 +25,15 @@ import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.nullability
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import java.util.*
|
||||
|
||||
class TypesWithContainsDetector(
|
||||
private val scope: JetScope,
|
||||
private val argumentType: JetType,
|
||||
private val scope: KtScope,
|
||||
private val argumentType: KtType,
|
||||
private val resolutionFacade: ResolutionFacade
|
||||
) {
|
||||
private val cache = HashMap<FuzzyType, Boolean>()
|
||||
@@ -41,7 +41,7 @@ class TypesWithContainsDetector(
|
||||
private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType
|
||||
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
|
||||
|
||||
private val typesWithExtensionContains: Collection<JetType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
|
||||
private val typesWithExtensionContains: Collection<KtType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
|
||||
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }
|
||||
.map { it.getExtensionReceiverParameter()!!.getType() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user