Replace map { ... }.filterNotNull() with mapNotNull { ... }
This commit is contained in:
@@ -127,7 +127,7 @@ public class PropertyReferenceCodegen(
|
||||
StackValue.singleton(containingObject, typeMapper).put(typeMapper.mapClass(containingObject), this)
|
||||
}
|
||||
|
||||
for ((index, type) in listOf(dispatchReceiverType, extensionReceiverType).filterNotNull().withIndex()) {
|
||||
for ((index, type) in listOfNotNull(dispatchReceiverType, extensionReceiverType).withIndex()) {
|
||||
StackValue.local(index + 1, OBJECT_TYPE).put(typeMapper.mapType(type), this)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -40,10 +40,10 @@ class BuilderFactoryForDuplicateClassNameDiagnostics(
|
||||
}
|
||||
|
||||
private fun reportError(internalName: String, vararg another: JvmDeclarationOrigin) {
|
||||
val fromString = another.map { it.descriptor }.filterNotNull().
|
||||
val fromString = another.mapNotNull { it.descriptor }.
|
||||
joinToString { DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.render(it) }
|
||||
|
||||
another.map { it.element }.filterNotNull().forEach {
|
||||
another.mapNotNull { it.element }.forEach {
|
||||
diagnostics.report(ErrorsJvm.DUPLICATE_CLASS_NAMES.on(it, internalName, fromString))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -92,13 +92,13 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
|
||||
}
|
||||
|
||||
override fun findClassOrObjectDeclarations(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtClassOrObject> {
|
||||
return ResolveSessionUtils.getClassDescriptorsByFqName(module, fqName).map {
|
||||
return ResolveSessionUtils.getClassDescriptorsByFqName(module, fqName).mapNotNull {
|
||||
val element = DescriptorToSourceUtils.getSourceFromDescriptor(it)
|
||||
if (element is KtClassOrObject && PsiSearchScopeUtil.isInScope(searchScope, element)) {
|
||||
element
|
||||
}
|
||||
else null
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
override fun findFilesForPackage(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtFile> {
|
||||
@@ -216,7 +216,7 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
|
||||
override fun getFacadeClassesInPackage(packageFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> {
|
||||
return PackagePartClassUtils.getFilesWithCallables(findFilesForPackage(packageFqName, scope)).groupBy {
|
||||
JvmFileClassUtil.getFileClassInfoNoResolve(it).facadeClassFqName
|
||||
}.map { KtLightClassForFacade.createForFacade(psiManager, it.key, scope, it.value) }.filterNotNull()
|
||||
}.mapNotNull { KtLightClassForFacade.createForFacade(psiManager, it.key, scope, it.value) }
|
||||
}
|
||||
|
||||
override fun getFacadeNames(packageFqName: FqName, scope: GlobalSearchScope): Collection<String> {
|
||||
|
||||
@@ -28,9 +28,9 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
val roots by lazy {
|
||||
env.configuration.getList(CommonConfigurationKeys.CONTENT_ROOTS).
|
||||
filterIsInstance<JvmClasspathRoot>().
|
||||
map {
|
||||
mapNotNull {
|
||||
env.contentRootToVirtualFile(it);
|
||||
}.filter { it?.findChild("META-INF") != null }.filterNotNull()
|
||||
}.filter { it.findChild("META-INF") != null }
|
||||
}
|
||||
|
||||
override fun findPackageParts(packageFqName: String): List<String> {
|
||||
@@ -43,10 +43,10 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
else parent.findChild(part) ?: return@filter false
|
||||
}
|
||||
true
|
||||
}.map {
|
||||
}.mapNotNull {
|
||||
it.findChild("META-INF")
|
||||
}.filterNotNull().flatMap {
|
||||
it.children.filter { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }.toList<VirtualFile>()
|
||||
}.flatMap {
|
||||
it.children.filter<VirtualFile> { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }
|
||||
}.map {
|
||||
try {
|
||||
ModuleMapping.create(it.contentsToByteArray())
|
||||
@@ -55,6 +55,6 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
}
|
||||
}
|
||||
|
||||
return mappings.map { it.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
|
||||
return mappings.mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts }.distinct()
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,10 @@ public fun inlineFunctionsJvmNames(bytes: ByteArray): Set<String> {
|
||||
private fun inlineFunctionsJvmNames(functions: List<ProtoBuf.Function>, nameResolver: NameResolver, protoTypeTable: ProtoBuf.TypeTable): Set<String> {
|
||||
val typeTable = TypeTable(protoTypeTable)
|
||||
val inlineFunctions = functions.filter { Flags.IS_INLINE.get(it.flags) }
|
||||
val jvmNames = inlineFunctions.map {
|
||||
val jvmNames = inlineFunctions.mapNotNull {
|
||||
JvmProtoBufUtil.getJvmMethodSignature(it, nameResolver, typeTable)
|
||||
}
|
||||
return jvmNames.filterNotNull().toSet()
|
||||
return jvmNames.toSet()
|
||||
}
|
||||
|
||||
private fun readKotlinHeader(bytes: ByteArray): KotlinClassHeader {
|
||||
|
||||
+3
-5
@@ -119,10 +119,9 @@ public class IncrementalPackageFragmentProvider(
|
||||
} ?: emptyList<String>()
|
||||
|
||||
val scopes = actualPackagePartFiles
|
||||
.map {
|
||||
.mapNotNull {
|
||||
incrementalCache.getPackagePartData(it)
|
||||
}
|
||||
.filterNotNull()
|
||||
.map {
|
||||
IncrementalPackageScope(JvmProtoBufUtil.readPackageDataFrom(it.data, it.strings))
|
||||
}
|
||||
@@ -149,7 +148,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
val partsNames: Collection<String>
|
||||
) : PackageFragmentDescriptorImpl(moduleDescriptor, multifileClassFqName.parent()) {
|
||||
val memberScope = storageManager.createLazyValue {
|
||||
val partsData = partsNames.map { incrementalCache.getPackagePartData(it) }.filterNotNull()
|
||||
val partsData = partsNames.mapNotNull { incrementalCache.getPackagePartData(it) }
|
||||
if (partsData.isEmpty())
|
||||
MemberScope.Empty
|
||||
else {
|
||||
@@ -182,8 +181,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
|
||||
if (LOG.isDebugEnabled) {
|
||||
val allPackageParts = allMemberProtos
|
||||
.map(::getPackagePart)
|
||||
.filterNotNull()
|
||||
.mapNotNull(::getPackagePart)
|
||||
.toSet()
|
||||
val skippedPackageParts = allPackageParts.filter { shouldSkipPackagePart(it) }
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ internal class IncrementalPackagePartProvider private constructor(
|
||||
val packagePartsFromParent = parent.findPackageParts(packageFqName)
|
||||
if (packageFqName in fqNamesToIgnore) return packagePartsFromParent
|
||||
|
||||
val packagePartsFromCompiled = moduleMappings().map { it.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }
|
||||
val packagePartsFromCompiled = moduleMappings().mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts }
|
||||
return (packagePartsFromCompiled + packagePartsFromParent).distinct()
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -77,8 +77,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
|
||||
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
|
||||
type.memberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
|
||||
.filterIsInstance<FunctionDescriptor>()
|
||||
.map { extensionForFunction(it.original) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { extensionForFunction(it.original) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ fun getReceiverTypePredicate(resolvedCall: ResolvedCall<*>, receiverValue: Recei
|
||||
}
|
||||
resolvedCall.getDispatchReceiver() -> {
|
||||
val rootCallableDescriptors = callableDescriptor.findTopMostOverriddenDescriptors()
|
||||
return or(rootCallableDescriptors.map {
|
||||
return or(rootCallableDescriptors.mapNotNull {
|
||||
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.isSafeCall()) }?.getSubtypesPredicate()
|
||||
}.filterNotNull())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ public object PositioningStrategies {
|
||||
val visibilityTokens = listOf(KtTokens.PRIVATE_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PUBLIC_KEYWORD, KtTokens.INTERNAL_KEYWORD)
|
||||
val modifierList = element.getModifierList()
|
||||
|
||||
val result = visibilityTokens.map { modifierList?.getModifier(it)?.getTextRange() }.filterNotNull()
|
||||
val result = visibilityTokens.mapNotNull { modifierList?.getModifier(it)?.getTextRange() }
|
||||
if (!result.isEmpty()) return result
|
||||
|
||||
// Try to resolve situation when there's no visibility modifiers written before element
|
||||
|
||||
@@ -282,8 +282,8 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
|
||||
}
|
||||
|
||||
fun renderChildren(element: KtElementImplStub<*>, separator: String, prefix: String = "", postfix: String = ""): String? {
|
||||
val childrenTexts = element.getStub()?.getChildrenStubs()?.map { (it?.getPsi() as? KtElement)?.getDebugText() }
|
||||
return childrenTexts?.filterNotNull()?.joinToString(separator, prefix, postfix) ?: element.getText()
|
||||
val childrenTexts = element.getStub()?.getChildrenStubs()?.mapNotNull { (it?.getPsi() as? KtElement)?.getDebugText() }
|
||||
return childrenTexts?.joinToString(separator, prefix, postfix) ?: element.getText()
|
||||
}
|
||||
|
||||
fun render(element: KtElementImplStub<*>, vararg relevantChildren: KtElement?): String? {
|
||||
|
||||
@@ -58,8 +58,7 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo
|
||||
|
||||
val newModifier = KtPsiFactory(modifierList).createModifier(modifier)
|
||||
val modifierToReplace = MODIFIERS_TO_REPLACE[modifier]
|
||||
?.map { modifierList.getModifier(it) }
|
||||
?.filterNotNull()
|
||||
?.mapNotNull { modifierList.getModifier(it) }
|
||||
?.firstOrNull()
|
||||
|
||||
if (modifierToReplace != null) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public open class KotlinStubBaseImpl<T : KtElementImplStub<*>>(parent: StubEleme
|
||||
}
|
||||
|
||||
private fun renderPropertyValues(stubInterface: Class<out Any?>): List<String> {
|
||||
return collectProperties(stubInterface).map { property -> renderProperty(property) }.filterNotNull().sorted()
|
||||
return collectProperties(stubInterface).mapNotNull { property -> renderProperty(property) }.sorted()
|
||||
}
|
||||
|
||||
private fun collectProperties(stubInterface: Class<*>): Collection<Method> {
|
||||
|
||||
@@ -40,7 +40,7 @@ class AllUnderImportsScope(descriptor: DeclarationDescriptor) : BaseImportingSco
|
||||
= scopes.flatMap { it.getContributedDescriptors(kindFilter, nameFilter) }
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation)
|
||||
= scopes.asSequence().map { it.getContributedClassifier(name, location) }.filterNotNull().singleOrNull()
|
||||
= scopes.asSequence().mapNotNull { it.getContributedClassifier(name, location) }.singleOrNull()
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation)
|
||||
= scopes.flatMap { it.getContributedVariables(name, location) }
|
||||
|
||||
@@ -157,9 +157,9 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
?: return null
|
||||
val valueArguments = targetEntryDescriptor.allValueArguments
|
||||
val valueArgument = valueArguments.entrySet().firstOrNull()?.getValue() as? ArrayValue ?: return null
|
||||
return valueArgument.value.filterIsInstance<EnumValue>().map {
|
||||
return valueArgument.value.filterIsInstance<EnumValue>().mapNotNull {
|
||||
KotlinTarget.valueOrNull(it.value.name.asString())
|
||||
}.filterNotNull().toSet()
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
public fun getDeclarationSiteActualTargetList(annotated: KtElement, descriptor: ClassDescriptor?): List<KotlinTarget> {
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ public object NonExpansiveInheritanceRestrictionChecker {
|
||||
val bounds = hashSetOf<KotlinType>()
|
||||
|
||||
val substitutor = constituentType.substitution.buildSubstitutor()
|
||||
val adaptedUpperBounds = originalTypeParameter.upperBounds.map { substitutor.substitute(it, Variance.INVARIANT) }.filterNotNull()
|
||||
val adaptedUpperBounds = originalTypeParameter.upperBounds.mapNotNull { substitutor.substitute(it, Variance.INVARIANT) }
|
||||
bounds.addAll(adaptedUpperBounds)
|
||||
|
||||
if (!typeProjection.isStarProjection) {
|
||||
|
||||
@@ -237,8 +237,7 @@ public class TypeResolver(
|
||||
val modifierList = param.modifierList
|
||||
if (modifierList != null) {
|
||||
KtTokens.MODIFIER_KEYWORDS_ARRAY
|
||||
.map { modifierList.getModifier(it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { modifierList.getModifier(it) }
|
||||
.forEach { c.trace.report(Errors.UNSUPPORTED.on(it, "modifier on parameter in function type"))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
val candidateWithFreshVariables = FunctionDescriptorUtil.alphaConvertTypeParameters(candidateDescriptor)
|
||||
val conversion = candidateDescriptor.typeParameters.zip(candidateWithFreshVariables.typeParameters).toMap()
|
||||
|
||||
val freshVariables = returnType.getNestedTypeParameters().map { conversion[it] }.filterNotNull()
|
||||
val freshVariables = returnType.getNestedTypeParameters().mapNotNull { conversion[it] }
|
||||
builder.registerTypeVariables(resultingCall.call.toHandle(), freshVariables, external = true)
|
||||
|
||||
builder.addSubtypeConstraint(
|
||||
|
||||
+1
-3
@@ -58,9 +58,7 @@ public abstract class DeclarationProviderFactoryService {
|
||||
private class SyntheticFilesFilteringScope(syntheticFiles: Collection<KtFile>, baseScope: GlobalSearchScope)
|
||||
: DelegatingGlobalSearchScope(baseScope) {
|
||||
|
||||
private val originals = syntheticFiles
|
||||
.map { it.getOriginalFile().getVirtualFile() }
|
||||
.filterNotNullTo(HashSet<VirtualFile>())
|
||||
private val originals = syntheticFiles.mapNotNullTo(HashSet<VirtualFile>()) { it.getOriginalFile().getVirtualFile() }
|
||||
|
||||
override fun contains(file: VirtualFile) = super.contains(file) && file !in originals
|
||||
}
|
||||
|
||||
+4
-5
@@ -86,11 +86,10 @@ public class LazyAnnotations(
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> {
|
||||
return annotationEntries
|
||||
.asSequence()
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val (descriptor, target) = annotation(it)
|
||||
if (target == null) null else AnnotationWithTarget(descriptor, target)
|
||||
}.filterNotNull().toList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAllAnnotations() = annotationEntries.map(annotation)
|
||||
@@ -98,10 +97,10 @@ public class LazyAnnotations(
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> {
|
||||
return annotationEntries
|
||||
.asSequence()
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val (descriptor, target) = annotation(it)
|
||||
if (target == null) descriptor else null // Filter out annotations with target
|
||||
}.filterNotNull().iterator()
|
||||
}.iterator()
|
||||
}
|
||||
|
||||
override fun forceResolveAllContents() {
|
||||
|
||||
+3
-3
@@ -365,13 +365,13 @@ public open class KtLightClassForExplicitDeclaration(
|
||||
override fun toString() = "${KtLightClass::class.java.simpleName}:$classFqName"
|
||||
|
||||
override fun getOwnInnerClasses(): List<PsiClass> {
|
||||
val result = ArrayList<PsiClass?>()
|
||||
classOrObject.declarations.filterIsInstance<KtClassOrObject>().mapTo(result) { create(it) }
|
||||
val result = ArrayList<PsiClass>()
|
||||
classOrObject.declarations.filterIsInstance<KtClassOrObject>().mapNotNullTo(result) { create(it) }
|
||||
|
||||
if (classOrObject.hasInterfaceDefaultImpls) {
|
||||
result.add(KtLightClassForInterfaceDefaultImpls(classFqName.defaultImplsChild(), classOrObject))
|
||||
}
|
||||
return result.filterNotNull()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getUseScope(): SearchScope = getOrigin().useScope
|
||||
|
||||
@@ -327,14 +327,17 @@ public object LightClassUtil {
|
||||
public val setter: PsiMethod?,
|
||||
public val backingField: PsiField?,
|
||||
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> {
|
||||
private val allMethods = arrayListOf<PsiMethod>()
|
||||
val allDeclarations = arrayListOf<PsiNamedElement>()
|
||||
private val allMethods: List<PsiMethod>
|
||||
val allDeclarations: List<PsiNamedElement>
|
||||
|
||||
init {
|
||||
listOf(getter, setter).filterNotNullTo(allMethods)
|
||||
listOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
|
||||
allDeclarations.addAll(additionalAccessors)
|
||||
allMethods = arrayListOf<PsiMethod>()
|
||||
arrayOf(getter, setter).filterNotNullTo(allMethods)
|
||||
additionalAccessors.filterIsInstanceTo<PsiMethod, MutableList<PsiMethod>>(allMethods)
|
||||
|
||||
allDeclarations = arrayListOf<PsiNamedElement>()
|
||||
arrayOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
|
||||
allDeclarations.addAll(additionalAccessors)
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<PsiMethod> = allMethods.iterator()
|
||||
|
||||
@@ -45,9 +45,9 @@ public fun cliPluginUsageString(pluginId: String, options: Collection<CliOption>
|
||||
"\n" + " ".repeat(MAX_OPTION_WIDTH + LEFT_INDENT + 1)
|
||||
} else " ".repeat(1 + MAX_OPTION_WIDTH - name.length())
|
||||
|
||||
val modifiers = listOf(
|
||||
val modifiers = listOfNotNull(
|
||||
if (it.required) "required" else null,
|
||||
if (it.allowMultipleOccurrences) "multiple" else null).filterNotNull()
|
||||
if (it.allowMultipleOccurrences) "multiple" else null)
|
||||
val modifiersEnclosed = if (modifiers.isEmpty()) "" else " (${modifiers.joinToString()})"
|
||||
|
||||
" ".repeat(LEFT_INDENT) + name + margin + it.description + modifiersEnclosed
|
||||
|
||||
@@ -236,11 +236,10 @@ public object KotlinCompilerClient {
|
||||
?.split(File.pathSeparator)
|
||||
?.map { File(it).parentFile }
|
||||
?.distinct()
|
||||
?.map {
|
||||
?.mapNotNull {
|
||||
it?.walk()
|
||||
?.firstOrNull { it.name.equals(COMPILER_JAR_NAME, ignoreCase = true) }
|
||||
}
|
||||
?.filterNotNull()
|
||||
?.firstOrNull()
|
||||
?.let { listOf(it.absolutePath) }
|
||||
|
||||
@@ -266,7 +265,7 @@ public object KotlinCompilerClient {
|
||||
val daemons = registryDir.walk()
|
||||
.map { Pair(it, it.name.extractPortFromRunFilename(classPathDigest)) }
|
||||
.filter { it.second != 0 }
|
||||
.map {
|
||||
.mapNotNull {
|
||||
assert(it.second > 0 && it.second < 0xffff)
|
||||
reportingTargets.report(DaemonReportCategory.DEBUG, "found suitable daemon on port ${it.second}, trying to connect")
|
||||
val daemon = tryConnectToDaemon(it.second, reportingTargets)
|
||||
@@ -276,7 +275,6 @@ public object KotlinCompilerClient {
|
||||
}
|
||||
daemon
|
||||
}
|
||||
.filterNotNull()
|
||||
.toList()
|
||||
return when (daemons.size) {
|
||||
0 -> null
|
||||
|
||||
@@ -66,8 +66,8 @@ open class PropMapper<C, V, P : KMutableProperty1<C, V>>(val dest: C,
|
||||
open fun toArgs(prefix: String = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX): List<String> =
|
||||
when {
|
||||
skipIf(prop.get(dest)) -> listOf<String>()
|
||||
mergeDelimiter != null -> listOf(listOf(prefix + names.first(), toString(prop.get(dest))).filterNotNull().joinToString(mergeDelimiter))
|
||||
else -> listOf(prefix + names.first(), toString(prop.get(dest))).filterNotNull()
|
||||
mergeDelimiter != null -> listOf(listOfNotNull(prefix + names.first(), toString(prop.get(dest))).joinToString(mergeDelimiter))
|
||||
else -> listOfNotNull(prefix + names.first(), toString(prop.get(dest)))
|
||||
}
|
||||
|
||||
open fun apply(s: String) = prop.set(dest, fromString(s))
|
||||
|
||||
@@ -66,8 +66,7 @@ public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
|
||||
|
||||
val elementToValues = getElementToValueMap(pseudocode)
|
||||
val unboundValues = pseudocode.getInstructions()
|
||||
.map { (it as? InstructionWithValue)?.outputValue }
|
||||
.filterNotNull()
|
||||
.mapNotNull { (it as? InstructionWithValue)?.outputValue }
|
||||
.filter { it.element == null }
|
||||
.sortedBy { it.debugName }
|
||||
val allValues = elementToValues.values() + unboundValues
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.io.File
|
||||
public interface AbstractSMAPBaseTest {
|
||||
|
||||
private fun extractSMAPFromClasses(outputFiles: Iterable<OutputFile>): List<SMAPAndFile> {
|
||||
return outputFiles.map { outputFile ->
|
||||
return outputFiles.mapNotNull { outputFile ->
|
||||
var debugInfo: String? = null
|
||||
ClassReader(outputFile.asByteArray()).accept(object : ClassVisitor(Opcodes.ASM5) {
|
||||
override fun visitSource(source: String?, debug: String?) {
|
||||
@@ -41,7 +41,7 @@ public interface AbstractSMAPBaseTest {
|
||||
}, 0)
|
||||
|
||||
SMAPAndFile.SMAPAndFile(debugInfo, outputFile.sourceFiles.single())
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractSmapFromSource(file: KtFile): SMAPAndFile? {
|
||||
@@ -63,11 +63,11 @@ public interface AbstractSMAPBaseTest {
|
||||
return
|
||||
}
|
||||
|
||||
val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull()
|
||||
val sourceData = inputFiles.mapNotNull { extractSmapFromSource(it) }
|
||||
val compiledData = extractSMAPFromClasses(outputFiles).groupBy {
|
||||
it.sourceFile
|
||||
}.map {
|
||||
val smap = it.getValue().map { replaceHash(it.smap) }.filterNotNull().joinToString("\n")
|
||||
val smap = it.getValue().mapNotNull { it.smap?.replaceHash() }.joinToString("\n")
|
||||
SMAPAndFile(if (smap.isNotEmpty()) smap else null, it.key)
|
||||
}.toMap { it.sourceFile }
|
||||
|
||||
@@ -77,17 +77,16 @@ public interface AbstractSMAPBaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
fun replaceHash(data: String?): String? {
|
||||
if (data == null) return null
|
||||
|
||||
val fileSectionStart = data.indexOf("*F") + 3
|
||||
val lineSection = data.indexOf("*L") - 1
|
||||
private fun String.replaceHash(): String {
|
||||
val fileSectionStart = indexOf("*F") + 3
|
||||
val lineSection = indexOf("*L") - 1
|
||||
|
||||
val files = data.substring(fileSectionStart, lineSection).split("\n")
|
||||
val files = substring(fileSectionStart, lineSection).split("\n")
|
||||
|
||||
val cleaned = files.joinToString("\n")
|
||||
|
||||
return data.substring(0, fileSectionStart) + cleaned + data.substring(lineSection)
|
||||
return substring(0, fileSectionStart) + cleaned + substring(lineSection)
|
||||
}
|
||||
|
||||
class SMAPAndFile(val smap: String?, val sourceFile: String) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user