Deprecations cleanup: sequence -> asSequence

This commit is contained in:
Ilya Gorbunov
2015-06-25 20:25:31 +03:00
parent 765733b791
commit 5779b89ff0
12 changed files with 19 additions and 20 deletions
@@ -30,7 +30,7 @@ public class CompositeBindingContext private constructor(
private val delegates: List<BindingContext> private val delegates: List<BindingContext>
) : BindingContext { ) : BindingContext {
override fun getType(expression: JetExpression): JetType? { override fun getType(expression: JetExpression): JetType? {
return delegates.sequence().map { it.getType(expression) }.firstOrNull { it != null } return delegates.asSequence().map { it.getType(expression) }.firstOrNull { it != null }
} }
companion object { companion object {
@@ -42,7 +42,7 @@ public class CompositeBindingContext private constructor(
} }
override fun <K, V> get(slice: ReadOnlySlice<K, V>?, key: K?): V? { override fun <K, V> get(slice: ReadOnlySlice<K, V>?, key: K?): V? {
return delegates.sequence().map { it[slice, key] }.firstOrNull { it != null } return delegates.asSequence().map { it[slice, key] }.firstOrNull { it != null }
} }
override fun <K, V> getKeys(slice: WritableSlice<K, V>?): Collection<K> { override fun <K, V> getKeys(slice: WritableSlice<K, V>?): Collection<K> {
@@ -65,8 +65,7 @@ public class CompositeBindingContext private constructor(
) : Diagnostics { ) : Diagnostics {
override fun iterator(): Iterator<Diagnostic> { override fun iterator(): Iterator<Diagnostic> {
val emptyStream = listOf<Diagnostic>().sequence() return delegates.fold(emptySequence<Diagnostic>(), { r, t -> r + t.asSequence() }).iterator()
return delegates.fold(emptyStream, { r, t -> r + t.sequence() }).iterator()
} }
override val modificationTracker = object : ModificationTracker { override val modificationTracker = object : ModificationTracker {
@@ -77,7 +77,7 @@ public class LazyAnnotations(
override fun findExternalAnnotation(fqName: FqName) = null override fun findExternalAnnotation(fqName: FqName) = null
override fun iterator(): Iterator<AnnotationDescriptor> = annotationEntries.sequence().map(annotation).iterator() override fun iterator(): Iterator<AnnotationDescriptor> = annotationEntries.asSequence().map(annotation).iterator()
override fun forceResolveAllContents() { override fun forceResolveAllContents() {
// To resolve all entries // To resolve all entries
@@ -53,7 +53,7 @@ public object InlineTestUtil {
val skipParameterChecking = val skipParameterChecking =
sourceFiles.sequence().filter { sourceFiles.asSequence().filter {
InTextDirectivesUtils.isDirectiveDefined(it.getText(), "NO_CHECK_LAMBDA_INLINING") InTextDirectivesUtils.isDirectiveDefined(it.getText(), "NO_CHECK_LAMBDA_INLINING")
}.any() }.any()
@@ -39,7 +39,7 @@ class LazyJavaAnnotations(
c.externalAnnotationResolver.findExternalAnnotation(annotationOwner, fqName)?.let(annotationDescriptors) c.externalAnnotationResolver.findExternalAnnotation(annotationOwner, fqName)?.let(annotationDescriptors)
override fun iterator() = override fun iterator() =
annotationOwner.getAnnotations().sequence().map(annotationDescriptors).filterNotNull().iterator() annotationOwner.getAnnotations().asSequence().map(annotationDescriptors).filterNotNull().iterator()
override fun isEmpty() = !iterator().hasNext() override fun isEmpty() = !iterator().hasNext()
} }
@@ -56,7 +56,7 @@ class FilteredAnnotations(
if (fqNameFilter(fqName)) delegate.findExternalAnnotation(fqName) if (fqNameFilter(fqName)) delegate.findExternalAnnotation(fqName)
else null else null
override fun iterator() = delegate.sequence() override fun iterator() = delegate.asSequence()
.filter { annotation -> .filter { annotation ->
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor() val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
descriptor != null && DescriptorUtils.getFqName(descriptor).let { fqName -> descriptor != null && DescriptorUtils.getFqName(descriptor).let { fqName ->
@@ -80,7 +80,7 @@ class KClassImpl<T>(override val jClass: Class<T>) : KCallableContainerImpl(), K
} }
private fun <P : KProperty<*>> getProperties(extension: Boolean, declared: Boolean, create: (PropertyDescriptor) -> P): Collection<P> = private fun <P : KProperty<*>> getProperties(extension: Boolean, declared: Boolean, create: (PropertyDescriptor) -> P): Collection<P> =
scope.getAllDescriptors().sequence() scope.getAllDescriptors().asSequence()
.filterIsInstance<PropertyDescriptor>() .filterIsInstance<PropertyDescriptor>()
.filter { descriptor -> .filter { descriptor ->
(descriptor.getExtensionReceiverParameter() != null) == extension && (descriptor.getExtensionReceiverParameter() != null) == extension &&
@@ -53,7 +53,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
callType: CallType, callType: CallType,
containingDeclarationOrModule: DeclarationDescriptor containingDeclarationOrModule: DeclarationDescriptor
): Collection<CallableDescriptor> { ): Collection<CallableDescriptor> {
val sequence = receivers.sequence().flatMap { substituteExtensionIfCallable(it, callType, context, dataFlowInfo, containingDeclarationOrModule).sequence() } val sequence = receivers.asSequence().flatMap { substituteExtensionIfCallable(it, callType, context, dataFlowInfo, containingDeclarationOrModule).asSequence() }
if (getTypeParameters().isEmpty()) { // optimization for non-generic callables if (getTypeParameters().isEmpty()) { // optimization for non-generic callables
return sequence.firstOrNull()?.let { listOf(it) } ?: listOf() return sequence.firstOrNull()?.let { listOf(it) } ?: listOf()
} }
@@ -81,7 +81,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
if (!receiver.exists()) return listOf() if (!receiver.exists()) return listOf()
if (!callType.canCall(this)) return listOf() if (!callType.canCall(this)) return listOf()
var types = SmartCastUtils.getSmartCastVariants(receiver, bindingContext, containingDeclarationOrModule, dataFlowInfo).sequence() var types = SmartCastUtils.getSmartCastVariants(receiver, bindingContext, containingDeclarationOrModule, dataFlowInfo).asSequence()
if (callType == CallType.SAFE) { if (callType == CallType.SAFE) {
types = types.map { it.makeNotNullable() } types = types.map { it.makeNotNullable() }
@@ -167,7 +167,7 @@ public class CheckPartialBodyResolveAction : AnAction() {
private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<JetFile> { private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<JetFile> {
val manager = PsiManager.getInstance(project) val manager = PsiManager.getInstance(project)
return allFiles(filesOrDirs) return allFiles(filesOrDirs)
.sequence() .asSequence()
.map { manager.findFile(it) as? JetFile } .map { manager.findFile(it) as? JetFile }
.filterNotNull() .filterNotNull()
} }
@@ -153,7 +153,7 @@ public class FindImplicitNothingAction : AnAction() {
private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<JetFile> { private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<JetFile> {
val manager = PsiManager.getInstance(project) val manager = PsiManager.getInstance(project)
return allFiles(filesOrDirs) return allFiles(filesOrDirs)
.sequence() .asSequence()
.map { manager.findFile(it) as? JetFile } .map { manager.findFile(it) as? JetFile }
.filterNotNull() .filterNotNull()
} }
@@ -106,11 +106,11 @@ private fun findPackagePartFileNamesForElement(elementAt: JetElement): List<Stri
JdkScope(project, libraryEntry as JdkOrderEntry) JdkScope(project, libraryEntry as JdkOrderEntry)
} }
val packagePartFiles = FilenameIndex.getAllFilenames(project).sequence().filter { val packagePartFiles = FilenameIndex.getAllFilenames(project).asSequence().filter {
it.startsWith(packagePartNameWoHash) && it.endsWith(".class") && it.startsWith(packagePartNameWoHash) && it.endsWith(".class") &&
!it.substringAfter(packagePartNameWoHash).contains("\$") !it.substringAfter(packagePartNameWoHash).contains("\$")
}.flatMap { }.flatMap {
FilenameIndex.getVirtualFilesByName(project, it, scope).sequence() FilenameIndex.getVirtualFilesByName(project, it, scope).asSequence()
}.map { }.map {
val packageFqName = file.getPackageFqName() val packageFqName = file.getPackageFqName()
if (packageFqName.isRoot()) { if (packageFqName.isRoot()) {
@@ -225,12 +225,12 @@ public class JetPsiUnifier(
if (args1.size() != args2.size()) return UNMATCHED if (args1.size() != args2.size()) return UNMATCHED
if (rc1.getCall().getValueArguments().size() != args1.size() || rc2.getCall().getValueArguments().size() != args2.size()) return null if (rc1.getCall().getValueArguments().size() != args1.size() || rc2.getCall().getValueArguments().size() != args2.size()) return null
return (args1.sequence() zip args2.sequence()).fold(MATCHED) { s, p -> return (args1.asSequence() zip args2.asSequence()).fold(MATCHED) { s, p ->
val (arg1, arg2) = p val (arg1, arg2) = p
s and when { s and when {
arg1 == arg2 -> MATCHED arg1 == arg2 -> MATCHED
arg1 == null || arg2 == null -> UNMATCHED arg1 == null || arg2 == null -> UNMATCHED
else -> (arg1.getArguments().sequence() zip arg2.getArguments().sequence()).fold(MATCHED) { s, p -> else -> (arg1.getArguments().asSequence() zip arg2.getArguments().asSequence()).fold(MATCHED) { s, p ->
s and matchArguments(p.first, p.second) s and matchArguments(p.first, p.second)
} }
} }
@@ -737,7 +737,7 @@ public class JetPsiUnifier(
val patternElements = pattern.elements val patternElements = pattern.elements
if (targetElements.size() != patternElements.size()) return UNMATCHED if (targetElements.size() != patternElements.size()) return UNMATCHED
return (targetElements.sequence() zip patternElements.sequence()).fold(MATCHED) { s, p -> return (targetElements.asSequence() zip patternElements.asSequence()).fold(MATCHED) { s, p ->
if (s != UNMATCHED) s and doUnify(p.first, p.second) else s if (s != UNMATCHED) s and doUnify(p.first, p.second) else s
} }
} }
+1 -1
View File
@@ -183,7 +183,7 @@ private fun RegExp.findNext(input: String, from: Int): MatchResult? {
override fun contains(o: Any?): Boolean = this.any { it == o } override fun contains(o: Any?): Boolean = this.any { it == o }
override fun containsAll(c: Collection<Any?>): Boolean = c.all({contains(it)}) override fun containsAll(c: Collection<Any?>): Boolean = c.all({contains(it)})
override fun iterator(): Iterator<MatchGroup?> = indices.sequence().map { this[it] }.iterator() override fun iterator(): Iterator<MatchGroup?> = indices.asSequence().map { this[it] }.iterator()
override fun get(index: Int): MatchGroup? = match[index]?.let { MatchGroup(it) } override fun get(index: Int): MatchGroup? = match[index]?.let { MatchGroup(it) }
} }
@@ -234,7 +234,7 @@ private fun Matcher.findNext(from: Int): MatchResult? {
override fun contains(o: Any?): Boolean = o is MatchGroup? && this.any({ it == o }) override fun contains(o: Any?): Boolean = o is MatchGroup? && this.any({ it == o })
override fun containsAll(c: Collection<Any?>): Boolean = c.all({contains(it)}) override fun containsAll(c: Collection<Any?>): Boolean = c.all({contains(it)})
override fun iterator(): Iterator<MatchGroup?> = indices.sequence().map { this[it] }.iterator() override fun iterator(): Iterator<MatchGroup?> = indices.asSequence().map { this[it] }.iterator()
override fun get(index: Int): MatchGroup? { override fun get(index: Int): MatchGroup? {
val range = matchResult.range(index) val range = matchResult.range(index)
return if (range.start >= 0) return if (range.start >= 0)