Shorten references: Group elements by file before applying transformation

This commit is contained in:
Alexey Sedunov
2014-02-12 20:16:02 +04:00
parent d2e6aa2aa5
commit 86619f5f28
@@ -27,19 +27,17 @@ public object ShortenReferences {
} }
public fun process(elements: Iterable<JetElement>) { public fun process(elements: Iterable<JetElement>) {
val first = elements.firstOrNull() for ((file, fileElements) in elements.groupBy { element -> element.getContainingFile() as JetFile }) {
if (first == null) return // first resolve all qualified references - optimization
val file = first.getContainingFile() as JetFile val resolveAllVisitor = ResolveAllReferencesVisitor(file)
processElements(fileElements, resolveAllVisitor)
// first resolve all qualified references - optimization val shortenTypesVisitor = ShortenTypesVisitor(file, resolveAllVisitor.result)
val resolveAllVisitor = ResolveAllReferencesVisitor(file) processElements(fileElements, shortenTypesVisitor)
processElements(elements, resolveAllVisitor) shortenTypesVisitor.finish()
val shortenTypesVisitor = ShortenTypesVisitor(file, resolveAllVisitor.result) processElements(fileElements, ShortenQualifiedExpressionsVisitor(file, resolveAllVisitor.result))
processElements(elements, shortenTypesVisitor) }
shortenTypesVisitor.finish()
processElements(elements, ShortenQualifiedExpressionsVisitor(file, resolveAllVisitor.result))
} }
private fun processElements(elements: Iterable<JetElement>, visitor: JetVisitorVoid) { private fun processElements(elements: Iterable<JetElement>, visitor: JetVisitorVoid) {