Replace map { ... }.filterNotNull() with mapNotNull { ... }
This commit is contained in:
@@ -85,7 +85,7 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
|
||||
val extensionReceiverType = fuzzyExtensionReceiverType()!!
|
||||
val substitutors = types
|
||||
.map {
|
||||
.mapNotNull {
|
||||
var substitutor = extensionReceiverType.checkIsSuperTypeOf(it)
|
||||
// check if we may fail due to receiver expression being nullable
|
||||
if (substitutor == null && it.nullability() == TypeNullability.NULLABLE && extensionReceiverType.nullability() == TypeNullability.NOT_NULL) {
|
||||
@@ -93,7 +93,6 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
}
|
||||
substitutor
|
||||
}
|
||||
.filterNotNull()
|
||||
if (getTypeParameters().isEmpty()) { // optimization for non-generic callables
|
||||
return if (substitutors.any()) listOf(this) else listOf()
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ class PartialBodyResolveFilter(
|
||||
else {
|
||||
val leftName = left.smartCastExpressionName()
|
||||
val rightName = right.smartCastExpressionName()
|
||||
val names = listOf(leftName, rightName).filterNotNull().toSet()
|
||||
val names = listOfNotNull(leftName, rightName).toSet()
|
||||
return Pair(names, setOf())
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -138,9 +138,9 @@ public class CodeFragmentAnalyzer(
|
||||
return scopeForContextElement to dataFlowInfo
|
||||
}
|
||||
|
||||
val importScopes = importList.imports.map {
|
||||
val importScopes = importList.imports.mapNotNull {
|
||||
qualifierResolver.processImportReference(it, resolveSession.moduleDescriptor, resolveSession.trace, null)
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
return scopeForContextElement.addImportingScopes(importScopes) to dataFlowInfo
|
||||
}
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return withFakeLightClasses(lightClassForFacade, facadeFiles)
|
||||
}
|
||||
else {
|
||||
return facadeFiles.filter { it.isCompiled }.map { createLightClassForDecompiledKotlinFile(it) }.filterNotNull()
|
||||
return facadeFiles.filter { it.isCompiled }.mapNotNull { createLightClassForDecompiledKotlinFile(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ public object JsAnalyzerFacade : AnalyzerFacade<PlatformAnalysisParameters>() {
|
||||
val providers = moduleInfo.library.getFiles(OrderRootType.CLASSES)
|
||||
.flatMap { KotlinJavascriptMetadataUtils.loadMetadata(PathUtil.getLocalPath(it)!!) }
|
||||
.filter { it.isAbiVersionCompatible }
|
||||
.map { KotlinJavascriptSerializationUtil.createPackageFragmentProvider(moduleDescriptor, it.body, moduleContext.storageManager) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { KotlinJavascriptSerializationUtil.createPackageFragmentProvider(moduleDescriptor, it.body, moduleContext.storageManager) }
|
||||
|
||||
if (providers.isNotEmpty()) {
|
||||
packageFragmentProvider = CompositePackageFragmentProvider(listOf(packageFragmentProvider) + providers)
|
||||
|
||||
+2
-2
@@ -177,9 +177,9 @@ public class KotlinCacheService(val project: Project) {
|
||||
return ResolutionFacadeImpl(projectFacade, file.getModuleInfo())
|
||||
}
|
||||
|
||||
private fun findSyntheticFiles(files: Collection<KtFile>) = files.map {
|
||||
private fun findSyntheticFiles(files: Collection<KtFile>) = files.mapNotNull {
|
||||
if (it is KtCodeFragment) it.getContextFile() else it
|
||||
}.filterNotNull().filter {
|
||||
}.filter {
|
||||
!ProjectRootsUtil.isInProjectSource(it)
|
||||
}.toSet()
|
||||
|
||||
|
||||
+3
-4
@@ -72,11 +72,10 @@ public fun KtElement.addToShorteningWaitSet(options: Options = Options.DEFAULT)
|
||||
public fun performDelayedShortening(project: Project) {
|
||||
project.elementsToShorten?.let { requests ->
|
||||
project.elementsToShorten = null
|
||||
val elements = requests.map { it.pointer.getElement() }
|
||||
val options = requests.map { it.options }
|
||||
val elementToOptions = (elements zip options).toMap()
|
||||
val elementToOptions = requests.mapNotNull { req -> req.pointer.element?.let { it to req.options } }.toMap()
|
||||
val elements = elementToOptions.keys
|
||||
//TODO: this is not correct because it should not shorten deep into the elements!
|
||||
ShortenReferences({ elementToOptions[it] ?: ShortenReferences.Options.DEFAULT }).process(elements.filterNotNull())
|
||||
ShortenReferences({ elementToOptions[it] ?: ShortenReferences.Options.DEFAULT }).process(elements)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public fun findMultifileClassParts(file: VirtualFile, multifileClass: KotlinJvmB
|
||||
val packageFqName = multifileClass.classId.packageFqName
|
||||
val partsFinder = DirectoryBasedClassFinder(file.parent!!, packageFqName)
|
||||
val partNames = multifileClass.classHeader.filePartClassNames ?: return emptyList()
|
||||
return partNames.map {
|
||||
return partNames.mapNotNull {
|
||||
partsFinder.findKotlinClass(ClassId(packageFqName, Name.identifier(it.substringAfterLast('/'))))
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -244,7 +244,7 @@ fun createModifierListStubForDeclaration(
|
||||
): KotlinModifierListStubImpl {
|
||||
assert(flagsToTranslate.isNotEmpty())
|
||||
|
||||
val modifiers = flagsToTranslate.map { it.getModifiers(flags) }.filterNotNull() + additionalModifiers
|
||||
val modifiers = flagsToTranslate.mapNotNull { it.getModifiers(flags) } + additionalModifiers
|
||||
return createModifierListStub(parent, modifiers)!!
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -70,7 +70,7 @@ public fun buildDecompiledText(
|
||||
classHeader.isCompatibleFileFacadeKind() ->
|
||||
buildDecompiledText(packageFqName, ArrayList(resolver.resolveDeclarationsInFacade(classId.asSingleFqName())))
|
||||
classHeader.isCompatibleClassKind() ->
|
||||
buildDecompiledText(packageFqName, listOf(resolver.resolveTopLevelClass(classId)).filterNotNull())
|
||||
buildDecompiledText(packageFqName, listOfNotNull(resolver.resolveTopLevelClass(classId)))
|
||||
classHeader.isCompatibleMultifileClassKind() -> {
|
||||
val partClasses = findMultifileClassParts(classFile, kotlinClass)
|
||||
val partMembers = partClasses.flatMap { partClass -> resolver.resolveDeclarationsInFacade(partClass.classId.asSingleFqName()) }
|
||||
@@ -95,7 +95,7 @@ public fun buildDecompiledTextFromJsMetadata(
|
||||
}
|
||||
else {
|
||||
val classId = JsMetaFileUtils.getClassId(classFile)
|
||||
return buildDecompiledText(packageFqName, listOf(resolver.resolveTopLevelClass(classId)).filterNotNull(), descriptorRendererForKotlinJavascriptDecompiler)
|
||||
return buildDecompiledText(packageFqName, listOfNotNull(resolver.resolveTopLevelClass(classId)), descriptorRendererForKotlinJavascriptDecompiler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,7 @@ public object IdeRenderers {
|
||||
data: ConflictingJvmDeclarationsData ->
|
||||
|
||||
val conflicts = data.signatureOrigins
|
||||
.map { it.descriptor }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.descriptor }
|
||||
.sortedWith(MemberComparator.INSTANCE)
|
||||
.joinToString("") { "<li>" + HTML_COMPACT_WITH_MODIFIERS.render(it) + "</li>\n" }
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class KtForLoopInReference(element: KtForExpression) : KtMultiReference<K
|
||||
if (loopRange == null) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
return LOOP_RANGE_KEYS.map { key -> context.get(key, loopRange)?.getCandidateDescriptor() }.filterNotNull()
|
||||
return LOOP_RANGE_KEYS.mapNotNull { key -> context.get(key, loopRange)?.getCandidateDescriptor() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
|
||||
class KtMultiDeclarationReference(element: KtMultiDeclaration) : KtMultiReference<KtMultiDeclaration>(element) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
return expression.getEntries().map { entry ->
|
||||
return expression.getEntries().mapNotNull { entry ->
|
||||
context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)?.getCandidateDescriptor()
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getRangeInElement(): TextRange? {
|
||||
|
||||
+2
-2
@@ -42,9 +42,9 @@ public class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) :
|
||||
if (descriptor !is PropertyDescriptor) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
return (descriptor.getAccessors().map {
|
||||
return (descriptor.getAccessors().mapNotNull {
|
||||
accessor ->
|
||||
context.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor)?.getCandidateDescriptor()
|
||||
} + listOf(context.get(BindingContext.DELEGATED_PROPERTY_PD_RESOLVED_CALL, descriptor)?.getCandidateDescriptor())).filterNotNull()
|
||||
} + listOfNotNull(context.get(BindingContext.DELEGATED_PROPERTY_PD_RESOLVED_CALL, descriptor)?.getCandidateDescriptor()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public val PsiReference.unwrappedTargets: Set<PsiElement>
|
||||
}
|
||||
|
||||
return when (this) {
|
||||
is PsiPolyVariantReference -> multiResolve(false).map { it.getElement()?.adjust() }.filterNotNullTo(HashSet<PsiElement>())
|
||||
is PsiPolyVariantReference -> multiResolve(false).mapNotNullTo(HashSet<PsiElement>()) { it.getElement()?.adjust() }
|
||||
else -> emptyOrSingletonList(resolve()?.adjust()).toSet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,8 +333,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
if (leaf is LineBreakTreeElement) return null
|
||||
return leaf.parentsWithSelf
|
||||
.takeWhile { it != lineBreakParent }
|
||||
.map { toNewPsiElementMap[it]?.first() } //TODO: what about multiple?
|
||||
.filterNotNull()
|
||||
.mapNotNull { toNewPsiElementMap[it]?.first() } //TODO: what about multiple?
|
||||
.firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -500,8 +500,7 @@ class BasicCompletionSession(
|
||||
val classOrObject = position.parents.firstIsInstanceOrNull<KtClassOrObject>() ?: return
|
||||
val classDescriptor = resolutionFacade.resolveToDescriptor(classOrObject) as ClassDescriptor
|
||||
var superClasses = classDescriptor.defaultType.constructor.supertypesWithAny()
|
||||
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
|
||||
if (callTypeAndReceiver.receiver != null) {
|
||||
val referenceVariantsSet = referenceVariants!!.imported.toSet()
|
||||
|
||||
@@ -281,16 +281,14 @@ abstract class CompletionSession(
|
||||
if (expectedInfos.isEmpty()) return null
|
||||
|
||||
var context = expectedInfos
|
||||
.map { it.fuzzyType?.type?.constructor?.declarationDescriptor?.importableFqName }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.fuzzyType?.type?.constructor?.declarationDescriptor?.importableFqName }
|
||||
.distinct()
|
||||
.singleOrNull()
|
||||
?.let { "expectedType=$it" }
|
||||
|
||||
if (context == null) {
|
||||
context = expectedInfos
|
||||
.map { it.expectedName }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.expectedName }
|
||||
.distinct()
|
||||
.singleOrNull()
|
||||
?.let { "expectedName=$it" }
|
||||
|
||||
@@ -211,8 +211,7 @@ class ExpectedInfos(
|
||||
val callExpression = (call.callElement as? KtExpression)?.getQualifiedExpressionForSelectorOrThis() ?: return results
|
||||
val expectedFuzzyTypes = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures, useOuterCallsExpectedTypeCount - 1)
|
||||
.calculate(callExpression)
|
||||
.map { it.fuzzyType }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.fuzzyType }
|
||||
if (expectedFuzzyTypes.isEmpty() || expectedFuzzyTypes.any { it.freeParameters.isNotEmpty() }) return results
|
||||
|
||||
return expectedFuzzyTypes
|
||||
@@ -469,8 +468,7 @@ class ExpectedInfos(
|
||||
if (functionLiteral != null) {
|
||||
val literalExpression = functionLiteral.parent as KtFunctionLiteralExpression
|
||||
return calculate(literalExpression)
|
||||
.map { it.fuzzyType }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.fuzzyType }
|
||||
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.type) }
|
||||
.map {
|
||||
val returnType = KotlinBuiltIns.getReturnTypeFromFunctionType(it.type)
|
||||
|
||||
+1
-2
@@ -68,13 +68,12 @@ class StaticMembersCompletion(
|
||||
fun membersFromImports(file: KtFile): Collection<DeclarationDescriptor> {
|
||||
val containers = file.importDirectives
|
||||
.filter { !it.isAllUnder }
|
||||
.map {
|
||||
.mapNotNull {
|
||||
it.targetDescriptors(resolutionFacade)
|
||||
.map { it.containingDeclaration }
|
||||
.distinct()
|
||||
.singleOrNull() as? ClassDescriptor
|
||||
}
|
||||
.filterNotNull()
|
||||
.toSet()
|
||||
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
|
||||
+1
-2
@@ -82,8 +82,7 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
|
||||
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures = false).calculate(expression)
|
||||
|
||||
val functionTypes = expectedInfos
|
||||
.map { it.fuzzyType?.type }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.fuzzyType?.type }
|
||||
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it) }
|
||||
.toSet()
|
||||
if (functionTypes.size() <= 1) return false
|
||||
|
||||
@@ -39,8 +39,7 @@ object LambdaItems {
|
||||
if (functionExpectedInfos.isEmpty()) return
|
||||
|
||||
val distinctTypes = functionExpectedInfos
|
||||
.map { it.fuzzyType?.type }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.fuzzyType?.type }
|
||||
.toSet()
|
||||
|
||||
val singleType = if (distinctTypes.size() == 1) distinctTypes.single() else null
|
||||
|
||||
+1
-2
@@ -32,8 +32,7 @@ object NameSimilarityWeigher : LookupElementWeigher("kotlin.nameSimilarity") {
|
||||
|
||||
fun calcNameSimilarity(name: String, expectedInfos: Collection<ExpectedInfo>): Int {
|
||||
return expectedInfos
|
||||
.map { it.expectedName }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.expectedName }
|
||||
.map { calcNameSimilarity(name, it) }
|
||||
.max() ?: 0
|
||||
}
|
||||
|
||||
+1
-2
@@ -363,8 +363,7 @@ class SmartCompletion(
|
||||
if (descriptor.modality != Modality.ABSTRACT && !descriptor.isInner) {
|
||||
descriptor.constructors
|
||||
.filter(visibilityFilter)
|
||||
.map { toLookupElement(it) }
|
||||
.filterNotNullTo(this)
|
||||
.mapNotNullTo(this) { toLookupElement(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ public class IterableTypesDetection(
|
||||
|
||||
private val typesWithExtensionIterator: Collection<KotlinType> = scope
|
||||
.collectFunctions(iteratorName, NoLookupLocation.FROM_IDE)
|
||||
.map { it.extensionReceiverParameter }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.extensionReceiverParameter }
|
||||
.map { it.type }
|
||||
|
||||
override fun isIterable(type: FuzzyType, loopVarType: KotlinType?): Boolean {
|
||||
|
||||
@@ -189,8 +189,7 @@ public class KotlinIndicesHelper(
|
||||
|
||||
public fun getJvmClassesByName(name: String): Collection<ClassDescriptor> {
|
||||
return PsiShortNamesCache.getInstance(project).getClassesByName(name, scope)
|
||||
.map { it.resolveToDescriptor(resolutionFacade) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.resolveToDescriptor(resolutionFacade) }
|
||||
.filter(descriptorFilter)
|
||||
.toSet()
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ public object KotlinNameSuggester {
|
||||
val result = LinkedHashSet<String>()
|
||||
|
||||
suggestNamesByExpressionOnly(collection, bindingContext, { true })
|
||||
.map { StringUtil.unpluralize(it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { StringUtil.unpluralize(it) }
|
||||
.mapTo(result) { suggestNameByName(it, validator) }
|
||||
|
||||
result.addNamesByType(elementType, validator)
|
||||
|
||||
@@ -47,8 +47,7 @@ public object OptionalParametersHelper {
|
||||
val descriptor = resolvedCall.getResultingDescriptor()
|
||||
|
||||
val parameterToDefaultValue = descriptor.getValueParameters()
|
||||
.map { parameter -> defaultParameterValue(parameter, project)?.let { parameter to it } }
|
||||
.filterNotNull()
|
||||
.mapNotNull { parameter -> defaultParameterValue(parameter, project)?.let { parameter to it } }
|
||||
.toMap()
|
||||
if (parameterToDefaultValue.isEmpty()) return emptyList()
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ public class KotlinJavaScriptLibraryManager private constructor(private var myPr
|
||||
|
||||
val changedFiles = events
|
||||
.filter { it !is MyVFileContentChangeEvent && it is VFileContentChangeEvent }
|
||||
.map { it.file }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.file }
|
||||
|
||||
val files = update(changedFiles, addToMapIfAbsent = false)
|
||||
val application = ApplicationManager.getApplication()
|
||||
|
||||
@@ -147,8 +147,7 @@ public class JavaToKotlinAction : AnAction() {
|
||||
val manager = PsiManager.getInstance(project)
|
||||
return allFiles(filesOrDirs)
|
||||
.asSequence()
|
||||
.map { manager.findFile(it) as? PsiJavaFile }
|
||||
.filterNotNull()
|
||||
.mapNotNull { manager.findFile(it) as? PsiJavaFile }
|
||||
}
|
||||
|
||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
|
||||
|
||||
return with(info) {
|
||||
val prototypes = if (superConstructors.isNotEmpty()) {
|
||||
superConstructors.map { generateConstructor(classDescriptor, propertiesToInitialize, it) }.filterNotNull()
|
||||
superConstructors.mapNotNull { generateConstructor(classDescriptor, propertiesToInitialize, it) }
|
||||
} else {
|
||||
generateConstructor(classDescriptor, propertiesToInitialize, null).singletonOrEmptyList()
|
||||
}
|
||||
|
||||
+1
-2
@@ -170,8 +170,7 @@ public class CheckPartialBodyResolveAction : AnAction() {
|
||||
val manager = PsiManager.getInstance(project)
|
||||
return allFiles(filesOrDirs)
|
||||
.asSequence()
|
||||
.map { manager.findFile(it) as? KtFile }
|
||||
.filterNotNull()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
}
|
||||
|
||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||
|
||||
@@ -156,8 +156,7 @@ public class FindImplicitNothingAction : AnAction() {
|
||||
val manager = PsiManager.getInstance(project)
|
||||
return allFiles(filesOrDirs)
|
||||
.asSequence()
|
||||
.map { manager.findFile(it) as? KtFile }
|
||||
.filterNotNull()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
}
|
||||
|
||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||
|
||||
@@ -202,13 +202,13 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
|
||||
if (file !is KtFile) return listOf()
|
||||
|
||||
val fileResolutionScope = file.getResolutionFacade().getFileResolutionScope(file)
|
||||
return referenceData.map {
|
||||
return referenceData.mapNotNull {
|
||||
val reference = findReference(it, file, blockStart)
|
||||
if (reference != null)
|
||||
createReferenceToRestoreData(reference, it, file, fileResolutionScope)
|
||||
else
|
||||
null
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun findReference(data: KotlinReferenceData, file: KtFile, blockStart: Int): KtReference? {
|
||||
@@ -250,8 +250,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
|
||||
}
|
||||
val referencedFqNames = referencedDescriptors
|
||||
.filterNot { ErrorUtils.isError(it) }
|
||||
.map { it.importableFqName }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.importableFqName }
|
||||
.toSet()
|
||||
if (referencedFqNames.singleOrNull() == originalFqName) return null
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class RuntimeLibraryFiles(
|
||||
val reflectJar: File?,
|
||||
val runtimeSourcesJar: File
|
||||
) {
|
||||
fun getAllJars(): List<File> = listOf(runtimeJar, reflectJar, runtimeSourcesJar).filterNotNull()
|
||||
fun getAllJars(): List<File> = listOfNotNull(runtimeJar, reflectJar, runtimeSourcesJar)
|
||||
|
||||
fun getRuntimeDestination(dirToCopyJar: String): File =
|
||||
File(dirToCopyJar + "/" + runtimeJar.name)
|
||||
|
||||
@@ -252,10 +252,10 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
|
||||
val lambdas = getLambdasAtLineIfAny(sourcePosition)
|
||||
val file = sourcePosition.file.containingFile as KtFile
|
||||
val isInLibrary = LibraryUtil.findLibraryEntry(file.virtualFile, file.project) != null
|
||||
lambdas.map {
|
||||
lambdas.mapNotNull {
|
||||
val typeMapper = if (!isInLibrary) prepareTypeMapper(file) else createTypeMapperForLibraryFile(it, file)
|
||||
getInternalClassNameForElement(it, typeMapper, file, isInLibrary).className
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,9 +327,9 @@ public class KotlinPositionManager(private val myDebugProcess: DebugProcess) : M
|
||||
throw NoDataException.INSTANCE
|
||||
}
|
||||
|
||||
return classNameForPositionAndInlinedOnes(position).map {
|
||||
return classNameForPositionAndInlinedOnes(position).mapNotNull {
|
||||
className -> myDebugProcess.requestsManager.createClassPrepareRequest(requestor, className.replace('/', '.'))
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class KotlinFieldBreakpointType : JavaBreakpointType<KotlinPropertyBreakp
|
||||
|
||||
result = when (psiClass) {
|
||||
is KtLightClassForFacade -> {
|
||||
psiClass.files.asSequence().map { createBreakpointIfPropertyExists(it, it, className, fieldName) }.filterNotNull().firstOrNull()
|
||||
psiClass.files.asSequence().mapNotNull { createBreakpointIfPropertyExists(it, it, className, fieldName) }.firstOrNull()
|
||||
}
|
||||
is KtLightClassForExplicitDeclaration -> {
|
||||
val jetClass = psiClass.getOrigin()
|
||||
|
||||
@@ -89,8 +89,7 @@ public class KotlinFindUsagesHandlerFactory(project: Project) : FindUsagesHandle
|
||||
assert(parameterIndex < parametersCount)
|
||||
val overridingParameters = OverridingMethodsSearch.search(psiMethod, true)
|
||||
.filter { it.parameterList.parametersCount == parametersCount }
|
||||
.map { it.parameterList.parameters[parameterIndex].unwrapped }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.parameterList.parameters[parameterIndex].unwrapped }
|
||||
return handlerForMultiple(element, listOf(element) + overridingParameters)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -169,7 +169,7 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
|
||||
object : IntentionWrapper(MarkHiddenAndDeprecatedAction(property), property.containingFile), LowPriorityAction {}
|
||||
else
|
||||
null
|
||||
listOf(fix1, fix2).filterNotNull().toTypedArray()
|
||||
listOfNotNull(fix1, fix2).toTypedArray()
|
||||
}
|
||||
else {
|
||||
emptyArray()
|
||||
@@ -196,8 +196,7 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
|
||||
val searchScope = KotlinSourceFilterScope.sources(GlobalSearchScope.projectScope(project), project)
|
||||
ReferencesSearch.search(declaration, searchScope)
|
||||
.filterIsInstance<KtSimpleNameReference>()
|
||||
.map { ref -> ref.expression.getStrictParentOfType<KtImportDirective>() }
|
||||
.filterNotNull()
|
||||
.mapNotNull { ref -> ref.expression.getStrictParentOfType<KtImportDirective>() }
|
||||
.filter { import -> !import.isAllUnder && import.targetDescriptors().size() == 1 }
|
||||
}
|
||||
UIUtil.invokeLaterIfNeeded {
|
||||
|
||||
@@ -63,8 +63,7 @@ class KotlinUnusedImportInspection : AbstractKotlinInspection() {
|
||||
val directives = file.importDirectives
|
||||
val explicitlyImportedFqNames = directives
|
||||
.asSequence()
|
||||
.map { it.importPath }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.importPath }
|
||||
.filter { !it.isAllUnder && !it.hasAlias() }
|
||||
.map { it.fqnPart() }
|
||||
.toSet()
|
||||
|
||||
@@ -106,8 +106,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
val annotationsPresent = annotated.getAnnotations()
|
||||
.map { it.getType() }
|
||||
.filter { !it.isError() }
|
||||
.map { it.getConstructor().getDeclarationDescriptor()?.let { DescriptorUtils.getFqName(it).asString() } }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.getConstructor().getDeclarationDescriptor()?.let { DescriptorUtils.getFqName(it).asString() } }
|
||||
|
||||
if (annotationsPresent.isEmpty()) return false
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SwapBinaryExpressionIntention : SelfTargetingIntention<KtBinaryExpr
|
||||
companion object {
|
||||
private val SUPPORTED_OPERATIONS = setOf(PLUS, MUL, OROR, ANDAND, EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ, GT, LT, GTEQ, LTEQ)
|
||||
|
||||
private val SUPPORTED_OPERATION_NAMES = SUPPORTED_OPERATIONS.map { OperatorConventions.BINARY_OPERATION_NAMES[it]?.asString() }.toSet().filterNotNull() +
|
||||
private val SUPPORTED_OPERATION_NAMES = SUPPORTED_OPERATIONS.mapNotNull { OperatorConventions.BINARY_OPERATION_NAMES[it]?.asString() }.toSet() +
|
||||
setOf("xor", "or", "and", "equals", "identityEquals")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -65,8 +65,8 @@ public class MergeWhenIntention : SelfTargetingRangeIntention<KtWhenExpression>(
|
||||
private fun KtWhenEntry.declarationNames(): Set<String> =
|
||||
getExpression()?.blockExpressionsOrSingle()
|
||||
?.filter { it is KtNamedDeclaration }
|
||||
?.map { it.getName() }
|
||||
?.filterNotNull()?.toSet() ?: emptySet()
|
||||
?.mapNotNull { it.getName() }
|
||||
?.toSet() ?: emptySet()
|
||||
|
||||
override fun applyTo(element: KtWhenExpression, editor: Editor) {
|
||||
val nextWhen = PsiTreeUtil.skipSiblingsForward(element, javaClass<PsiWhiteSpace>()) as KtWhenExpression
|
||||
|
||||
@@ -41,8 +41,7 @@ public class JoinDeclarationAndAssignmentHandler : JoinRawLinesHandlerDelegate {
|
||||
?.firstOrNull { !isToSkip(it) } ?: return -1
|
||||
|
||||
val pair = element.parentsWithSelf
|
||||
.map { getPropertyAndAssignment(it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { getPropertyAndAssignment(it) }
|
||||
.firstOrNull() ?: return -1
|
||||
val (property, assignment) = pair
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ class AnonymousSuperMacro : Macro() {
|
||||
return resolutionScope
|
||||
.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
|
||||
.filter { it is ClassDescriptor && it.modality.isOverridable && (it.kind == ClassKind.CLASS || it.kind == ClassKind.INTERFACE) }
|
||||
.map { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? }
|
||||
.filterNotNull()
|
||||
.mapNotNull { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? }
|
||||
.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class AddFunctionToSupertypeFix private constructor(
|
||||
if (descriptors.isEmpty()) return null
|
||||
|
||||
val project = diagnostic.psiFile.project
|
||||
val functionData = descriptors.map { createFunctionData(it, project) }.filterNotNull()
|
||||
val functionData = descriptors.mapNotNull { createFunctionData(it, project) }
|
||||
if (functionData.isEmpty()) return null
|
||||
|
||||
return AddFunctionToSupertypeFix(function, functionData)
|
||||
@@ -169,9 +169,7 @@ class AddFunctionToSupertypeFix private constructor(
|
||||
}
|
||||
})
|
||||
|
||||
return supertypes
|
||||
.map { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
.filterNotNull()
|
||||
return supertypes.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||
}
|
||||
|
||||
private fun generateFunctionSignatureForType(functionDescriptor: FunctionDescriptor, typeDescriptor: ClassDescriptor): FunctionDescriptor {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class AddGenericUpperBoundFix(
|
||||
|
||||
val resultingSubstitutor = successfulConstraintSystem.resultingSubstitutor
|
||||
|
||||
return inferenceData.descriptor.typeParameters.map factory@{
|
||||
return inferenceData.descriptor.typeParameters.mapNotNull factory@{
|
||||
typeParameterDescriptor ->
|
||||
|
||||
if (ConstraintsUtil.checkUpperBoundIsSatisfied(
|
||||
@@ -96,7 +96,7 @@ public class AddGenericUpperBoundFix(
|
||||
?: return@factory null
|
||||
|
||||
createAction(argument, upperBound)
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAction(argument: KotlinType, upperBound: KotlinType): IntentionAction? {
|
||||
|
||||
+1
-3
@@ -665,9 +665,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
val expandedValueParameters = declaration.getValueParameters()
|
||||
parameterIndicesToShorten.asSequence()
|
||||
.map { expandedValueParameters[it].getTypeReference() }
|
||||
.filterNotNullTo(typeRefsToShorten)
|
||||
parameterIndicesToShorten.mapNotNullTo(typeRefsToShorten) { expandedValueParameters[it].getTypeReference() }
|
||||
|
||||
return typeRefsToShorten
|
||||
}
|
||||
|
||||
+2
-2
@@ -84,9 +84,9 @@ internal class ParameterNameExpression(
|
||||
}
|
||||
|
||||
// remember other parameter names for later use
|
||||
val parameterNames = parameterList.getParameters().asSequence().map { jetParameter ->
|
||||
val parameterNames = parameterList.getParameters().mapNotNullTo(HashSet<String>()) { jetParameter ->
|
||||
if (jetParameter == parameter) null else jetParameter.getName()
|
||||
}.filterNotNullTo(HashSet<String>())
|
||||
}
|
||||
|
||||
// add fallback parameter name
|
||||
if (names.isEmpty()) {
|
||||
|
||||
+3
-3
@@ -207,14 +207,14 @@ fun KtExpression.guessTypes(
|
||||
}
|
||||
|
||||
private fun KtNamedDeclaration.guessType(context: BindingContext): Array<KotlinType> {
|
||||
val expectedTypes = SearchUtils.findAllReferences(this, getUseScope())!!.asSequence().map { ref ->
|
||||
val expectedTypes = SearchUtils.findAllReferences(this, getUseScope())!!.mapNotNullTo(HashSet<KotlinType>()) { ref ->
|
||||
if (ref is KtSimpleNameReference) {
|
||||
context[BindingContext.EXPECTED_EXPRESSION_TYPE, ref.expression]
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}.filterNotNullTo(HashSet<KotlinType>())
|
||||
}
|
||||
|
||||
if (expectedTypes.isEmpty() || expectedTypes.any { expectedType -> ErrorUtils.containsErrorType(expectedType) }) {
|
||||
return arrayOf()
|
||||
@@ -257,7 +257,7 @@ internal fun KotlinType.substitute(substitution: KotlinTypeSubstitution, varianc
|
||||
fun KtExpression.getExpressionForTypeGuess() = getAssignmentByLHS()?.getRight() ?: this
|
||||
|
||||
fun KtCallElement.getTypeInfoForTypeArguments(): List<TypeInfo> {
|
||||
return getTypeArguments().map { it.getTypeReference()?.let { TypeInfo(it, Variance.INVARIANT) } }.filterNotNull()
|
||||
return getTypeArguments().mapNotNull { it.getTypeReference()?.let { TypeInfo(it, Variance.INVARIANT) } }
|
||||
}
|
||||
|
||||
fun KtCallExpression.getParameterInfos(): List<ParameterInfo> {
|
||||
|
||||
+1
-2
@@ -151,8 +151,7 @@ public abstract class CreateCallableFromUsageFixBase<E : KtElement>(
|
||||
val receiverTypeCandidates = callableBuilder.computeTypeCandidates(callableInfo.receiverTypeInfo)
|
||||
if (receiverTypeCandidates.isNotEmpty()) {
|
||||
val containers = receiverTypeCandidates
|
||||
.map { candidate -> getDeclarationIfApplicable(project, candidate)?.let { candidate to it } }
|
||||
.filterNotNull()
|
||||
.mapNotNull { candidate -> getDeclarationIfApplicable(project, candidate)?.let { candidate to it } }
|
||||
|
||||
chooseContainerElementIfNecessary(containers, editor, popupTitle, false, { it.second }) {
|
||||
runBuilder(CallablePlacement.WithReceiver(it.first))
|
||||
|
||||
+1
-3
@@ -78,9 +78,7 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas
|
||||
|
||||
val typeArgumentInfos = when {
|
||||
isAnnotation -> Collections.emptyList<TypeInfo>()
|
||||
else -> element.typeArguments
|
||||
.map { it.typeReference?.let { TypeInfo(it, Variance.INVARIANT) } }
|
||||
.filterNotNull()
|
||||
else -> element.typeArguments.mapNotNull { it.typeReference?.let { TypeInfo(it, Variance.INVARIANT) } }
|
||||
}
|
||||
|
||||
return ClassInfo(
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
}
|
||||
|
||||
fun getAffectedCallables(project: Project, descriptorsForChange: Collection<CallableDescriptor>): List<PsiElement> {
|
||||
val baseCallables = descriptorsForChange.map { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }.filterNotNull()
|
||||
val baseCallables = descriptorsForChange.mapNotNull { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||
return baseCallables + baseCallables.flatMap { it.toLightMethods() }.flatMapTo(HashSet<PsiElement>()) { psiMethod ->
|
||||
val overrides = OverridingMethodsSearch.search(psiMethod).findAll()
|
||||
overrides.map { method -> method.namedUnwrappedElement ?: method}
|
||||
|
||||
@@ -373,8 +373,7 @@ public open class KotlinChangeInfo(
|
||||
else
|
||||
PsiModifier.PACKAGE_LOCAL
|
||||
val propagationTargets = primaryPropagationTargets.asSequence()
|
||||
.map { it.getRepresentativeLightMethod() }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.getRepresentativeLightMethod() }
|
||||
.toSet()
|
||||
val javaChangeInfo = ChangeSignatureProcessor(
|
||||
getMethod().getProject(),
|
||||
@@ -413,7 +412,7 @@ public open class KotlinChangeInfo(
|
||||
val oldParameterCount = originalPsiMethod.parameterList.parametersCount
|
||||
var indexInCurrentPsiMethod = 0
|
||||
return newParameterList.withIndex()
|
||||
.map { pair ->
|
||||
.mapNotNullTo(ArrayList()) map@ { pair ->
|
||||
val (i, info) = pair
|
||||
|
||||
if (info.defaultValueForParameter != null && defaultValuesRemained-- <= 0) return@map null
|
||||
@@ -435,7 +434,6 @@ public open class KotlinChangeInfo(
|
||||
val defaultValue = info.defaultValueForCall ?: info.defaultValueForParameter
|
||||
ParameterInfoImpl(javaOldIndex, info.getName(), type, defaultValue?.getText() ?: "")
|
||||
}
|
||||
.filterNotNullTo(ArrayList())
|
||||
}
|
||||
|
||||
fun createJavaChangeInfoForFunctionOrGetter(
|
||||
@@ -470,7 +468,7 @@ public open class KotlinChangeInfo(
|
||||
if (javaChangeInfos == null) {
|
||||
val method = getMethod()
|
||||
originalToCurrentMethods = matchOriginalAndCurrentMethods(method.toLightMethods())
|
||||
javaChangeInfos = originalToCurrentMethods.entries.map {
|
||||
javaChangeInfos = originalToCurrentMethods.entries.mapNotNull {
|
||||
val (originalPsiMethod, currentPsiMethod) = it
|
||||
|
||||
when (method) {
|
||||
@@ -488,7 +486,7 @@ public open class KotlinChangeInfo(
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
return javaChangeInfos
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ public class KotlinChangeSignature(project: Project,
|
||||
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
|
||||
val adjustedDescriptor = adjustDescriptor(descriptorsForChange) ?: return
|
||||
|
||||
val affectedFunctions = adjustedDescriptor.affectedCallables.map { it.getElement() }.filterNotNull()
|
||||
val affectedFunctions = adjustedDescriptor.affectedCallables.mapNotNull { it.getElement() }
|
||||
if (affectedFunctions.any { !checkModifiable(it) }) return
|
||||
|
||||
if (configuration.performSilently(affectedFunctions) || ApplicationManager.getApplication()!!.isUnitTestMode()) {
|
||||
|
||||
+2
-2
@@ -111,14 +111,14 @@ public class KotlinChangeSignatureData(
|
||||
lightMethods.flatMap { baseMethod ->
|
||||
OverridingMethodsSearch
|
||||
.search(baseMethod)
|
||||
.map { overridingMethod ->
|
||||
.mapNotNullTo(HashSet<UsageInfo>()) { overridingMethod ->
|
||||
if (overridingMethod is KtLightMethod) {
|
||||
val overridingDeclaration = overridingMethod.namedUnwrappedElement as KtNamedDeclaration
|
||||
val overridingDescriptor = overridingDeclaration.resolveToDescriptor() as CallableDescriptor
|
||||
KotlinCallableDefinitionUsage<PsiElement>(overridingDeclaration, overridingDescriptor, primaryFunction, null)
|
||||
}
|
||||
else OverriderUsageInfo(overridingMethod, baseMethod, true, true, true)
|
||||
}.filterNotNullTo(HashSet<UsageInfo>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-11
@@ -154,11 +154,11 @@ private fun List<Instruction>.getResultTypeAndExpressions(
|
||||
}
|
||||
}
|
||||
|
||||
val resultTypes = map(::instructionToType).filterNotNull()
|
||||
var commonSupertype = if (resultTypes.isNotEmpty()) CommonSupertypes.commonSupertype(resultTypes) else module.builtIns.defaultReturnType
|
||||
val resultTypes = mapNotNull(::instructionToType)
|
||||
val commonSupertype = if (resultTypes.isNotEmpty()) CommonSupertypes.commonSupertype(resultTypes) else module.builtIns.defaultReturnType
|
||||
val resultType = if (options.allowSpecialClassNames) commonSupertype else commonSupertype.approximateWithResolvableType(targetScope, false)
|
||||
|
||||
val expressions = map { instructionToExpression(it, false) }.filterNotNull()
|
||||
val expressions = mapNotNull { instructionToExpression(it, false) }
|
||||
|
||||
return resultType to expressions
|
||||
}
|
||||
@@ -420,13 +420,9 @@ fun KtTypeParameter.collectRelevantConstraints(): List<KtTypeConstraint> {
|
||||
fun TypeParameter.collectReferencedTypes(bindingContext: BindingContext): List<KotlinType> {
|
||||
val typeRefs = ArrayList<KtTypeReference>()
|
||||
originalDeclaration.extendsBound?.let { typeRefs.add(it) }
|
||||
originalConstraints
|
||||
.map { it.boundTypeReference }
|
||||
.filterNotNullTo(typeRefs)
|
||||
originalConstraints.mapNotNullTo(typeRefs) { it.boundTypeReference }
|
||||
|
||||
return typeRefs
|
||||
.map { bindingContext[BindingContext.TYPE, it] }
|
||||
.filterNotNull()
|
||||
return typeRefs.mapNotNull { bindingContext[BindingContext.TYPE, it] }
|
||||
}
|
||||
|
||||
private fun KotlinType.isExtractable(targetScope: LexicalScope?): Boolean {
|
||||
@@ -812,9 +808,9 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
|
||||
for ((originalOffset, resolveResult) in extractionData.refOffsetToDeclaration) {
|
||||
if (resolveResult.declaration.isInsideOf(extractionData.originalElements)) continue
|
||||
|
||||
val currentRefExprs = result.nameByOffset[originalOffset].map {
|
||||
val currentRefExprs = result.nameByOffset[originalOffset].mapNotNull {
|
||||
(it as? KtThisExpression)?.instanceReference ?: it as? KtSimpleNameExpression
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
currentRefExprs.forEach { processReference(resolveResult, it) }
|
||||
}
|
||||
|
||||
+3
-5
@@ -212,11 +212,10 @@ fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
|
||||
.match(scopeElement, unifier)
|
||||
.asSequence()
|
||||
.filter { !(it.range.getTextRange() intersects originalTextRange) }
|
||||
.map { match ->
|
||||
.mapNotNull { match ->
|
||||
val controlFlow = getControlFlowIfMatched(match)
|
||||
controlFlow?.let { DuplicateInfo(match.range, it, unifierParameters.map { match.result.substitution[it]!!.text!! }) }
|
||||
}
|
||||
.filterNotNull()
|
||||
.toList()
|
||||
}
|
||||
|
||||
@@ -421,7 +420,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
||||
|
||||
fun getReturnArguments(resultExpression: KtExpression?): List<String> {
|
||||
return descriptor.controlFlow.outputValues
|
||||
.map {
|
||||
.mapNotNull {
|
||||
when (it) {
|
||||
is ExpressionValue -> resultExpression?.text
|
||||
is Jump -> if (it.conditional) "false" else null
|
||||
@@ -430,7 +429,6 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
||||
else -> throw IllegalArgumentException("Unknown output value: $it")
|
||||
}
|
||||
}
|
||||
.filterNotNull()
|
||||
}
|
||||
|
||||
fun replaceWithReturn(
|
||||
@@ -525,7 +523,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
||||
|
||||
for ((expr, originalOffset) in originalOffsetByExpr) {
|
||||
if (expr.isValid) {
|
||||
val replacements = exprReplacementMap[expr].map { it?.invoke(descriptor, expr) }.filterNotNull()
|
||||
val replacements = exprReplacementMap[expr].mapNotNull { it?.invoke(descriptor, expr) }
|
||||
nameByOffset.put(originalOffset, if (replacements.isEmpty()) arrayListOf(expr) else replacements)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -55,8 +55,7 @@ public class KotlinInplaceParameterIntroducer(
|
||||
null,
|
||||
originalDescriptor.originalRange.elements.single() as KtExpression,
|
||||
originalDescriptor.occurrencesToReplace
|
||||
.map { it.elements.single() as KtExpression }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.elements.single() as KtExpression }
|
||||
.toTypedArray(),
|
||||
INTRODUCE_PARAMETER,
|
||||
project,
|
||||
|
||||
+1
-2
@@ -249,7 +249,7 @@ public open class KotlinIntroduceParameterHandler(
|
||||
val textRange = it.range.getTextRange()
|
||||
forbiddenRanges.any { it.intersects(textRange) }
|
||||
}
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val matchedElement = it.range.elements.singleOrNull()
|
||||
when (matchedElement) {
|
||||
is KtExpression -> matchedElement
|
||||
@@ -257,7 +257,6 @@ public open class KotlinIntroduceParameterHandler(
|
||||
else -> null
|
||||
} as? KtExpression
|
||||
}
|
||||
.filterNotNull()
|
||||
.map { it.toRange() }
|
||||
|
||||
project.executeCommand(
|
||||
|
||||
+1
-2
@@ -120,13 +120,12 @@ public class MoveKotlinTopLevelDeclarationsProcessor(
|
||||
val projectScope = lightElement.getProject().projectScope()
|
||||
val results = ReferencesSearch
|
||||
.search(lightElement, projectScope, false)
|
||||
.mapTo(ArrayList<UsageInfo?>()) { ref ->
|
||||
.mapNotNullTo(ArrayList()) { ref ->
|
||||
if (foundReferences.add(ref) && elementsToMove.all { !it.isAncestor(ref.getElement())}) {
|
||||
createMoveUsageInfoIfPossible(ref, lightElement, true)
|
||||
}
|
||||
else null
|
||||
}
|
||||
.filterNotNull()
|
||||
|
||||
val name = lightElement.getKotlinFqName()?.asString()
|
||||
if (name != null) {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class PackageNameInfo(val oldPackageName: FqName, val newPackageName: FqN
|
||||
public fun KtElement.getInternalReferencesToUpdateOnPackageNameChange(packageNameInfo: PackageNameInfo): List<UsageInfo> {
|
||||
val file = getContainingFile() as? KtFile ?: return listOf()
|
||||
|
||||
val importPaths = file.getImportDirectives().map { it.getImportPath() }.filterNotNull()
|
||||
val importPaths = file.getImportDirectives().mapNotNull { it.getImportPath() }
|
||||
|
||||
tailrec fun isImported(descriptor: DeclarationDescriptor): Boolean {
|
||||
val fqName = DescriptorUtils.getFqName(descriptor).let { if (it.isSafe()) it.toSafe() else return@isImported false }
|
||||
|
||||
+1
-2
@@ -78,8 +78,7 @@ public class JavaToKotlinPreconversionPullUpHelper(
|
||||
setter?.let { dummyAccessorByName[setterName] = dummyTargetClass.add(it) as PsiMethod }
|
||||
fieldsToUsages[member] = ReferencesSearch
|
||||
.search(member)
|
||||
.map { helper.createUsage(encapsulateFieldsDescriptor, fieldDescriptor, it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { helper.createUsage(encapsulateFieldsDescriptor, fieldDescriptor, it) }
|
||||
}
|
||||
|
||||
override fun move(info: MemberInfo, substitutor: PsiSubstitutor) {
|
||||
|
||||
@@ -114,7 +114,7 @@ public class KotlinPullUpDialog(
|
||||
val targetPsiClass = targetClass as? PsiClass ?: (targetClass as KtClass).toLightClass()
|
||||
return PullUpProcessor(sourceClass.toLightClass(),
|
||||
targetPsiClass,
|
||||
memberInfos.map { it.toJavaMemberInfo() }.filterNotNull().toTypedArray(),
|
||||
memberInfos.mapNotNull { it.toJavaMemberInfo() }.toTypedArray(),
|
||||
DocCommentPolicy<PsiComment>(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,12 @@ public class KotlinPullUpHandler : AbstractPullPushMembersHandler(
|
||||
val classDescriptor = classOrObject.resolveToDescriptor() as ClassDescriptor
|
||||
val superClasses = classDescriptor.defaultType
|
||||
.supertypes()
|
||||
.asSequence()
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val descriptor = it.constructor.declarationDescriptor
|
||||
val declaration = descriptor?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||
if ((declaration is KtClass || declaration is PsiClass)
|
||||
&& declaration.canRefactor()) declaration as PsiNamedElement else null
|
||||
}
|
||||
.filterNotNull()
|
||||
.asIterable()
|
||||
.sortedBy { it.qualifiedClassNameForRendering() }
|
||||
|
||||
if (superClasses.isEmpty()) {
|
||||
|
||||
@@ -38,8 +38,7 @@ public class KotlinPullUpHelperFactory : PullUpHelperFactory {
|
||||
val sourceClass = sourceClass.unwrapped as? KtClassOrObject ?: return null
|
||||
val targetClass = targetClass.unwrapped as? PsiNamedElement ?: return null
|
||||
val membersToMove = membersToMove
|
||||
.map { it.namedUnwrappedElement as? KtNamedDeclaration }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.namedUnwrappedElement as? KtNamedDeclaration }
|
||||
.sortedBy { it.startOffset }
|
||||
return KotlinPullUpData(sourceClass, targetClass, membersToMove)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ fun checkConflicts(project: Project,
|
||||
|
||||
val pullUpData = KotlinPullUpData(sourceClass,
|
||||
targetClass,
|
||||
memberInfos.map { it.member }.filterNotNull())
|
||||
memberInfos.mapNotNull { it.member })
|
||||
|
||||
with(pullUpData) {
|
||||
for (memberInfo in memberInfos) {
|
||||
@@ -112,8 +112,7 @@ private fun KotlinPullUpData.checkAccidentalOverrides(
|
||||
.searchInheritors()
|
||||
.asSequence()
|
||||
.filterNot { it.unwrapped == sourceClass || it.unwrapped == targetClass }
|
||||
.map { it.unwrapped as? KtClassOrObject }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.unwrapped as? KtClassOrObject }
|
||||
.forEach {
|
||||
val subClassDescriptor = resolutionFacade.resolveToDescriptor(it) as ClassDescriptor
|
||||
val substitutor = getTypeSubstitutor(targetClassDescriptor.defaultType,
|
||||
|
||||
@@ -94,14 +94,13 @@ public class KotlinPushDownProcessor(
|
||||
}
|
||||
|
||||
override fun getAfterData(usages: Array<out UsageInfo>) = RefactoringEventData().apply {
|
||||
addElements(usages.map { it.element as? KtClassOrObject }.filterNotNull())
|
||||
addElements(usages.mapNotNull { it.element as? KtClassOrObject })
|
||||
}
|
||||
|
||||
override fun findUsages(): Array<out UsageInfo> {
|
||||
return HierarchySearchRequest(context.sourceClass, context.sourceClass.useScope, false)
|
||||
.searchInheritors()
|
||||
.map { it.unwrapped }
|
||||
.filterNotNull()
|
||||
.mapNotNull { it.unwrapped }
|
||||
.map { SubclassUsage(it) }
|
||||
.toTypedArray()
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import java.util.ArrayList
|
||||
|
||||
fun analyzePushDownConflicts(context: KotlinPushDownContext,
|
||||
usages: Array<out UsageInfo>): MultiMap<PsiElement, String> {
|
||||
val targetClasses = usages.map { it.element?.unwrapped }.filterNotNull()
|
||||
val targetClasses = usages.mapNotNull { it.element?.unwrapped }
|
||||
|
||||
val conflicts = MultiMap<PsiElement, String>()
|
||||
|
||||
|
||||
+3
-4
@@ -73,7 +73,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
val javaUsages = ArrayList<UsageInfo>()
|
||||
val searchInfo = super.findUsages(element, allElementsToDelete, javaUsages)
|
||||
|
||||
javaUsages.map { usageInfo ->
|
||||
javaUsages.mapNotNullTo(usages) { usageInfo ->
|
||||
when (usageInfo) {
|
||||
is SafeDeleteOverridingMethodUsageInfo ->
|
||||
usageInfo.getSmartPointer().getElement()?.let { usageElement ->
|
||||
@@ -102,15 +102,14 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
|
||||
else -> usageInfo
|
||||
}
|
||||
}.filterNotNull().toCollection(usages)
|
||||
}
|
||||
|
||||
return searchInfo
|
||||
}
|
||||
|
||||
fun findUsagesByJavaProcessor(elements: Sequence<PsiElement>, insideDeleted: Condition<PsiElement>): Condition<PsiElement> =
|
||||
elements
|
||||
.map { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() }
|
||||
.filterNotNull()
|
||||
.mapNotNull { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() }
|
||||
.fold(insideDeleted) { condition1, condition2 -> Conditions.or(condition1, condition2) }
|
||||
|
||||
fun findUsagesByJavaProcessor(ktDeclaration: KtDeclaration): NonCodeUsageSearchInfo {
|
||||
|
||||
+1
-2
@@ -47,8 +47,7 @@ public open class KotlinDirectInheritorsSearcher() : QueryExecutorBase<PsiClass,
|
||||
runReadAction {
|
||||
val noLibrarySourceScope = KotlinSourceFilterScope.sourceAndClassFiles(scope, baseClass.getProject())
|
||||
KotlinSuperClassIndex.getInstance().get(name, baseClass.getProject(), noLibrarySourceScope).asSequence()
|
||||
.map { candidate -> SourceNavigationHelper.getOriginalPsiClassOrCreateLightClass(candidate)}
|
||||
.filterNotNull()
|
||||
.mapNotNull { candidate -> SourceNavigationHelper.getOriginalPsiClassOrCreateLightClass(candidate)}
|
||||
.filter { candidate -> candidate.isInheritor(baseClass, false) }
|
||||
.forEach { candidate -> consumer.process(candidate) }
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
val scopeToImport = getMemberScope(parentFqName, moduleDescriptor) ?: return ImportDescriptorResult.FAIL
|
||||
val importedScopes = imports
|
||||
.filter { it.isAllUnder () }
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val importPath = it.getImportPath()
|
||||
if (importPath != null) {
|
||||
val fqName = importPath.fqnPart()
|
||||
@@ -248,7 +248,6 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
null
|
||||
}
|
||||
}
|
||||
.filterNotNull()
|
||||
|
||||
val filePackage = moduleDescriptor.getPackage(file.getPackageFqName())
|
||||
|
||||
@@ -266,7 +265,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
val topLevelScope = resolutionFacade.getFileResolutionScope(file)
|
||||
val conflictCandidates: List<ClassifierDescriptor> = classNamesToImport
|
||||
.flatMap {
|
||||
importedScopes.map { scope -> scope.getContributedClassifier(it, NoLookupLocation.FROM_IDE) }.filterNotNull()
|
||||
importedScopes.mapNotNull { scope -> scope.getContributedClassifier(it, NoLookupLocation.FROM_IDE) }
|
||||
}
|
||||
.filter { importedClass ->
|
||||
isVisible(importedClass)
|
||||
|
||||
@@ -708,7 +708,7 @@ public class KotlinPsiUnifier(
|
||||
}
|
||||
|
||||
private fun ASTNode.getChildrenRange(): KotlinPsiRange =
|
||||
getChildren(null).map { it.getPsi() }.filterNotNull().toRange()
|
||||
getChildren(null).mapNotNull { it.getPsi() }.toRange()
|
||||
|
||||
private fun PsiElement.unwrapWeakly(): KtElement? {
|
||||
return when {
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class AbstractDataFlowValueRenderingTest: KotlinLightCodeInsight
|
||||
val info = expression.analyze().getDataFlowInfo(expression)
|
||||
|
||||
val allValues = (info.getCompleteTypeInfo().keySet() + info.getCompleteNullabilityInfo().keySet()).toSet()
|
||||
val actual = allValues.map { renderDataFlowValue(it) }.filterNotNull().sorted().joinToString("\n")
|
||||
val actual = allValues.mapNotNull { renderDataFlowValue(it) }.sorted().joinToString("\n")
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(File(FileUtil.getNameWithoutExtension(fileName) + ".txt"), actual)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTest
|
||||
setTestDataPath("${KotlinTestUtils.getHomeDirectory()}/$srcDir")
|
||||
|
||||
val afterFiles = srcDir.listFiles { it.name == "inspectionData" }?.single()?.listFiles { it.extension == "after" } ?: emptyArray()
|
||||
val psiFiles = srcDir.walkTopDown().treeFilter { it.name != "inspectionData" }.map {
|
||||
val psiFiles = srcDir.walkTopDown().treeFilter { it.name != "inspectionData" }.mapNotNull {
|
||||
file ->
|
||||
if (file.isDirectory) {
|
||||
null
|
||||
@@ -89,7 +89,7 @@ public abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTest
|
||||
"package ${file.nameWithoutExtension};$text"
|
||||
configureByText(file.name, fileText)!!
|
||||
}
|
||||
}.filterNotNull().toList()
|
||||
}.toList()
|
||||
|
||||
val isJs = srcDir.endsWith("js")
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
|
||||
|
||||
val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position)
|
||||
|
||||
stepTargets.filterIsInstance<SmartStepTarget>().map {
|
||||
stepTargets.filterIsInstance<SmartStepTarget>().mapNotNull {
|
||||
stepTarget ->
|
||||
when (stepTarget) {
|
||||
is KotlinLambdaSmartStepTarget -> KotlinLambdaMethodFilter(stepTarget.getLambda(), stepTarget.getCallingExpressionLines()!!, stepTarget.isInline)
|
||||
@@ -225,7 +225,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun SuspendContextImpl.printContext() {
|
||||
|
||||
Reference in New Issue
Block a user