Permalink
Browse files

Merge pull request #23 from mads379/1001621-record-occurrences-in-str…

…ing-interpolation

1001621 Improved tree traversal
  • Loading branch information...
2 parents 00576d1 + e9b0883 commit 71949254cafb660169c4a576ed29e2fe248136b1 @dragos dragos committed Apr 9, 2013
@@ -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)
+ }
+ }
}
@@ -0,0 +1,7 @@
+package org.example
+
+import java.io.IOException
+
+object Test {
+ @throws(classOf[IOException]) def test() = {}
+}
@@ -0,0 +1,5 @@
+package org.example
+
+object StringInterpolation {
+ def foo(x: String) = s"Hi there, ${x}"
+}
@@ -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)
}
}
}

0 comments on commit 7194925

Please sign in to comment.