Compiler&plugin deprecations cleanup: replace streams with sequences.

This commit is contained in:
Ilya Gorbunov
2015-06-25 21:09:30 +03:00
parent 5779b89ff0
commit 86f4a1b6e4
18 changed files with 34 additions and 34 deletions
@@ -41,7 +41,7 @@ public object CodegenUtilKt {
): Map<CallableMemberDescriptor, CallableDescriptor> {
if (delegateExpressionType?.isDynamic() ?: false) return mapOf();
return descriptor.getDefaultType().getMemberScope().getDescriptors().stream()
return descriptor.getDefaultType().getMemberScope().getDescriptors().asSequence()
.filterIsInstance<CallableMemberDescriptor>()
.filter { it.getKind() == CallableMemberDescriptor.Kind.DELEGATION }
.toList()
@@ -153,7 +153,7 @@ trait SourceMapper {
fun createFromSmap(smap: SMAP): DefaultSourceMapper {
val sourceMapper = DefaultSourceMapper(smap.sourceInfo, null)
smap.fileMappings.stream()
smap.fileMappings.asSequence()
//default one mapped through sourceInfo
.filterNot { it == smap.default }
.forEach { fileMapping ->
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.codegen.SourceInfo
class SMAPAndMethodNode(val node: MethodNode, val classSMAP: SMAP) {
val lineNumbers =
InsnSequence(node.instructions.getFirst(), null).stream().filterIsInstance<LineNumberNode>().map {
InsnSequence(node.instructions.getFirst(), null).filterIsInstance<LineNumberNode>().map {
val index = Collections.binarySearch(classSMAP.intervals, RangeMapping(it.line, it.line, 1)) {
value, key ->
if (value.contains(key.dest)) 0 else RangeMapping.Comparator.compare(value, key)
@@ -39,7 +39,7 @@ class SMAPAndMethodNode(val node: MethodNode, val classSMAP: SMAP) {
LabelAndMapping(it, classSMAP.intervals[index])
}.toList()
val ranges = lineNumbers.stream().map { it.mapper }.toList().distinct().toList();
val ranges = lineNumbers.asSequence().map { it.mapper }.distinct().toList();
}
class LabelAndMapping(val lineNumberNode: LineNumberNode, val mapper: RangeMapping)
@@ -44,7 +44,7 @@ class AllUnderImportsScope : JetScope {
}
override fun getClassifier(name: Name): ClassifierDescriptor? {
return scopes.stream().map { it.getClassifier(name) }.filterNotNull().singleOrNull()
return scopes.asSequence().map { it.getClassifier(name) }.filterNotNull().singleOrNull()
}
override fun getProperties(name: Name): Collection<VariableDescriptor> {
@@ -84,7 +84,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
// neither objects nor enum members can be in java package
if (!kindFilter.acceptsKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)) return listOf()
return jPackage.getClasses(nameFilter).stream()
return jPackage.getClasses(nameFilter).asSequence()
.filter { c -> c.getOriginKind() != JavaClass.OriginKind.KOTLIN_LIGHT_CLASS }
.map { c -> c.getName() }.toList()
}
@@ -44,8 +44,8 @@ open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember
memberFilter(m) && !DescriptorResolverUtils.isObjectMethodInInterface(m)
}
private val methods = jClass.getMethods().stream().filter(methodFilter).groupBy { m -> m.getName() }
private val fields = jClass.getFields().stream().filter(memberFilter).valuesToMap { m -> m.getName() }
private val methods = jClass.getMethods().asSequence().filter(methodFilter).groupBy { m -> m.getName() }
private val fields = jClass.getFields().asSequence().filter(memberFilter).valuesToMap { m -> m.getName() }
override fun findMethodsByName(name: Name): Collection<JavaMethod> = methods[name] ?: listOf()
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> = jClass.getAllMemberNames(methodFilter) { getMethods() }
@@ -34,7 +34,7 @@ public class ReflectJavaClass(
override val modifiers: Int get() = klass.getModifiers()
override fun getInnerClasses() = klass.getDeclaredClasses()
.stream()
.asSequence()
.filterNot {
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are in fact
// anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private nested class
@@ -58,7 +58,7 @@ public class ReflectJavaClass(
}
override fun getMethods() = klass.getDeclaredMethods()
.stream()
.asSequence()
.filter { method ->
when {
method.isSynthetic() -> false
@@ -78,13 +78,13 @@ public class ReflectJavaClass(
}
override fun getFields() = klass.getDeclaredFields()
.stream()
.asSequence()
.filter { field -> !field.isSynthetic() }
.map(::ReflectJavaField)
.toList()
override fun getConstructors() = klass.getDeclaredConstructors()
.stream()
.asSequence()
.filter { constructor -> !constructor.isSynthetic() }
.map(::ReflectJavaConstructor)
.toList()
@@ -26,7 +26,7 @@ public class PackageFragmentProviderImpl(
packageFragments.filter { it.fqName == fqName }
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> =
packageFragments.stream()
packageFragments.asSequence()
.map { it.fqName }
.filter { !it.isRoot() && it.parent() == fqName }
.toList()
@@ -27,7 +27,7 @@ public fun <T> T.singletonList(): List<T> = Collections.singletonList(this)
public fun <T: Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) Collections.singleton(this) else Collections.emptySet()
public inline fun <reified T : Any> Stream<*>.firstIsInstanceOrNull(): T? {
public inline fun <reified T : Any> Sequence<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}
@@ -42,7 +42,7 @@ public inline fun <reified T : Any> Array<*>.firstIsInstanceOrNull(): T? {
return null
}
public inline fun <reified T> Stream<*>.firstIsInstance(): T {
public inline fun <reified T> Sequence<*>.firstIsInstance(): T {
for (element in this) if (element is T) return element
throw NoSuchElementException("No element of given type found")
}
@@ -73,7 +73,7 @@ public inline fun <reified T : Any> Iterable<*>.lastIsInstanceOrNull(): T? {
}
}
public fun <T> streamOfLazyValues(vararg elements: () -> T): Stream<T> = elements.stream().map { it() }
public fun <T> sequenceOfLazyValues(vararg elements: () -> T): Sequence<T> = elements.asSequence().map { it() }
public fun <T1, T2> Pair<T1, T2>.swap(): Pair<T2, T1> = Pair(second, first)
@@ -23,7 +23,7 @@ import java.util.HashSet
import java.util.Collections
import java.util.LinkedHashSet
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
public fun <K, V> Sequence<V>.valuesToMap(key: (V) -> K): Map<K, V> {
val map = LinkedHashMap<K, V>()
for (v in this) {
map[key(v)] = v
@@ -31,7 +31,7 @@ public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
return map
}
public fun <K, V> Stream<K>.keysToMap(value: (K) -> V): Map<K, V> {
public fun <K, V> Sequence<K>.keysToMap(value: (K) -> V): Map<K, V> {
val map = LinkedHashMap<K, V>()
for (k in this) {
map[k] = value(k)
@@ -39,7 +39,7 @@ public fun <K, V> Stream<K>.keysToMap(value: (K) -> V): Map<K, V> {
return map
}
public fun <K, V: Any> Stream<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
public fun <K, V: Any> Sequence<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
val map = LinkedHashMap<K, V>()
for (k in this) {
val v = value(k)
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.*
import java.util.*
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.utils.addToStdlib.streamOfLazyValues
import org.jetbrains.kotlin.utils.addToStdlib.sequenceOfLazyValues
public object DescriptorToSourceUtilsIde {
// Returns PSI element for descriptor. If there are many relevant elements (e.g. it is fake override
@@ -45,12 +45,12 @@ public object DescriptorToSourceUtilsIde {
return result.filter { element -> result.none { element != it && it.getNavigationElement() == element } }
}
private fun getDeclarationsStream(project: Project, targetDescriptor: DeclarationDescriptor): Stream<PsiElement> {
val effectiveReferencedDescriptors = DescriptorToSourceUtils.getEffectiveReferencedDescriptors(targetDescriptor).stream()
private fun getDeclarationsStream(project: Project, targetDescriptor: DeclarationDescriptor): Sequence<PsiElement> {
val effectiveReferencedDescriptors = DescriptorToSourceUtils.getEffectiveReferencedDescriptors(targetDescriptor).asSequence()
return effectiveReferencedDescriptors.flatMap { effectiveReferenced ->
// References in library sources should be resolved to corresponding decompiled declarations,
// therefore we put both source declaration and decompiled declaration to stream, and afterwards we filter it in getAllDeclarations
streamOfLazyValues(
sequenceOfLazyValues(
{ DescriptorToSourceUtils.getSourceFromDescriptor(effectiveReferenced) },
{ findBuiltinDeclaration(project, effectiveReferenced) ?: DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, effectiveReferenced) }
)
@@ -39,7 +39,7 @@ class KotlinOverrideTreeStructure(project: Project, val element: PsiElement) : H
}
return javaTreeStructures
.stream()
.asSequence()
.map (::buildChildrenByTreeStructure)
.reduce { a, b -> ContainerUtil.union(a.toSet(), b.toSet()).toTypedArray() }
}
@@ -203,7 +203,7 @@ fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
return extractionData
.originalRange
.match(scopeElement, unifier)
.stream()
.asSequence()
.filter { !(it.range.getTextRange() intersects originalTextRange) }
.map { match ->
val controlFlow = getControlFlowIfMatched(match)
@@ -248,7 +248,7 @@ private fun makeCall(
else -> calleeName
}
val anchorInBlock = stream(anchor) { it.getParent() }.firstOrNull { it.getParent() is JetBlockExpression }
val anchorInBlock = sequence(anchor) { it.getParent() }.firstOrNull { it.getParent() is JetBlockExpression }
val block = (anchorInBlock?.getParent() as? JetBlockExpression) ?: anchorParent
val psiFactory = JetPsiFactory(anchor.getProject())
@@ -107,7 +107,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
return searchInfo
}
fun findUsagesByJavaProcessor(elements: Stream<PsiElement>, insideDeleted: Condition<PsiElement>): Condition<PsiElement> =
fun findUsagesByJavaProcessor(elements: Sequence<PsiElement>, insideDeleted: Condition<PsiElement>): Condition<PsiElement> =
elements
.map { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() }
.filterNotNull()
@@ -116,7 +116,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
fun findUsagesByJavaProcessor(jetDeclaration: JetDeclaration): NonCodeUsageSearchInfo {
return NonCodeUsageSearchInfo(
findUsagesByJavaProcessor(
jetDeclaration.toLightElements().stream(),
jetDeclaration.toLightElements().asSequence(),
getIgnoranceCondition()
),
jetDeclaration
@@ -125,7 +125,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
fun findKotlinDeclarationUsages(declaration: JetDeclaration): NonCodeUsageSearchInfo {
ReferencesSearch.search(declaration, declaration.getUseScope())
.stream()
.asSequence()
.filterNot { reference -> getIgnoranceCondition().value(reference.getElement()) }
.mapTo(usages) { reference ->
reference.getElement().getNonStrictParentOfType<JetImportDirective>()?.let { importDirective ->
@@ -231,7 +231,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
if (declarationDescriptor !is CallableMemberDescriptor) return null
return declarationDescriptor.getOverriddenDescriptors()
.stream()
.asSequence()
.filter { overridenDescriptor -> overridenDescriptor.getModality() == Modality.ABSTRACT }
.mapTo(ArrayList<String>()) { overridenDescriptor ->
JetBundle.message(
@@ -56,7 +56,7 @@ fun PsiElement.removeOverrideModifier() {
fun PsiMethod.cleanUpOverrides() {
val superMethods = findSuperMethods(true)
for (overridingMethod in OverridingMethodsSearch.search(this, true).findAll()) {
val currentSuperMethods = overridingMethod.findSuperMethods(true).stream() + superMethods.stream()
val currentSuperMethods = overridingMethod.findSuperMethods(true).asSequence() + superMethods.asSequence()
if (currentSuperMethods.all { superMethod -> superMethod.unwrapped == unwrapped }) {
overridingMethod.unwrapped?.removeOverrideModifier()
}
@@ -46,7 +46,7 @@ public open class KotlinDirectInheritorsSearcher() : QueryExecutorBase<PsiClass,
runReadAction {
val noLibrarySourceScope = JetSourceFilterScope.kotlinSourceAndClassFiles(scope, baseClass.getProject())
JetSuperClassIndex.getInstance().get(name, baseClass.getProject(), noLibrarySourceScope).stream()
JetSuperClassIndex.getInstance().get(name, baseClass.getProject(), noLibrarySourceScope).asSequence()
.map { candidate -> JetSourceNavigationHelper.getOriginalPsiClassOrCreateLightClass(candidate)}
.filterNotNull()
.filter { candidate -> candidate.isInheritor(baseClass, false) }
@@ -113,7 +113,7 @@ private fun getDefaultParamsNames(
): Set<JsName> {
val argsParams = args.zipWithDefault(params, Namer.UNDEFINED_EXPRESSION)
val relevantParams = argsParams.stream()
val relevantParams = argsParams.asSequence()
.filter { it.second.hasDefaultValue }
.filter { initialized == !isUndefined(it.first) }
@@ -32,7 +32,7 @@ public fun <T> Collection<T>.toIdentitySet(): MutableSet<T> {
return result
}
public fun <T> Stream<T>.toIdentitySet(): MutableSet<T> {
public fun <T> Sequence<T>.toIdentitySet(): MutableSet<T> {
val result = IdentitySet<T>()
for (element in this) {
result.add(element)