Iterators replaced with streams where appropriate

This commit is contained in:
Andrey Breslav
2014-04-29 15:51:16 +04:00
parent 19719f9747
commit c6bd4a22ef
11 changed files with 21 additions and 24 deletions
@@ -57,7 +57,7 @@ class KotlinOverrideTreeStructure(project: Project, val element: PsiElement) : H
}
return javaTreeStructures
.iterator()
.stream()
.map (::buildChildrenByTreeStructure)
.reduce { (a, b) -> ContainerUtil.union(a.toSet(), b.toSet()).copyToArray() }
}
@@ -265,7 +265,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(project: Project, val optio
}
getTransaction()!!.getElementListener(oldDeclaration).elementMoved(newDeclaration)
for ((oldElement, newElement) in oldLightElements.iterator() zip newDeclaration.toLightElements().iterator()) {
for ((oldElement, newElement) in oldLightElements.stream() zip newDeclaration.toLightElements().stream()) {
oldToNewElementsMapping[oldElement] = newElement
}
}
@@ -105,7 +105,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
return searchInfo
}
fun findUsagesByJavaProcessor(elements: Iterator<PsiElement>, insideDeleted: Condition<PsiElement>): Condition<PsiElement> =
fun findUsagesByJavaProcessor(elements: Stream<PsiElement>, insideDeleted: Condition<PsiElement>): Condition<PsiElement> =
elements
.map { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() }
.filterNotNull()
@@ -114,7 +114,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
fun findUsagesByJavaProcessor(jetDeclaration: JetDeclaration): NonCodeUsageSearchInfo {
return NonCodeUsageSearchInfo(
findUsagesByJavaProcessor(
jetDeclaration.toLightElements().iterator(),
jetDeclaration.toLightElements().stream(),
getIgnoranceCondition()
),
jetDeclaration
@@ -123,7 +123,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
fun findKotlinDeclarationUsages(declaration: JetDeclaration): NonCodeUsageSearchInfo {
ReferencesSearch.search(declaration, declaration.getUseScope())
.iterator()
.stream()
.filterNot { reference -> getIgnoranceCondition().value(reference.getElement()) }
.mapTo(usages) { reference ->
reference.getElement().getParentByType(javaClass<JetImportDirective>())?.let { importDirective ->
@@ -214,7 +214,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
if (declarationDescriptor !is CallableMemberDescriptor) return null
return declarationDescriptor.getOverriddenDescriptors()
.iterator()
.stream()
.filter { overridenDescriptor -> overridenDescriptor.getModality() == Modality.ABSTRACT }
.mapTo(ArrayList<String>()) { overridenDescriptor ->
JetBundle.message(
@@ -64,7 +64,7 @@ fun PsiElement.removeOverrideModifier() {
fun PsiMethod.cleanUpOverrides() {
val superMethods = findSuperMethods(true)
for (overridingMethod in OverridingMethodsSearch.search(this, true).findAll()) {
val currentSuperMethods = overridingMethod.findSuperMethods(true).iterator() + superMethods.iterator()
val currentSuperMethods = overridingMethod.findSuperMethods(true).stream() + superMethods.stream()
if (currentSuperMethods.all { superMethod -> superMethod.unwrapped == unwrapped }) {
overridingMethod.unwrapped?.removeOverrideModifier()
}
@@ -46,7 +46,7 @@ public open class KotlinDirectInheritorsSearcher() : QueryExecutorBase<PsiClass,
if (scope == null) return
ApplicationManager.getApplication()?.runReadAction {
JetSuperClassIndex.getInstance().get(name, baseClass.getProject(), scope).iterator()
JetSuperClassIndex.getInstance().get(name, baseClass.getProject(), scope).stream()
.map { candidate -> JetSourceNavigationHelper.getOriginalPsiClassOrCreateLightClass(candidate)}
.filterNotNull()
.filter { candidate -> candidate.isInheritor(baseClass, false) }