Code cleanup: several inspections applied
This commit is contained in:
committed by
Mikhail Glukhikh
parent
fdca96634e
commit
840847e47c
@@ -27,7 +27,7 @@ interface ICReporter {
|
||||
fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {}
|
||||
|
||||
fun pathsAsString(files: Iterable<File>): String =
|
||||
files.map { it.canonicalPath }.joinToString()
|
||||
files.joinToString { it.canonicalPath }
|
||||
|
||||
fun pathsAsString(vararg files: File): String =
|
||||
pathsAsString(files.toList())
|
||||
|
||||
@@ -41,9 +41,7 @@ import java.util.*
|
||||
|
||||
|
||||
fun Iterable<File>.javaSourceRoots(roots: Iterable<File>): Iterable<File> =
|
||||
filter(File::isJavaFile)
|
||||
.map { findSrcDirRoot(it, roots) }
|
||||
.filterNotNull()
|
||||
filter(File::isJavaFile).mapNotNull { findSrcDirRoot(it, roots) }
|
||||
|
||||
fun makeModuleFile(name: String, isTest: Boolean, outputDir: File, sourcesToCompile: Iterable<File>, javaSourceRoots: Iterable<File>, classpath: Iterable<File>, friendDirs: Iterable<File>): File {
|
||||
val builder = KotlinModuleXmlBuilder()
|
||||
@@ -166,7 +164,7 @@ fun<Target> OutputItemsCollectorImpl.generatedFiles(
|
||||
return outputs.map { outputItem ->
|
||||
val target =
|
||||
outputItem.sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?:
|
||||
targets.filter { getOutputDir(it)?.let { outputItem.outputFile.startsWith(it) } ?: false }.singleOrNull() ?:
|
||||
targets.singleOrNull { getOutputDir(it)?.let { outputItem.outputFile.startsWith(it) } ?: false } ?:
|
||||
representativeTarget
|
||||
|
||||
when (outputItem.outputFile.extension) {
|
||||
|
||||
@@ -42,5 +42,5 @@ open class BasicMapsOwner {
|
||||
maps.forEach { it.flush(memoryCachesOnly) }
|
||||
}
|
||||
|
||||
@TestOnly fun dump(): String = maps.map { it.dump() }.joinToString("\n\n")
|
||||
@TestOnly fun dump(): String = maps.joinToString("\n\n") { it.dump() }
|
||||
}
|
||||
@@ -158,7 +158,7 @@ object CodegenUtil {
|
||||
@JvmStatic
|
||||
fun constructFakeFunctionCall(project: Project, referencedFunction: FunctionDescriptor): KtCallExpression {
|
||||
val fakeFunctionCall = StringBuilder("callableReferenceFakeCall(")
|
||||
fakeFunctionCall.append(referencedFunction.valueParameters.map { "p${it.index}" }.joinToString(", "))
|
||||
fakeFunctionCall.append(referencedFunction.valueParameters.joinToString(", ") { "p${it.index}" })
|
||||
fakeFunctionCall.append(")")
|
||||
return KtPsiFactory(project, markGenerated = false).createExpression(fakeFunctionCall.toString()) as KtCallExpression
|
||||
}
|
||||
|
||||
@@ -243,8 +243,9 @@ fun reportTarget6InheritanceErrorIfNeeded(
|
||||
state.diagnostics.report(
|
||||
ErrorsJvm.TARGET6_INTERFACE_INHERITANCE.on(
|
||||
classElement, classDescriptor, key,
|
||||
value.map { Renderers.COMPACT.render(JvmCodegenUtil.getDirectMember(it), RenderingContext.Empty) }.
|
||||
joinToString(separator = "\n", prefix = "\n")
|
||||
value.joinToString(separator = "\n", prefix = "\n") {
|
||||
Renderers.COMPACT.render(JvmCodegenUtil.getDirectMember(it), RenderingContext.Empty)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class CoroutineCodegenForLambda private constructor(
|
||||
if (allFunctionParameters().size <= 1) {
|
||||
val delegate = typeMapper.mapSignatureSkipGeneric(createCoroutineDescriptor).asmMethod
|
||||
|
||||
val bridgeParameters = (1..delegate.argumentTypes.size - 1).map { AsmTypes.OBJECT_TYPE } + delegate.argumentTypes.last()
|
||||
val bridgeParameters = (1 until delegate.argumentTypes.size).map { AsmTypes.OBJECT_TYPE } + delegate.argumentTypes.last()
|
||||
val bridge = Method(delegate.name, delegate.returnType, bridgeParameters.toTypedArray())
|
||||
|
||||
generateBridge(bridge, delegate)
|
||||
@@ -288,7 +288,7 @@ class CoroutineCodegenForLambda private constructor(
|
||||
|
||||
private fun allFunctionParameters() =
|
||||
originalSuspendFunctionDescriptor.extensionReceiverParameter.let(::listOfNotNull) +
|
||||
originalSuspendFunctionDescriptor.valueParameters.orEmpty()
|
||||
originalSuspendFunctionDescriptor.valueParameters
|
||||
|
||||
private fun ParameterDescriptor.getFieldInfoForCoroutineLambdaParameter() =
|
||||
createHiddenFieldInfo(type, COROUTINE_LAMBDA_PARAMETER_PREFIX + (this.safeAs<ValueParameterDescriptor>()?.index ?: ""))
|
||||
|
||||
@@ -51,7 +51,7 @@ internal fun ClassLoader.listAllUrlsAsFiles(): List<File> {
|
||||
}
|
||||
|
||||
internal fun URLClassLoader.listLocalUrlsAsFiles(): List<File> {
|
||||
return this.urLs.map { it.toString().removePrefix("file:") }.filterNotNull().map(::File)
|
||||
return this.urLs.mapNotNull { it.toString().removePrefix("file:") }.map(::File)
|
||||
}
|
||||
|
||||
internal fun <T : Any> List<T>.ensureNotEmpty(error: String): List<T> {
|
||||
|
||||
@@ -74,7 +74,7 @@ private fun inlineAccessorsJvmNames(properties: List<ProtoBuf.Property>, nameRes
|
||||
}
|
||||
}
|
||||
|
||||
return inlineAccessors.mapNotNull {
|
||||
return inlineAccessors.map {
|
||||
nameResolver.getString(it.name) + nameResolver.getString(it.desc)
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class NondeterministicJumpInstruction(
|
||||
|
||||
override fun toString(): String {
|
||||
val inVal = if (inputValue != null) "|$inputValue" else ""
|
||||
val labels = targetLabels.map { it.name }.joinToString(", ")
|
||||
val labels = targetLabels.joinToString(", ") { it.name }
|
||||
return "jmp?($labels$inVal)"
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
|
||||
|
||||
fun render(element: KtElementImplStub<*>, vararg relevantChildren: KtElement?): String? {
|
||||
if (element.stub == null) return element.text
|
||||
return relevantChildren.filterNotNull().map { it.getDebugText() }.joinToString("", "", "")
|
||||
return relevantChildren.filterNotNull().joinToString("", "", "") { it.getDebugText() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ private val SUPPORTED_ARGUMENT_TYPES = listOf(
|
||||
fun <TElement : KtElement> createByPattern(pattern: String, vararg args: Any, reformat: Boolean = true, factory: (String) -> TElement): TElement {
|
||||
val argumentTypes = args.map { arg ->
|
||||
SUPPORTED_ARGUMENT_TYPES.firstOrNull { it.klass.isInstance(arg) }
|
||||
?: throw IllegalArgumentException("Unsupported argument type: ${arg::class.java}, should be one of: ${SUPPORTED_ARGUMENT_TYPES.map { it.klass.simpleName }.joinToString()}")
|
||||
?: throw IllegalArgumentException("Unsupported argument type: ${arg::class.java}, should be one of: ${SUPPORTED_ARGUMENT_TYPES.joinToString { it.klass.simpleName }}")
|
||||
}
|
||||
|
||||
// convert arguments that can be converted into plain text
|
||||
|
||||
@@ -33,7 +33,7 @@ val STUB_TO_STRING_PREFIX = "KotlinStub$"
|
||||
open class KotlinStubBaseImpl<T : KtElementImplStub<*>>(parent: StubElement<*>?, elementType: IStubElementType<*, *>) : StubBase<T>(parent, elementType) {
|
||||
|
||||
override fun toString(): String {
|
||||
val stubInterface = this::class.java.interfaces.filter { it.name.contains("Stub") }.single()
|
||||
val stubInterface = this::class.java.interfaces.single { it.name.contains("Stub") }
|
||||
val propertiesValues = renderPropertyValues(stubInterface)
|
||||
if (propertiesValues.isEmpty()) {
|
||||
return "$STUB_TO_STRING_PREFIX$stubType"
|
||||
|
||||
@@ -377,7 +377,7 @@ class CallCompleter(
|
||||
expression = deparenthesizeOrGetSelector(expression)
|
||||
}
|
||||
|
||||
var shouldBeMadeNullable: Boolean = false
|
||||
var shouldBeMadeNullable = false
|
||||
expressions.asReversed().forEach { expression ->
|
||||
if (!(expression is KtParenthesizedExpression || expression is KtLabeledExpression || expression is KtAnnotatedExpression)) {
|
||||
shouldBeMadeNullable = hasNecessarySafeCall(expression, trace)
|
||||
|
||||
+3
-3
@@ -198,12 +198,12 @@ class NewResolutionOldInference(
|
||||
tracing: TracingStrategy,
|
||||
candidates: Collection<ResolutionCandidate<D>>
|
||||
): OverloadResolutionResultsImpl<D> {
|
||||
val resolvedCandidates = candidates.mapNotNull { candidate ->
|
||||
val resolvedCandidates = candidates.map { candidate ->
|
||||
val candidateTrace = TemporaryBindingTrace.create(basicCallContext.trace, "Context for resolve candidate")
|
||||
val resolvedCall = ResolvedCallImpl.create(candidate, candidateTrace, tracing, basicCallContext.dataFlowInfoForArguments)
|
||||
|
||||
if (candidate.descriptor.isHiddenInResolution(languageVersionSettings, basicCallContext.isSuperCall)) {
|
||||
return@mapNotNull MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), resolvedCall)
|
||||
return@map MyCandidate(ResolutionCandidateStatus(listOf(HiddenDescriptor)), resolvedCall)
|
||||
}
|
||||
|
||||
val callCandidateResolutionContext = CallCandidateResolutionContext.create(
|
||||
@@ -238,7 +238,7 @@ class NewResolutionOldInference(
|
||||
basicCallContext: BasicCallResolutionContext,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): OverloadResolutionResultsImpl<D> {
|
||||
val resolvedCalls = candidates.mapNotNull {
|
||||
val resolvedCalls = candidates.map {
|
||||
val (status, resolvedCall) = it
|
||||
if (resolvedCall is VariableAsFunctionResolvedCallImpl) {
|
||||
// todo hacks
|
||||
|
||||
+1
-1
@@ -295,7 +295,7 @@ class IncrementalJvmCompilerRunner(
|
||||
// todo: more optimal to save only last iteration, but it will require adding standalone-ic specific logs
|
||||
// (because jps rebuilds all files from last build if it failed and gradle rebuilds everything)
|
||||
allSourcesToCompile.addAll(sourcesToCompile)
|
||||
val text = allSourcesToCompile.map { it.canonicalPath }.joinToString(separator = System.getProperty("line.separator"))
|
||||
val text = allSourcesToCompile.joinToString(separator = System.getProperty("line.separator")) { it.canonicalPath }
|
||||
dirtySourcesSinceLastTimeFile.writeText(text)
|
||||
|
||||
val compilerOutput = compileChanged(listOf(targetId), sourcesToCompile.toSet(), args, { caches.incrementalCache }, lookupTracker, messageCollector)
|
||||
|
||||
+1
-2
@@ -239,8 +239,7 @@ class LocalFunctionsLowering(val context: BackendContext): DeclarationContainerL
|
||||
functionDescriptor.parentsWithSelf
|
||||
.takeWhile { it is FunctionDescriptor }
|
||||
.toList().reversed()
|
||||
.map { suggestLocalName(it) }
|
||||
.joinToString(separator = "$")
|
||||
.joinToString(separator = "$") { suggestLocalName(it) }
|
||||
)
|
||||
|
||||
private fun createTransformedDescriptor(localFunctionContext: LocalFunctionContext): FunctionDescriptor {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ abstract class ClassLowerWithContext : FileLoweringPass, IrElementTransformer<Ir
|
||||
private val irClass2Context = hashMapOf<IrClass, IrClassContext>()
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
val packageIr = irFile.declarations.filter { it.descriptor is FileClassDescriptor }.singleOrNull()
|
||||
val packageIr = irFile.declarations.singleOrNull { it.descriptor is FileClassDescriptor }
|
||||
if (packageIr != null) {
|
||||
visitClass(packageIr as IrClass, null)
|
||||
irFile.declarations.filterNot { it == packageIr }.forEach { it.accept(this, irClass2Context[packageIr]!!) }
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
|
||||
|
||||
val members = defaultImplsIrClass.declarations
|
||||
|
||||
irClass.declarations.filterIsInstance<IrFunction>().mapNotNull {
|
||||
irClass.declarations.filterIsInstance<IrFunction>().forEach {
|
||||
val descriptor = it.descriptor
|
||||
if (descriptor.modality != Modality.ABSTRACT) {
|
||||
val functionDescriptorImpl = createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper)
|
||||
|
||||
@@ -80,7 +80,7 @@ class MockKotlinClassifier(override val fqName: FqName,
|
||||
|
||||
override val supertypes: Collection<JavaClassifierType>
|
||||
get() = classOrObject.superTypeListEntries
|
||||
.mapNotNull { superTypeListEntry ->
|
||||
.map { superTypeListEntry ->
|
||||
val userType = superTypeListEntry.typeAsUserType
|
||||
arrayListOf<String>().apply {
|
||||
userType?.referencedName?.let { add(it) }
|
||||
|
||||
+2
-2
@@ -45,12 +45,12 @@ class TreeBasedTypeParameter(
|
||||
get() = false
|
||||
|
||||
override val upperBounds: Collection<JavaClassifierType>
|
||||
get() = tree.bounds.map {
|
||||
get() = tree.bounds.mapNotNull {
|
||||
when (it) {
|
||||
is JCTree.JCTypeApply -> TreeBasedGenericClassifierType(it, TreePath(treePath, it), javac)
|
||||
is JCTree.JCIdent -> TreeBasedNonGenericClassifierType(it, TreePath(treePath, it), javac)
|
||||
else -> null
|
||||
}
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
}
|
||||
+3
-4
@@ -147,12 +147,11 @@ class OverloadingConflictResolver<C : Any>(
|
||||
candidates.firstOrNull()
|
||||
else when (checkArgumentsMode) {
|
||||
CheckArgumentTypesMode.CHECK_CALLABLE_TYPE ->
|
||||
uniquifyCandidatesSet(candidates).filter {
|
||||
isDefinitelyMostSpecific(it, candidates) {
|
||||
call1, call2 ->
|
||||
uniquifyCandidatesSet(candidates).singleOrNull {
|
||||
isDefinitelyMostSpecific(it, candidates) { call1, call2 ->
|
||||
isNotLessSpecificCallableReference(call1.resultingDescriptor, call2.resultingDescriptor)
|
||||
}
|
||||
}.singleOrNull()
|
||||
}
|
||||
|
||||
CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS ->
|
||||
findMaximallySpecificCall(candidates, discriminateGenerics, isDebuggerContext)
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType
|
||||
|
||||
val lowerArgs = renderArguments(lowerBound)
|
||||
val upperArgs = renderArguments(upperBound)
|
||||
val newArgs = lowerArgs.map { "(raw) $it" }.joinToString(", ")
|
||||
val newArgs = lowerArgs.joinToString(", ") { "(raw) $it" }
|
||||
val newUpper =
|
||||
if (lowerArgs.zip(upperArgs).all { onlyOutDiffers(it.first, it.second) })
|
||||
upperRendered.replaceArgs(newArgs)
|
||||
|
||||
@@ -290,7 +290,7 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendTypeProjections(typeProjections: List<TypeProjection>) {
|
||||
typeProjections.map {
|
||||
typeProjections.joinTo(this, ", ") {
|
||||
if (it.isStarProjection) {
|
||||
"*"
|
||||
}
|
||||
@@ -298,7 +298,7 @@ internal class DescriptorRendererImpl(
|
||||
val type = renderType(it.type)
|
||||
if (it.projectionKind == Variance.INVARIANT) type else "${it.projectionKind} $type"
|
||||
}
|
||||
}.joinTo(this, ", ")
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.renderFunctionType(type: KotlinType) {
|
||||
@@ -454,7 +454,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderConstant(value: ConstantValue<*>): String {
|
||||
return when (value) {
|
||||
is ArrayValue -> value.value.map { renderConstant(it) }.joinToString(", ", "{", "}")
|
||||
is ArrayValue -> value.value.joinToString(", ", "{", "}") { renderConstant(it) }
|
||||
is AnnotationValue -> renderAnnotation(value.value).removePrefix("@")
|
||||
is KClassValue -> renderType(value.value) + "::class"
|
||||
else -> value.toString()
|
||||
@@ -975,8 +975,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
renderSpaceIfNeeded(builder)
|
||||
builder.append(": ")
|
||||
supertypes.map { renderType(it) }
|
||||
.joinTo(builder, ", ")
|
||||
supertypes.joinTo(builder, ", ") { renderType(it) }
|
||||
}
|
||||
|
||||
private fun renderClassKindPrefix(klass: ClassDescriptor, builder: StringBuilder) {
|
||||
|
||||
+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)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.j2k.ast.*
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
fun quoteKeywords(packageName: String): String = packageName.split('.').map { Identifier.toKotlin(it) }.joinToString(".")
|
||||
fun quoteKeywords(packageName: String): String = packageName.split('.').joinToString(".") { Identifier.toKotlin(it) }
|
||||
|
||||
fun getDefaultInitializer(property: Property): Expression? {
|
||||
val t = property.type
|
||||
|
||||
@@ -46,8 +46,7 @@ class Modifiers(modifiers: Collection<Modifier>) : Element() {
|
||||
modifiers.filter { it != Modifier.PUBLIC }
|
||||
val text = modifiersToInclude
|
||||
.sortedBy { it.ordinal }
|
||||
.map { it.toKotlin() }
|
||||
.joinToString(" ")
|
||||
.joinToString(" ") { it.toKotlin() }
|
||||
builder.append(text)
|
||||
}
|
||||
|
||||
|
||||
@@ -507,7 +507,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
val outputFile = outputItem.outputFile
|
||||
val target =
|
||||
sourceFiles.firstOrNull()?.let { sourceToTarget[it] } ?:
|
||||
chunk.targets.filter { it.outputDir?.let { outputFile.startsWith(it) } ?: false }.singleOrNull() ?:
|
||||
chunk.targets.singleOrNull { it.outputDir?.let { outputFile.startsWith(it) } ?: false } ?:
|
||||
representativeTarget
|
||||
|
||||
if (outputFile.name.endsWith(".class")) {
|
||||
@@ -642,7 +642,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
environment.messageCollector.report(
|
||||
STRONG_WARNING,
|
||||
"Circular dependencies are not supported. The following JS modules depend on each other: "
|
||||
+ chunk.modules.map { it.name }.joinToString(", ") + ". "
|
||||
+ chunk.modules.joinToString(", ") { it.name } + ". "
|
||||
+ "Kotlin is not compiled for these modules"
|
||||
)
|
||||
return null
|
||||
@@ -700,7 +700,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
environment.messageCollector.report(
|
||||
STRONG_WARNING,
|
||||
"Circular dependencies are only partially supported. The following modules depend on each other: "
|
||||
+ chunk.modules.map { it.name }.joinToString(", ") + ". "
|
||||
+ chunk.modules.joinToString(", ") { it.name } + ". "
|
||||
+ "Kotlin will compile them, but some strange effect may happen"
|
||||
)
|
||||
}
|
||||
|
||||
+1
-2
@@ -55,8 +55,7 @@ private class UnusedInstanceCollector : JsVisitorWithContextImpl() {
|
||||
tracker.addCandidateForRemoval(name, currentStatement!!)
|
||||
|
||||
val references = collectUsedNames(x)
|
||||
references.filterNotNull()
|
||||
.forEach { tracker.addRemovableReference(name, it) }
|
||||
references.forEach { tracker.addRemovableReference(name, it) }
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
+2
-4
@@ -157,8 +157,7 @@ class ClassModelGenerator(val context: StaticContext) {
|
||||
// When none found, we have nothing to copy, ignore.
|
||||
// When multiple found, our current class should provide implementation, ignore.
|
||||
val memberToCopy = member.findNonRepeatingOverriddenDescriptors({ overriddenDescriptors }, { original })
|
||||
.filter { it.modality != Modality.ABSTRACT }
|
||||
.singleOrNull() ?: return null
|
||||
.singleOrNull { it.modality != Modality.ABSTRACT } ?: return null
|
||||
|
||||
// If found member is not from interface, we don't need to copy it, it's already in prototype
|
||||
if ((memberToCopy.containingDeclaration as ClassDescriptor).kind != ClassKind.INTERFACE) return null
|
||||
@@ -172,8 +171,7 @@ class ClassModelGenerator(val context: StaticContext) {
|
||||
// When non found, we have nothing to copy, ignore.
|
||||
// When multiple found, our current class should provide implementation, ignore.
|
||||
val memberToCopy = member.findNonRepeatingOverriddenDescriptors({ overriddenDescriptors }, { original })
|
||||
.filter { it.hasOrInheritsParametersWithDefaultValue() }
|
||||
.singleOrNull() ?: return null
|
||||
.singleOrNull { it.hasOrInheritsParametersWithDefaultValue() } ?: return null
|
||||
|
||||
// If found member is not from interface, we don't need to copy it, it's already in prototype
|
||||
if ((memberToCopy.containingDeclaration as ClassDescriptor).kind != ClassKind.INTERFACE) return null
|
||||
|
||||
+1
-1
@@ -260,7 +260,7 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
log { "Saving incremental data: ${analyzedClasses.size} class names" }
|
||||
try {
|
||||
incrementalDataFile.parentFile.mkdirs()
|
||||
incrementalDataFile.writeText(analyzedClasses.map { "i $it" }.joinToString(LINE_SEPARATOR))
|
||||
incrementalDataFile.writeText(analyzedClasses.joinToString(LINE_SEPARATOR) { "i $it" })
|
||||
}
|
||||
catch (e: IOException) {
|
||||
log { "Unable to write $incrementalDataFile" }
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ class DefaultJeElementRenderer : JeElementRenderer {
|
||||
return if (modifiers.isEmpty())
|
||||
renderedAnnotations
|
||||
else
|
||||
renderedAnnotations + modifiers.map { it.name.toLowerCase() }.joinToString(" ", postfix = " ")
|
||||
renderedAnnotations + modifiers.joinToString(" ", postfix = " ") { it.name.toLowerCase() }
|
||||
}
|
||||
|
||||
private fun renderAnnotations(element: Element): String {
|
||||
@@ -111,7 +111,7 @@ class DefaultJeElementRenderer : JeElementRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.withMargin() = lines().map { MARGIN + it }.joinToString(LINE_SEPARATOR)
|
||||
private fun String.withMargin() = lines().joinToString(LINE_SEPARATOR) { MARGIN + it }
|
||||
|
||||
private companion object {
|
||||
val MARGIN = " "
|
||||
|
||||
Reference in New Issue
Block a user