Code cleanup: several inspections applied
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fdca96634e
commit
840847e47c
+1
-2
@@ -264,8 +264,7 @@ class ReferenceVariantsHelper(
|
||||
|
||||
if (isStatic) {
|
||||
explicitReceiverTypes
|
||||
.map { (it.constructor.declarationDescriptor as? ClassDescriptor)?.staticScope }
|
||||
.filterNotNull()
|
||||
.mapNotNull { (it.constructor.declarationDescriptor as? ClassDescriptor)?.staticScope }
|
||||
.flatMapTo(descriptors) { it.collectStaticMembers(resolutionFacade, kindFilter, nameFilter) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo,
|
||||
get() = LibrarySourceInfo(project, library)
|
||||
|
||||
override fun getLibraryRoots(): Collection<String> =
|
||||
library.getFiles(OrderRootType.CLASSES).map(PathUtil::getLocalPath).filterNotNull()
|
||||
library.getFiles(OrderRootType.CLASSES).mapNotNull(PathUtil::getLocalPath)
|
||||
|
||||
override fun toString() = "LibraryInfo(libraryName=${library.name})"
|
||||
|
||||
|
||||
+2
-2
@@ -82,7 +82,7 @@ private fun findDeclarationInCompiledFile(file: KtClsFile, member: PsiMember, si
|
||||
file
|
||||
else {
|
||||
val topClassOrObject = file.declarations.singleOrNull() as? KtClassOrObject
|
||||
relativeClassName.fold<Name, KtClassOrObject?>(topClassOrObject) { classOrObject, name ->
|
||||
relativeClassName.fold(topClassOrObject) { classOrObject, name ->
|
||||
classOrObject?.declarations?.singleOrNull { it.name == name.asString() } as? KtClassOrObject
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ private fun PsiMember.relativeClassName(): List<Name> {
|
||||
}
|
||||
|
||||
private fun ClassDescriptor.relativeClassName(): List<Name> {
|
||||
return classId!!.relativeClassName.pathSegments().drop(1).orEmpty()
|
||||
return classId!!.relativeClassName.pathSegments().drop(1)
|
||||
}
|
||||
|
||||
private fun ClassDescriptor.desc(): String = "L" + JvmClassName.byClassId(classId!!).internalName + ";"
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ object SourceNavigationHelper {
|
||||
.mapNotNull { it.sourcesModuleInfo?.sourceScope() }.union()
|
||||
|
||||
NavigationKind.SOURCES_TO_CLASS_FILES -> getLibrarySourcesModuleInfos(declaration.project, vFile)
|
||||
.mapNotNull { it.binariesModuleInfo.binariesScope() }.union()
|
||||
.map { it.binariesModuleInfo.binariesScope() }.union()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ private fun createQuickFixes(similarDiagnostics: Collection<Diagnostic>): MultiM
|
||||
val actions = MultiMap<Diagnostic, IntentionAction>()
|
||||
|
||||
val intentionActionsFactories = QuickFixes.getInstance().getActionFactories(factory)
|
||||
for (intentionActionsFactory in intentionActionsFactories.filterNotNull()) {
|
||||
for (intentionActionsFactory in intentionActionsFactories) {
|
||||
val allProblemsActions = intentionActionsFactory.createActionsForAllProblems(similarDiagnostics)
|
||||
if (!allProblemsActions.isEmpty()) {
|
||||
actions.putValues(first, allProblemsActions)
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ private object DeclarationKindDetector : KtVisitor<AnnotationHostKind?, Unit?>()
|
||||
override fun visitProperty(d: KtProperty, data: Unit?) = detect(d, d.valOrVarKeyword.text!!)
|
||||
|
||||
override fun visitDestructuringDeclaration(d: KtDestructuringDeclaration, data: Unit?) = detect(d, d.valOrVarKeyword?.text ?: "val",
|
||||
name = d.entries.map { it.name!! }.joinToString(", ", "(", ")"))
|
||||
name = d.entries.joinToString(", ", "(", ")") { it.name!! })
|
||||
|
||||
override fun visitTypeParameter(d: KtTypeParameter, data: Unit?) = detect(d, "type parameter", newLineNeeded = false)
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ fun renderResolvedCall(resolvedCall: ResolvedCall<*>, context: RenderingContext)
|
||||
|
||||
append("<br/>$indent<i>where</i> ")
|
||||
if (!notInferredTypeParameters.isEmpty()) {
|
||||
append(notInferredTypeParameters.map { typeParameter -> renderError(typeParameter.name) }.joinToString())
|
||||
append(notInferredTypeParameters.joinToString { typeParameter -> renderError(typeParameter.name) })
|
||||
append("<i> cannot be inferred</i>")
|
||||
if (!inferredTypeParameters.isEmpty()) {
|
||||
append("; ")
|
||||
@@ -91,9 +91,9 @@ fun renderResolvedCall(resolvedCall: ResolvedCall<*>, context: RenderingContext)
|
||||
|
||||
val typeParameterToTypeArgumentMap = resolvedCall.typeArguments
|
||||
if (!inferredTypeParameters.isEmpty()) {
|
||||
append(inferredTypeParameters.map { typeParameter ->
|
||||
append(inferredTypeParameters.joinToString { typeParameter ->
|
||||
"${typeParameter.name} = ${typeRenderer.render(typeParameterToTypeArgumentMap[typeParameter]!!, context)}"
|
||||
}.joinToString())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ fun renderResolvedCall(resolvedCall: ResolvedCall<*>, context: RenderingContext)
|
||||
append(typeRenderer.render(receiverParameter.type, context)).append(".")
|
||||
}
|
||||
append(HtmlEscapers.htmlEscaper().escape(resultingDescriptor.name.asString())).append("(")
|
||||
append(resultingDescriptor.valueParameters.map(::renderParameter).joinToString())
|
||||
append(resultingDescriptor.valueParameters.joinToString(transform = ::renderParameter))
|
||||
append(if (resolvedCall.hasUnmappedArguments()) renderError(")") else ")")
|
||||
|
||||
if (!resolvedCall.candidateDescriptor.typeParameters.isEmpty()) {
|
||||
|
||||
@@ -205,8 +205,7 @@ class ResolveElementCache(
|
||||
}
|
||||
else {
|
||||
contextElements
|
||||
.map { it.getNonStrictParentOfType<KtDeclaration>() }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.getNonStrictParentOfType<KtDeclaration>() }
|
||||
.filterTo(declarationsToResolve) {
|
||||
it !is KtAnonymousInitializer && it !is KtDestructuringDeclaration && it !is KtDestructuringDeclarationEntry
|
||||
}
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ class BasicLookupElementFactory(
|
||||
is ClassifierDescriptorWithTypeParameters -> {
|
||||
val typeParams = descriptor.declaredTypeParameters
|
||||
if (includeClassTypeArguments && typeParams.isNotEmpty()) {
|
||||
element = element.appendTailText(typeParams.map { it.name.asString() }.joinToString(", ", "<", ">"), true)
|
||||
element = element.appendTailText(typeParams.joinToString(", ", "<", ">") { it.name.asString() }, true)
|
||||
}
|
||||
|
||||
var container = descriptor.containingDeclaration
|
||||
|
||||
+1
-3
@@ -109,9 +109,7 @@ object LambdaSignatureTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
return functionParameterTypes(lambdaType)
|
||||
.map(::parameterPresentation)
|
||||
.joinToString(", ") + " ->"
|
||||
return functionParameterTypes(lambdaType).joinToString(", ", transform = ::parameterPresentation) + " ->"
|
||||
}
|
||||
|
||||
fun explicitParameterTypesRequired(file: KtFile, placeholderRange: TextRange, lambdaType: KotlinType): Boolean {
|
||||
|
||||
+2
-2
@@ -209,9 +209,9 @@ class LookupElementFactory(
|
||||
if (descriptor.valueParameters.isEmpty()) return null
|
||||
if (descriptor.findOriginalTopMostOverriddenDescriptors().none { it in superFunctions }) return null
|
||||
|
||||
val argumentText = descriptor.valueParameters.map {
|
||||
val argumentText = descriptor.valueParameters.joinToString(", ") {
|
||||
(if (it.varargElementType != null) "*" else "") + it.name.render()
|
||||
}.joinToString(", ") //TODO: use code formatting settings
|
||||
} //TODO: use code formatting settings
|
||||
|
||||
val lookupElement = createFunctionCallElementWithArguments(descriptor, argumentText, true)
|
||||
lookupElement.assignPriority(ItemPriority.SUPER_METHOD_WITH_ARGUMENTS)
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ class MultipleArgumentsItemProvider(
|
||||
compoundIcon.setIcon(firstIcon, 1, 0, 0)
|
||||
|
||||
return LookupElementBuilder
|
||||
.create(variables.map { it.name.render() }.joinToString(", ")) //TODO: use code formatting settings
|
||||
.create(variables.joinToString(", ") { it.name.render() }) //TODO: use code formatting settings
|
||||
.withInsertHandler { context, _ ->
|
||||
if (context.completionChar == Lookup.REPLACE_SELECT_CHAR) {
|
||||
val offset = context.offsetMap.tryGetOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET)
|
||||
|
||||
@@ -475,7 +475,7 @@ class KotlinIndicesHelper(
|
||||
private fun KtNamedDeclaration.resolveToDescriptorsWithHack(
|
||||
psiFilter: (KtDeclaration) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (containingKtFile.isCompiled) { //TODO: it's temporary while resolveToDescriptor does not work for compiled declarations
|
||||
return resolutionFacade.resolveImportReference(moduleDescriptor, fqName!!).filterIsInstance<DeclarationDescriptor>()
|
||||
return resolutionFacade.resolveImportReference(moduleDescriptor, fqName!!)
|
||||
}
|
||||
else {
|
||||
val translatedDeclaration = declarationTranslator(this) ?: return emptyList()
|
||||
|
||||
@@ -168,7 +168,7 @@ fun String.quoteIfNeeded(): String = if (KotlinNameSuggester.isIdentifier(this))
|
||||
fun String.unquote(): String = KtPsiUtil.unquoteIdentifier(this)
|
||||
|
||||
fun FqName.quoteSegmentsIfNeeded(): String {
|
||||
return pathSegments().map { it.asString().quoteIfNeeded() }.joinToString(".")
|
||||
return pathSegments().joinToString(".") { it.asString().quoteIfNeeded() }
|
||||
}
|
||||
|
||||
fun FqName.quoteIfNeeded() = FqName(quoteSegmentsIfNeeded())
|
||||
|
||||
@@ -176,7 +176,7 @@ fun <T : KtDeclaration> insertMembersAfter(
|
||||
val body = classOrObject.getOrCreateBody()
|
||||
|
||||
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return@runWriteAction emptyList<T>()
|
||||
otherMembers.mapNotNullTo(insertedMembers) {
|
||||
otherMembers.mapTo(insertedMembers) {
|
||||
if (classOrObject is KtClass && classOrObject.isEnum()) {
|
||||
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
|
||||
val bound = (enumEntries.lastOrNull() ?: classOrObject.allChildren.firstOrNull { it.node.elementType == KtTokens.SEMICOLON })
|
||||
|
||||
+1
-3
@@ -90,9 +90,7 @@ class KotlinMavenArchetypesProvider(val kotlinPluginVersion: String, val predefi
|
||||
"v" to version,
|
||||
"p" to packaging
|
||||
)
|
||||
.filter { it.second != null }
|
||||
.map { "${it.first}:\"${it.second}\"" }
|
||||
.joinToString(separator = " AND ")
|
||||
.filter { it.second != null }.joinToString(separator = " AND ") { "${it.first}:\"${it.second}\"" }
|
||||
|
||||
return "http://search.maven.org/solrsearch/select?q=${q.encodeURL()}&core=gav&rows=$rowsLimit&wt=json"
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ class KotlinConsoleKeeper(val project: Project) {
|
||||
|
||||
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
|
||||
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.stdlibPath, kotlinPaths.scriptRuntimePath)
|
||||
.map { it.absolutePath }
|
||||
.joinToString(File.pathSeparator)
|
||||
.joinToString(File.pathSeparator) { it.absolutePath }
|
||||
|
||||
paramList.add("-cp")
|
||||
paramList.add(replClassPath)
|
||||
|
||||
@@ -111,9 +111,9 @@ class ReplOutputProcessor(
|
||||
)
|
||||
val lastCommandStartOffset = lastUnprocessedHistoryEntry.rangeInHistoryDocument.startOffset
|
||||
val lastCommandStartLine = historyDocument.getLineNumber(lastCommandStartOffset)
|
||||
val historyCommandRunIndicator = historyMarkup.allHighlighters.filter {
|
||||
val historyCommandRunIndicator = historyMarkup.allHighlighters.first {
|
||||
historyDocument.getLineNumber(it.startOffset) == lastCommandStartLine && it.gutterIconRenderer != null
|
||||
}.first()
|
||||
}
|
||||
|
||||
val highlighterAndMessagesByLine = compilerMessages.filter {
|
||||
it.severity == Severity.ERROR || it.severity == Severity.WARNING
|
||||
|
||||
@@ -61,15 +61,11 @@ internal fun createSingleImportAction(
|
||||
): KotlinAddImportAction {
|
||||
val file = element.containingKtFile
|
||||
val prioritizer = Prioritizer(element.containingKtFile)
|
||||
val variants = fqNames
|
||||
.map { fqName ->
|
||||
val sameFqNameDescriptors = file.resolveImportReference(fqName)
|
||||
val priority = sameFqNameDescriptors.map { prioritizer.priority(it) }.min() ?: return@map null
|
||||
Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority)
|
||||
}
|
||||
.filterNotNull()
|
||||
.sortedBy { it.priority }
|
||||
.map { it.variant }
|
||||
val variants = fqNames.mapNotNull { fqName ->
|
||||
val sameFqNameDescriptors = file.resolveImportReference(fqName)
|
||||
val priority = sameFqNameDescriptors.map { prioritizer.priority(it) }.min() ?: return@mapNotNull null
|
||||
Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority)
|
||||
}.sortedBy { it.priority }.map { it.variant }
|
||||
|
||||
return KotlinAddImportAction(project, editor, element, variants)
|
||||
}
|
||||
@@ -82,18 +78,14 @@ internal fun createSingleImportActionForConstructor(
|
||||
): KotlinAddImportAction {
|
||||
val file = element.containingKtFile
|
||||
val prioritizer = Prioritizer(element.containingKtFile)
|
||||
val variants = fqNames
|
||||
.map { fqName ->
|
||||
val sameFqNameDescriptors = file.resolveImportReference(fqName.parent())
|
||||
.filterIsInstance<ClassDescriptor>()
|
||||
.flatMap { it.constructors }
|
||||
val variants = fqNames.mapNotNull { fqName ->
|
||||
val sameFqNameDescriptors = file.resolveImportReference(fqName.parent())
|
||||
.filterIsInstance<ClassDescriptor>()
|
||||
.flatMap { it.constructors }
|
||||
|
||||
val priority = sameFqNameDescriptors.map { prioritizer.priority(it) }.min() ?: return@map null
|
||||
Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority)
|
||||
}
|
||||
.filterNotNull()
|
||||
.sortedBy { it.priority }
|
||||
.map { it.variant }
|
||||
val priority = sameFqNameDescriptors.map { prioritizer.priority(it) }.min() ?: return@mapNotNull null
|
||||
Prioritizer.VariantWithPriority(SingleImportVariant(fqName, sameFqNameDescriptors), priority)
|
||||
}.sortedBy { it.priority }.map { it.variant }
|
||||
return KotlinAddImportAction(project, editor, element, variants)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ class KotlinCreateFromTemplateHandler : DefaultCreateFromTemplateHandler() {
|
||||
if (!packageName.isNullOrEmpty()) {
|
||||
props[FileTemplate.ATTRIBUTE_PACKAGE_NAME] = packageName!!
|
||||
.split('.')
|
||||
.map(String::quoteIfNeeded)
|
||||
.joinToString(".")
|
||||
.joinToString(".", transform = String::quoteIfNeeded)
|
||||
}
|
||||
|
||||
val name = props[FileTemplate.ATTRIBUTE_NAME] as? String
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase<Kot
|
||||
var typeForCast = IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classDescriptor)
|
||||
val typeParams = classDescriptor.declaredTypeParameters
|
||||
if (typeParams.isNotEmpty()) {
|
||||
typeForCast += typeParams.map { "*" }.joinToString(prefix = "<", postfix = ">")
|
||||
typeForCast += typeParams.joinToString(prefix = "<", postfix = ">") { "*" }
|
||||
}
|
||||
|
||||
val useIsCheck = CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER
|
||||
|
||||
@@ -103,7 +103,7 @@ class KotlinCoverageExtension : JavaCoverageEngineExtension() {
|
||||
if (existingClassFiles.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
LOG.debug("Classfiles: [${existingClassFiles.map { it.name }.joinToString()}]")
|
||||
LOG.debug("Classfiles: [${existingClassFiles.joinToString { it.name }}]")
|
||||
return existingClassFiles.map {
|
||||
val relativePath = VfsUtilCore.getRelativePath(it, outputRoot!!)!!
|
||||
StringUtil.trimEnd(relativePath, ".class").replace("/", ".")
|
||||
|
||||
+4
-4
@@ -55,13 +55,13 @@ fun getFunctionForExtractedFragment(
|
||||
attachmentByPsiFile(codeFragment),
|
||||
Attachment("breakpoint.info", "line: $breakpointLine"),
|
||||
Attachment("context.info", codeFragment.context?.text ?: "null"),
|
||||
Attachment("errors.info", analysisResult.messages.map { "$it: ${it.renderMessage()}" }.joinToString("\n")))
|
||||
Attachment("errors.info", analysisResult.messages.joinToString("\n") { "$it: ${it.renderMessage()}" }))
|
||||
LOG.error(LogMessageEx.createEvent(
|
||||
"Internal error during evaluate expression",
|
||||
ExceptionUtil.getThrowableText(Throwable("Extract function fails with ${analysisResult.messages.joinToString { it.name }}")),
|
||||
mergeAttachments(*attachments)))
|
||||
}
|
||||
return analysisResult.messages.map { errorMessage ->
|
||||
return analysisResult.messages.joinToString(", ") { errorMessage ->
|
||||
val message = when(errorMessage) {
|
||||
ErrorMessage.NO_EXPRESSION -> "Cannot perform an action without an expression"
|
||||
ErrorMessage.NO_CONTAINER -> "Cannot perform an action at this breakpoint ${breakpointFile.name}:$breakpointLine"
|
||||
@@ -76,7 +76,7 @@ fun getFunctionForExtractedFragment(
|
||||
ErrorMessage.MULTIPLE_OUTPUT -> throw AssertionError("Unexpected error: $errorMessage")
|
||||
}
|
||||
errorMessage.additionalInfo?.let { "$message: ${it.joinToString(", ")}" } ?: message
|
||||
}.joinToString(", ")
|
||||
}
|
||||
}
|
||||
|
||||
fun generateFunction(): ExtractionResult? {
|
||||
@@ -104,7 +104,7 @@ fun getFunctionForExtractedFragment(
|
||||
|
||||
val validationResult = analysisResult.descriptor!!.validate()
|
||||
if (!validationResult.conflicts.isEmpty) {
|
||||
throw EvaluateExceptionUtil.createEvaluateException("Following declarations are unavailable in debug scope: ${validationResult.conflicts.keySet().map { it.text }.joinToString(",")}")
|
||||
throw EvaluateExceptionUtil.createEvaluateException("Following declarations are unavailable in debug scope: ${validationResult.conflicts.keySet().joinToString(",") { it.text }}")
|
||||
}
|
||||
|
||||
val generatorOptions = ExtractionGeneratorOptions(inTempFile = true,
|
||||
|
||||
+1
-1
@@ -381,7 +381,7 @@ fun getStepOverAction(
|
||||
val patchedLineNumber = patchedLocation.ktLineNumber()
|
||||
|
||||
val lambdaArgumentRanges = runReadAction {
|
||||
inlineFunctionArguments.filterIsInstance<KtElement>().map {
|
||||
inlineFunctionArguments.map {
|
||||
val startLineNumber = it.getLineNumber(true) + 1
|
||||
val endLineNumber = it.getLineNumber(false) + 1
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPane
|
||||
|
||||
add(rbUseSingleImports, true)
|
||||
add(rbUseStarImports, true)
|
||||
val jPanel: JPanel = JPanel(GridBagLayout())
|
||||
val jPanel = JPanel(GridBagLayout())
|
||||
add(jPanel.apply {
|
||||
val constraints = GridBagConstraints().apply { gridx = GridBagConstraints.RELATIVE }
|
||||
this.add(rbUseStarImportsIfAtLeast, constraints)
|
||||
|
||||
+2
-2
@@ -60,9 +60,9 @@ class DifferentKotlinGradleVersionInspection : GradleBaseInspection() {
|
||||
val buildScriptCall = dependenciesCall.getStrictParentOfType<GrMethodCall>() ?: return
|
||||
if (buildScriptCall.invokedExpression.text != "buildscript") return
|
||||
|
||||
val kotlinPluginStatement = findClassPathStatements(closure).filter {
|
||||
val kotlinPluginStatement = findClassPathStatements(closure).firstOrNull {
|
||||
it.text.contains(KOTLIN_PLUGIN_CLASSPATH_MARKER)
|
||||
}.firstOrNull() ?: return
|
||||
} ?: return
|
||||
|
||||
val kotlinPluginVersion =
|
||||
getHeuristicKotlinPluginVersion(kotlinPluginStatement) ?:
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ class ConvertFunctionTypeParameterToReceiverIntention : SelfTargetingRangeIntent
|
||||
}
|
||||
|
||||
private fun generateVariable(expression: KtExpression): String {
|
||||
var baseCallee: String = ""
|
||||
var baseCallee = ""
|
||||
KotlinIntroduceVariableHandler.doRefactoring(project, null, expression, false, emptyList()) {
|
||||
baseCallee = it.name!!
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class InsertExplicitTypeArgumentsIntention : SelfTargetingRangeIntention<KtCallE
|
||||
val args = resolvedCall.typeArguments
|
||||
val types = resolvedCall.candidateDescriptor.typeParameters
|
||||
|
||||
val text = types.map { IdeDescriptorRenderers.SOURCE_CODE.renderType(args[it]!!) }.joinToString(", ", "<", ">")
|
||||
val text = types.joinToString(", ", "<", ">") { IdeDescriptorRenderers.SOURCE_CODE.renderType(args[it]!!) }
|
||||
|
||||
return KtPsiFactory(element).createTypeArguments(text)
|
||||
}
|
||||
|
||||
+1
-1
@@ -215,7 +215,7 @@ class ConvertMemberToExtensionIntention : SelfTargetingRangeIntention<KtCallable
|
||||
val classParams = classElement.typeParameters
|
||||
if (classParams.isEmpty()) return null
|
||||
val allTypeParameters = classParams + member.typeParameters
|
||||
val text = allTypeParameters.map { it.text }.joinToString(",", "<", ">")
|
||||
val text = allTypeParameters.joinToString(",", "<", ">") { it.text }
|
||||
return KtPsiFactory(member).createDeclaration<KtFunction>("fun $text foo()").typeParameterList
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ object KDocRenderer {
|
||||
|
||||
val lines = text.split('\n')
|
||||
val minIndent = lines.filter { it.trim().isNotEmpty() }.map(String::leadingIndent).min() ?: 0
|
||||
return lines.map { it.drop(minIndent) }.joinToString("\n")
|
||||
return lines.joinToString("\n") { it.drop(minIndent) }
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ object KDocRenderer {
|
||||
val markdownNode = MarkdownNode(markdownTree, null, markdown)
|
||||
|
||||
// Avoid wrapping the entire converted contents in a <p> tag if it's just a single paragraph
|
||||
val maybeSingleParagraph = markdownNode.children.filter { it.type != MarkdownTokenTypes.EOL }.singleOrNull()
|
||||
val maybeSingleParagraph = markdownNode.children.singleOrNull { it.type != MarkdownTokenTypes.EOL }
|
||||
if (maybeSingleParagraph != null && !allowSingleParagraph) {
|
||||
return maybeSingleParagraph.children.joinToString("") { it.toHtml() }
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class ConvertExtensionToFunctionTypeFix(element: KtTypeReference, type: KotlinTy
|
||||
|
||||
private fun KotlinType.renderType(renderer: DescriptorRenderer) = buildString {
|
||||
append('(')
|
||||
arguments.dropLast(1).map { renderer.renderType(it.type) }.joinTo(this@buildString, ", ")
|
||||
arguments.dropLast(1).joinTo(this@buildString, ", ") { renderer.renderType(it.type) }
|
||||
append(") -> ")
|
||||
append(renderer.renderType(this@renderType.getReturnTypeFromFunctionType()))
|
||||
}
|
||||
|
||||
+2
-2
@@ -427,7 +427,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
|
||||
fun renderParamList(): String {
|
||||
val prefix = if (classKind == ClassKind.ANNOTATION_CLASS) "val " else ""
|
||||
val list = callableInfo.parameterInfos.indices.map { i -> "${prefix}p$i: Any" }.joinToString(", ")
|
||||
val list = callableInfo.parameterInfos.indices.joinToString(", ") { i -> "${prefix}p$i: Any" }
|
||||
return if (callableInfo.parameterInfos.isNotEmpty()
|
||||
|| callableInfo.kind == CallableKind.FUNCTION
|
||||
|| callableInfo.kind == CallableKind.SECONDARY_CONSTRUCTOR) "($list)" else list
|
||||
@@ -972,7 +972,7 @@ internal fun <D : KtNamedDeclaration> placeDeclarationInContainer(
|
||||
val newLine = psiFactory.createNewLine()
|
||||
|
||||
fun calcNecessaryEmptyLines(decl: KtDeclaration, after: Boolean): Int {
|
||||
var lineBreaksPresent: Int = 0
|
||||
var lineBreaksPresent = 0
|
||||
var neighbor: PsiElement? = null
|
||||
|
||||
siblingsLoop@
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ internal class TypeParameterListExpression(private val mandatoryTypeParameters:
|
||||
currentTypeParameters = sortedRenderedTypeParameters.map { it.typeParameter }
|
||||
|
||||
return TextResult(
|
||||
if (sortedRenderedTypeParameters.isEmpty()) "" else sortedRenderedTypeParameters.map { it.text }.joinToString(", ", prefix, ">")
|
||||
if (sortedRenderedTypeParameters.isEmpty()) "" else sortedRenderedTypeParameters.joinToString(", ", prefix, ">") { it.text }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -89,9 +89,9 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration)
|
||||
private data class JsNativeAnnotations(val annotations: List<KtAnnotationEntry>, val nativeAnnotation: KtAnnotationEntry?, val isGetter: Boolean, val isSetter: Boolean, val isInvoke: Boolean)
|
||||
|
||||
private fun fetchJsNativeAnnotations(declaration: KtNamedDeclaration) : JsNativeAnnotations {
|
||||
var isGetter: Boolean = false
|
||||
var isSetter: Boolean = false
|
||||
var isInvoke: Boolean = false
|
||||
var isGetter = false
|
||||
var isSetter = false
|
||||
var isInvoke = false
|
||||
var nativeAnnotation: KtAnnotationEntry? = null
|
||||
val nativeAnnotations = ArrayList<KtAnnotationEntry>()
|
||||
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class ReplaceProtectedToPublishedApiCallFix(
|
||||
KtPsiFactory(classOwner).createFunction(
|
||||
"@kotlin.PublishedApi\n" +
|
||||
"internal " + newSignature +
|
||||
" = $originalName(${paramNames.keys.map { it }.joinToString(", ")})"
|
||||
" = $originalName(${paramNames.keys.joinToString(", ") { it }})"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -75,9 +75,9 @@ abstract class CallableRefactoring<out T: CallableDescriptor>(
|
||||
private fun showSuperFunctionWarningDialog(superCallables: Collection<CallableDescriptor>,
|
||||
callableFromEditor: CallableDescriptor,
|
||||
options: List<String>): Int {
|
||||
val superString = superCallables.map {
|
||||
val superString = superCallables.joinToString(prefix = "\n ", separator = ",\n ", postfix = ".\n\n") {
|
||||
it.containingDeclaration.name.asString()
|
||||
}.joinToString(prefix = "\n ", separator = ",\n ", postfix = ".\n\n")
|
||||
}
|
||||
val message = KotlinBundle.message("x.overrides.y.in.class.list",
|
||||
DescriptorRenderer.COMPACT.render(callableFromEditor),
|
||||
callableFromEditor.containingDeclaration.name.asString(), superString,
|
||||
|
||||
@@ -288,9 +288,9 @@ open class KotlinChangeInfo(
|
||||
return signatureParameters[0].getDeclarationSignature(0, inheritedCallable).text
|
||||
}
|
||||
|
||||
return signatureParameters.indices
|
||||
.map { i -> signatureParameters[i].getDeclarationSignature(i, inheritedCallable).text }
|
||||
.joinToString(separator = ", ")
|
||||
return signatureParameters.indices.joinToString(separator = ", ") { i ->
|
||||
signatureParameters[i].getDeclarationSignature(i, inheritedCallable).text
|
||||
}
|
||||
}
|
||||
|
||||
fun renderReceiverType(inheritedCallable: KotlinCallableDefinitionUsage<*>): String? {
|
||||
|
||||
+2
-2
@@ -148,8 +148,8 @@ class KotlinChangeSignatureDialog(
|
||||
override fun isListTableViewSupported() = true
|
||||
|
||||
override fun isEmptyRow(row: ParameterTableModelItemBase<KotlinParameterInfo>): Boolean {
|
||||
if (!row.parameter.name.isNullOrEmpty()) return false
|
||||
if (!row.parameter.typeText.isNullOrEmpty()) return false
|
||||
if (!row.parameter.name.isEmpty()) return false
|
||||
if (!row.parameter.typeText.isEmpty()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ internal var KtSimpleNameExpression.internalUsageInfos: MutableMap<FqName, (KtSi
|
||||
|
||||
internal fun preProcessInternalUsages(element: KtElement, usages: Collection<KtElement>) {
|
||||
val mainFile = element.containingKtFile
|
||||
val targetPackages = usages.mapNotNullTo(LinkedHashSet()) { it.containingKtFile.packageFqName }
|
||||
val targetPackages = usages.mapTo(LinkedHashSet()) { it.containingKtFile.packageFqName }
|
||||
for (targetPackage in targetPackages) {
|
||||
if (targetPackage == mainFile.packageFqName) continue
|
||||
val packageNameInfo = ContainerChangeInfo(ContainerInfo.Package(mainFile.packageFqName), ContainerInfo.Package(targetPackage))
|
||||
|
||||
+1
-1
@@ -245,7 +245,7 @@ class ExtractSuperRefactoring(
|
||||
}
|
||||
|
||||
if (typeParameters.isNotEmpty()) {
|
||||
val typeParameterListText = typeParameters.sortedBy { it.startOffset }.map { it.text }.joinToString(prefix = "<", postfix = ">")
|
||||
val typeParameterListText = typeParameters.sortedBy { it.startOffset }.joinToString(prefix = "<", postfix = ">") { it.text }
|
||||
newClass.addAfter(psiFactory.createTypeParameterList(typeParameterListText), newClass.nameIdentifier)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -541,7 +541,7 @@ class AnalysisResult (
|
||||
}
|
||||
)
|
||||
|
||||
return additionalInfo?.let { "$message\n\n${it.map { StringUtil.htmlEmphasize(it) }.joinToString("\n")}" } ?: message
|
||||
return additionalInfo?.let { "$message\n\n${it.joinToString("\n") { StringUtil.htmlEmphasize(it) }}" } ?: message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ class ExtractionEngine(
|
||||
}
|
||||
}
|
||||
|
||||
val message = analysisResult.messages.map { it.renderMessage() }.joinToString("\n")
|
||||
val message = analysisResult.messages.joinToString("\n") { it.renderMessage() }
|
||||
when (analysisResult.status) {
|
||||
AnalysisResult.Status.CRITICAL_ERROR -> {
|
||||
showErrorHint(project, editor, message, helper.operationName)
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class KotlinInplaceParameterIntroducer(
|
||||
null,
|
||||
originalDescriptor.originalRange.elements.single() as KtExpression,
|
||||
originalDescriptor.occurrencesToReplace
|
||||
.mapNotNull { it.elements.single() as KtExpression }
|
||||
.map { it.elements.single() as KtExpression }
|
||||
.toTypedArray(),
|
||||
INTRODUCE_PARAMETER,
|
||||
project,
|
||||
|
||||
+1
-3
@@ -281,9 +281,7 @@ class KotlinIntroduceParameterDialog private constructor(
|
||||
val function = declaration as KtFunction
|
||||
val receiverType = function.receiverTypeReference?.text
|
||||
val parameterTypes = function
|
||||
.valueParameters
|
||||
.map { it.typeReference!!.text }
|
||||
.joinToString()
|
||||
.valueParameters.joinToString { it.typeReference!!.text }
|
||||
val returnType = function.typeReference?.text ?: "Unit"
|
||||
|
||||
chosenType = (receiverType?.let { "$it." } ?: "") + "($parameterTypes) -> $returnType"
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class KotlinIntroducePropertyHandler(
|
||||
): RefactoringActionHandler {
|
||||
object InteractiveExtractionHelper : ExtractionEngineHelper(INTRODUCE_PROPERTY) {
|
||||
private fun getExtractionTarget(descriptor: ExtractableCodeDescriptor) =
|
||||
propertyTargets.filter { it.isAvailable(descriptor) }.firstOrNull()
|
||||
propertyTargets.firstOrNull { it.isAvailable(descriptor) }
|
||||
|
||||
override fun validate(descriptor: ExtractableCodeDescriptor) =
|
||||
descriptor.validate(getExtractionTarget(descriptor) ?: ExtractionTarget.FUNCTION)
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ object KotlinIntroduceTypeParameterHandler : RefactoringActionHandler {
|
||||
restoredOriginalTypeElement.textRange.intersects(textRange)
|
||||
|| restoredOwner.typeParameterList?.textRange?.intersects(textRange) ?: false
|
||||
}
|
||||
.mapNotNull { it.range.elements.toRange() }
|
||||
.map { it.range.elements.toRange() }
|
||||
|
||||
restoredOriginalTypeElement.replace(parameterRefElement)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user