Skip to content

Commit

Permalink
Merge pull request #23 from mads379/1001621-record-occurrences-in-str…
Browse files Browse the repository at this point in the history
…ing-interpolation

1001621 Improved tree traversal
  • Loading branch information
dragos committed Apr 9, 2013
2 parents 00576d1 + e9b0883 commit 7194925
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,18 @@ class OccurrenceCollectorTest {
}
}

@Test def stringInterpolation() {
doWithOccurrencesInUnit("org","example","StringInterpolation.scala") { occurrences =>
val x = occurrenceFor("x", occurrences)
assertEquals("Should be 2 occurrences of x %s".format(x), 2, x.size)
}
}

@Test def annotationsOnMethods() {
doWithOccurrencesInUnit("org","example", "Annotations.scala") { occurrences =>
val x = occurrenceFor("IOException", occurrences)
assertEquals("Should be 1 occurrences of IOException %s".format(x), 1, x.size)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example

import java.io.IOException

object Test {
@throws(classOf[IOException]) def test() = {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example

object StringInterpolation {
def foo(x: String) = s"Hi there, ${x}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ object OccurrenceCollector extends HasLogger {

case Select(rest,name) if !isSynthetic(pc)(t, name.toString) =>
occurrences += Occurrence(name.toString, file, t.pos.point, Reference)
super.traverse(rest) // recurse in the case of chained selects: foo.baz.bar
traverse(rest) // recurse in the case of chained selects: foo.baz.bar

// Method definitions
case DefDef(_, name, _, _, _, body) if !isSynthetic(pc)(t, name.toString) =>
case DefDef(mods, name, _, args, _, body) if !isSynthetic(pc)(t, name.toString) =>
occurrences += Occurrence(name.toString, file, t.pos.point, Declaration)
super.traverse(body)
traverseTrees(mods.annotations)
traverseTreess(args)
traverse(body)

case _ => super.traverse(t)
// Val's and arguments.
case ValDef(_, name, tpt, rhs) =>
occurrences += Occurrence(name.toString, file, t.pos.point, Declaration)
traverse(tpt)
traverse(rhs)

case _ =>
super.traverse(t)
}
}
}
Expand Down

0 comments on commit 7194925

Please sign in to comment.