Permalink
Browse files

Fixed positions in named default applications (no hyperlinking in con…

…junction with implicit arguments).

Removed even more code in the presentation compiler testing infrastructure. One less level of indirection,
and a top-level object gone!
  • Loading branch information...
dragos committed May 8, 2012
1 parent f941025 commit 2e8029b127699ecd8ed1f55456faa345bd88c5ee
@@ -1,28 +0,0 @@
package scala.tools.nsc
package interactive
package tests.core
import scala.tools.nsc.util.Position
import scala.tools.nsc.util.SourceFile
/** Find occurrences of `text` in the passed `sources`. */
private[core] object FindOccurrences {
def apply(sources: Seq[SourceFile])(text: String): Map[SourceFile, Seq[Position]] =
allPositionsOf(sources, text)
/** All positions of the given string in all source files. */
private def allPositionsOf(sources: Seq[SourceFile], str: String): Map[SourceFile, Seq[Position]] =
(for (s <- sources; p <- positionsOf(s, str)) yield p).groupBy(_.source)
/** Return all positions of the given str in the given source file. */
private def positionsOf(source: SourceFile, str: String): Seq[Position] = {
val buf = new collection.mutable.ListBuffer[Position]
var pos = source.content.indexOfSlice(str)
while (pos >= 0) {
buf += source.position(pos - 1) // we need the position before the first character of this marker
pos = source.content.indexOfSlice(str, pos + 1)
}
buf.toList
}
}
@@ -16,7 +16,7 @@ trait PresentationCompilerRequestsWorkingMode extends TestResources {
* ask the type at all positions marked with `TypeMarker.marker` and println the result.
*/
private def askAllSourcesAsync[T](marker: TestMarker)(askAt: Position => Response[T])(f: (Position, T) => Unit) {
val positions = allPositionsOf(marker.marker).valuesIterator.toList.flatten
val positions = allPositionsOf(str = marker.marker)
val responses = for (pos <- positions) yield askAt(pos)
for ((pos, r) <- positions zip responses) withResponse(pos, r)(f)
@@ -26,13 +26,25 @@ trait PresentationCompilerRequestsWorkingMode extends TestResources {
* response before going to the next one.
*/
private def askAllSourcesSync[T](marker: TestMarker)(askAt: Position => Response[T])(f: (Position, T) => Unit) {
val positions = allPositionsOf(marker.marker).valuesIterator.toList.flatten
val positions = allPositionsOf(str = marker.marker)
for (pos <- positions) withResponse(pos, askAt(pos))(f)
}
private def allPositionsOf: String => Map[SourceFile, Seq[Position]] =
FindOccurrences(sourceFiles) _
/** All positions of the given string in all source files. */
private def allPositionsOf(srcs: Seq[SourceFile] = sourceFiles, str: String): Seq[Position] =
for (s <- srcs; p <- positionsOf(s, str)) yield p
/** Return all positions of the given str in the given source file. */
private def positionsOf(source: SourceFile, str: String): Seq[Position] = {
val buf = new collection.mutable.ListBuffer[Position]
var pos = source.content.indexOfSlice(str)
while (pos >= 0) {
buf += source.position(pos - 1) // we need the position before the first character of this marker
pos = source.content.indexOfSlice(str, pos + 1)
}
buf.toList
}
private def withResponse[T](pos: Position, response: Response[T])(f: (Position, T) => Unit) {
/** Return the filename:line:col version of this position. */
def showPos(pos: Position): String =
@@ -13,7 +13,7 @@ private[tests] object SourcesCollector {
* */
def apply(base: Path, filter: SourceFilter): Array[SourceFile] = {
assert(base.isDirectory)
base.walk.filter(filter).map(source).toArray
base.walk.filter(filter).map(source).toList.toArray.sortBy(_.file.name)
}
private def source(file: Path): SourceFile = source(AbstractFile.getFile(file.toFile))
@@ -338,7 +338,7 @@ trait NamesDefaults { self: Analyzer =>
// cannot call blockTyper.typedBlock here, because the method expr might be partially applied only
val res = blockTyper.doTypedApply(tree, expr, refArgs, mode, pt)
res.setPos(res.pos.makeTransparent)
val block = Block(stats ::: valDefs, res).setType(res.tpe).setPos(tree.pos)
val block = Block(stats ::: valDefs, res).setType(res.tpe).setPos(tree.pos.makeTransparent)
context.namedApplyBlockInfo =
Some((block, NamedApplyInfo(qual, targs, vargss :+ refArgs, blockTyper)))
block
@@ -1,4 +1,14 @@
reload: PatMatTests.scala
reload: NameDefaultTests.scala, PatMatTests.scala
askHyperlinkPos for `someOtherInt` at (14,24) NameDefaultTests.scala
================================================================================
[response] found askHyperlinkPos for `someOtherInt` at (12,9) NameDefaultTests.scala
================================================================================
askHyperlinkPos for `someString` at (14,45) NameDefaultTests.scala
================================================================================
[response] found askHyperlinkPos for `someString` at (3,7) NameDefaultTests.scala
================================================================================
askHyperlinkPos for `CaseOne` at (12,18) PatMatTests.scala
================================================================================
@@ -0,0 +1,16 @@
class NameDefaults {
val someString = "abc"
val someInt = 42
def foo(x: String, y: Int)(implicit logger: Int): Int = y
implicit val l = 42
def bar {
println()
val someOtherInt = 10
foo(y = someOtherInt/*#*/, x = someString/*#*/)
}
}

0 comments on commit 2e8029b

Please sign in to comment.