Fixed formatting
This commit is contained in:
+36
-30
@@ -48,11 +48,11 @@ import org.jetbrains.kotlin.types.isError
|
||||
import java.util.*
|
||||
|
||||
class VariableOrParameterNameWithTypeCompletion(
|
||||
private val collector: LookupElementsCollector,
|
||||
private val lookupElementFactory: BasicLookupElementFactory,
|
||||
private val prefixMatcher: PrefixMatcher,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val withType: Boolean
|
||||
private val collector: LookupElementsCollector,
|
||||
private val lookupElementFactory: BasicLookupElementFactory,
|
||||
private val prefixMatcher: PrefixMatcher,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val withType: Boolean
|
||||
) {
|
||||
private val userPrefixes: List<String>
|
||||
private val classNamePrefixMatchers: List<PrefixMatcher>
|
||||
@@ -77,7 +77,8 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
fun addFromImportedClasses(position: PsiElement, bindingContext: BindingContext, visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
for ((classNameMatcher, userPrefix) in classNamePrefixMatchers.zip(userPrefixes)) {
|
||||
val resolutionScope = position.getResolutionScope(bindingContext, resolutionFacade)
|
||||
val classifiers = resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter())
|
||||
val classifiers =
|
||||
resolutionScope.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classNameMatcher.asNameFilter())
|
||||
|
||||
for (classifier in classifiers) {
|
||||
if (visibilityFilter(classifier)) {
|
||||
@@ -92,21 +93,25 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
fun addFromAllClasses(parameters: CompletionParameters, indicesHelper: KotlinIndicesHelper) {
|
||||
for ((classNameMatcher, userPrefix) in classNamePrefixMatchers.zip(userPrefixes)) {
|
||||
AllClassesCompletion(
|
||||
parameters, indicesHelper, classNameMatcher, resolutionFacade, { !it.isSingleton },
|
||||
includeTypeAliases = true, includeJavaClassesNotToBeUsed = false
|
||||
parameters, indicesHelper, classNameMatcher, resolutionFacade, { !it.isSingleton },
|
||||
includeTypeAliases = true, includeJavaClassesNotToBeUsed = false
|
||||
).collect(
|
||||
{ addSuggestionsForClassifier(it, userPrefix, notImported = true) },
|
||||
{ addSuggestionsForJavaClass(it, userPrefix, notImported = true) }
|
||||
{ addSuggestionsForClassifier(it, userPrefix, notImported = true) },
|
||||
{ addSuggestionsForJavaClass(it, userPrefix, notImported = true) }
|
||||
)
|
||||
|
||||
collector.flushToResultSet()
|
||||
}
|
||||
}
|
||||
|
||||
fun addFromParametersInFile(position: PsiElement, resolutionFacade: ResolutionFacade, visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
fun addFromParametersInFile(
|
||||
position: PsiElement,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
visibilityFilter: (DeclarationDescriptor) -> Boolean
|
||||
) {
|
||||
val lookupElementToCount = LinkedHashMap<LookupElement, Pair<Int, String>>()
|
||||
position.containingFile.forEachDescendantOfType<KtParameter>(
|
||||
canGoInside = { it !is KtExpression || it is KtDeclaration } // we analyze parameters inside bodies to not resolve too much
|
||||
canGoInside = { it !is KtExpression || it is KtDeclaration } // we analyze parameters inside bodies to not resolve too much
|
||||
) { parameter ->
|
||||
ProgressManager.checkCanceled()
|
||||
|
||||
@@ -172,26 +177,27 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
override fun hashCode() = idString.hashCode()
|
||||
}
|
||||
|
||||
private class DescriptorType(private val classifier: ClassifierDescriptor) : Type(IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classifier)) {
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory)
|
||||
= lookupElementFactory.createLookupElement(classifier, qualifyNestedClasses = true)
|
||||
private class DescriptorType(private val classifier: ClassifierDescriptor) :
|
||||
Type(IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classifier)) {
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory) =
|
||||
lookupElementFactory.createLookupElement(classifier, qualifyNestedClasses = true)
|
||||
}
|
||||
|
||||
private class JavaClassType(private val psiClass: PsiClass) : Type(psiClass.qualifiedName!!) {
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory)
|
||||
= lookupElementFactory.createLookupElementForJavaClass(psiClass, qualifyNestedClasses = true)
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory) =
|
||||
lookupElementFactory.createLookupElementForJavaClass(psiClass, qualifyNestedClasses = true)
|
||||
}
|
||||
|
||||
private class ArbitraryType(private val type: KotlinType) : Type(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)) {
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory)
|
||||
= lookupElementFactory.createLookupElementForType(type)
|
||||
override fun createTypeLookupElement(lookupElementFactory: BasicLookupElementFactory) =
|
||||
lookupElementFactory.createLookupElementForType(type)
|
||||
}
|
||||
|
||||
private class MyLookupElement private constructor(
|
||||
private val parameterName: String,
|
||||
private val type: Type,
|
||||
typeLookupElement: LookupElement,
|
||||
private val shouldInsertType: Boolean
|
||||
private val parameterName: String,
|
||||
private val type: Type,
|
||||
typeLookupElement: LookupElement,
|
||||
private val shouldInsertType: Boolean
|
||||
) : LookupElementDecorator<LookupElement>(typeLookupElement) {
|
||||
|
||||
companion object {
|
||||
@@ -216,8 +222,7 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
super.renderElement(presentation)
|
||||
if (shouldInsertType) {
|
||||
presentation.itemText = parameterName + ": " + presentation.itemText
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
presentation.prependTailText(": " + presentation.itemText, true)
|
||||
presentation.itemText = parameterName
|
||||
}
|
||||
@@ -240,7 +245,8 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
val settings = CodeStyleSettingsManager.getInstance(context.project).currentSettings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
||||
val settings =
|
||||
CodeStyleSettingsManager.getInstance(context.project).currentSettings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
||||
val spaceBefore = if (settings.SPACE_BEFORE_TYPE_COLON) " " else ""
|
||||
val spaceAfter = if (settings.SPACE_AFTER_TYPE_COLON) " " else ""
|
||||
|
||||
@@ -253,16 +259,16 @@ class VariableOrParameterNameWithTypeCompletion(
|
||||
context.offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, startOffset + text.length)
|
||||
|
||||
super.handleInsert(context)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
context.document.replaceString(startOffset, context.tailOffset, parameterName)
|
||||
|
||||
context.commitDocument()
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?)
|
||||
= other is MyLookupElement && parameterName == other.parameterName && type == other.type && shouldInsertType == other.shouldInsertType
|
||||
override fun equals(other: Any?) =
|
||||
other is MyLookupElement && parameterName == other.parameterName && type == other.type && shouldInsertType == other.shouldInsertType
|
||||
|
||||
override fun hashCode() = parameterName.hashCode()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user