More cleanup: lift return / assignment out
This commit is contained in:
+3
-3
@@ -58,10 +58,10 @@ abstract class DeclarationLookupObjectImpl(
|
||||
if (this === other) return true
|
||||
if (other == null || this::class.java != other::class.java) return false
|
||||
val lookupObject = other as DeclarationLookupObjectImpl
|
||||
if (descriptor != null)
|
||||
return descriptorsEqualWithSubstitution(descriptor, lookupObject.descriptor)
|
||||
return if (descriptor != null)
|
||||
descriptorsEqualWithSubstitution(descriptor, lookupObject.descriptor)
|
||||
else
|
||||
return lookupObject.descriptor == null && psiElement == lookupObject.psiElement
|
||||
lookupObject.descriptor == null && psiElement == lookupObject.psiElement
|
||||
}
|
||||
|
||||
override val isDeprecated: Boolean
|
||||
|
||||
+4
-4
@@ -147,19 +147,19 @@ class KDocNameCompletionSession(
|
||||
fun collectDescriptorsForLinkCompletion(declarationDescriptor: DeclarationDescriptor, kDocLink: KDocLink): Sequence<DeclarationDescriptor> {
|
||||
val qualifiedLink = kDocLink.getLinkText().split('.').dropLast(1)
|
||||
val nameFilter = descriptorNameFilter.toNameFilter()
|
||||
if (qualifiedLink.isNotEmpty()) {
|
||||
return if (qualifiedLink.isNotEmpty()) {
|
||||
val parentDescriptors = resolveKDocLink(bindingContext, resolutionFacade, declarationDescriptor, kDocLink.getTagIfSubject(), qualifiedLink)
|
||||
val childDescriptorsOfPartialLink = parentDescriptors.asSequence().flatMap {
|
||||
val scope = getKDocLinkResolutionScope(resolutionFacade, it)
|
||||
collectDescriptorsFromScope(scope, nameFilter, false)
|
||||
}
|
||||
|
||||
return (collectPackageViewDescriptors(qualifiedLink, nameFilter) + childDescriptorsOfPartialLink)
|
||||
(collectPackageViewDescriptors(qualifiedLink, nameFilter) + childDescriptorsOfPartialLink)
|
||||
}
|
||||
else {
|
||||
val scope = getKDocLinkResolutionScope(resolutionFacade, declarationDescriptor)
|
||||
return (collectDescriptorsFromScope(scope, nameFilter, true)
|
||||
+ collectPackageViewDescriptors(qualifiedLink, nameFilter))
|
||||
(collectDescriptorsFromScope(scope, nameFilter, true)
|
||||
+ collectPackageViewDescriptors(qualifiedLink, nameFilter))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,11 +254,11 @@ object KeywordCompletion {
|
||||
val scope = parent.parent
|
||||
when (scope) {
|
||||
is KtClassOrObject -> {
|
||||
if (parent is KtPrimaryConstructor) {
|
||||
return buildFilterWithReducedContext("class X ", parent, position)
|
||||
return if (parent is KtPrimaryConstructor) {
|
||||
buildFilterWithReducedContext("class X ", parent, position)
|
||||
}
|
||||
else {
|
||||
return buildFilterWithReducedContext("class X { ", parent, position)
|
||||
buildFilterWithReducedContext("class X { ", parent, position)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -386,22 +386,22 @@ class KotlinCompletionContributor : CompletionContributor() {
|
||||
val nameRef = nameToken.parent 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.kind == ClassKind.CLASS }) {
|
||||
return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + ">".repeat(balance) + "$"
|
||||
return if (targets.isNotEmpty() && targets.all { it is FunctionDescriptor || it is ClassDescriptor && it.kind == ClassKind.CLASS }) {
|
||||
CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + ">".repeat(balance) + "$"
|
||||
}
|
||||
else {
|
||||
return null
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun unclosedTypeArgListNameAndBalance(tokenBefore: PsiElement): Pair<PsiElement, Int>? {
|
||||
val nameToken = findCallNameTokenIfInTypeArgs(tokenBefore) ?: return null
|
||||
val pair = unclosedTypeArgListNameAndBalance(nameToken)
|
||||
if (pair == null) {
|
||||
return Pair(nameToken, 1)
|
||||
return if (pair == null) {
|
||||
Pair(nameToken, 1)
|
||||
}
|
||||
else {
|
||||
return Pair(pair.first, pair.second + 1)
|
||||
Pair(pair.first, pair.second + 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -154,11 +154,11 @@ class OverridesCompletion(
|
||||
|
||||
is KtValVarKeywordOwner -> {
|
||||
if (descriptorToOverride !is PropertyDescriptor) return false
|
||||
if (declaration.valOrVarKeyword?.node?.elementType == KtTokens.VAL_KEYWORD) {
|
||||
return !descriptorToOverride.isVar
|
||||
return if (declaration.valOrVarKeyword?.node?.elementType == KtTokens.VAL_KEYWORD) {
|
||||
!descriptorToOverride.isVar
|
||||
}
|
||||
else {
|
||||
return true // var can override either var or val
|
||||
true // var can override either var or val
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ object PreferGetSetMethodsToPropertyWeigher : LookupElementWeigher("kotlin.prefe
|
||||
val prefixMatcher = context.itemMatcher(element)
|
||||
if (prefixMatcher.prefixMatches(property.name.asString())) return 0
|
||||
val matchedLookupStrings = element.allLookupStrings.filter { prefixMatcher.prefixMatches(it) }
|
||||
if (matchedLookupStrings.all { it.startsWith("get") || it.startsWith("set") }) return 1 else return 0
|
||||
return if (matchedLookupStrings.all { it.startsWith("get") || it.startsWith("set") }) 1 else 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -94,12 +94,12 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() {
|
||||
|
||||
private fun qualifiedNameToInsert(item: LookupElement): String {
|
||||
val lookupObject = item.`object` as DeclarationLookupObject
|
||||
if (lookupObject.descriptor != null) {
|
||||
return IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassifierDescriptor)
|
||||
return if (lookupObject.descriptor != null) {
|
||||
IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassifierDescriptor)
|
||||
}
|
||||
else {
|
||||
val qualifiedName = (lookupObject.psiElement as PsiClass).qualifiedName!!
|
||||
return if (FqNameUnsafe.isValid(qualifiedName)) FqNameUnsafe(qualifiedName).render() else qualifiedName
|
||||
if (FqNameUnsafe.isValid(qualifiedName)) FqNameUnsafe(qualifiedName).render() else qualifiedName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -176,11 +176,11 @@ class TypeInstantiationItems(
|
||||
val typeArgsToUse = typeArgs.map { TypeProjectionImpl(Variance.INVARIANT, it.type) }
|
||||
|
||||
val allTypeArgsKnown = fuzzyType.freeParameters.isEmpty() || typeArgs.none { it.type.areTypeParametersUsedInside(fuzzyType.freeParameters) }
|
||||
if (allTypeArgsKnown) {
|
||||
itemText += IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgsToUse)
|
||||
itemText += if (allTypeArgsKnown) {
|
||||
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgsToUse)
|
||||
}
|
||||
else {
|
||||
itemText += "<...>"
|
||||
"<...>"
|
||||
}
|
||||
|
||||
val constructorParenthesis = if (classifier.kind != ClassKind.INTERFACE) "()" else ""
|
||||
|
||||
@@ -315,11 +315,11 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
if (this is VariableDescriptor) { //TODO: generic properties!
|
||||
return smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) }
|
||||
return if (this is VariableDescriptor) { //TODO: generic properties!
|
||||
smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) }
|
||||
}
|
||||
else {
|
||||
return listOf(returnType)
|
||||
listOf(returnType)
|
||||
}
|
||||
}
|
||||
else if (this is ClassDescriptor && kind.isSingleton) {
|
||||
|
||||
Reference in New Issue
Block a user