LineNumbers for Lambda's #24480
This commit is contained in:
parent
c15c22622e
commit
5040ce82f1
3 changed files with 19 additions and 9 deletions
|
|
@ -40,6 +40,10 @@ class LineNumberSpec extends AkkaSpec {
|
||||||
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 19, 21))
|
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 19, 21))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"work for `def`" in {
|
||||||
|
LineNumbers(method("foo")) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 24, 26))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"writing Java" must {
|
"writing Java" must {
|
||||||
|
|
@ -47,12 +51,12 @@ class LineNumberSpec extends AkkaSpec {
|
||||||
|
|
||||||
"work for small functions" in {
|
"work for small functions" in {
|
||||||
// because how java Lambdas are implemented/designed
|
// because how java Lambdas are implemented/designed
|
||||||
LineNumbers(l.f1()) should ===(NoSourceInfo)
|
LineNumbers(l.f1()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 19, 19))
|
||||||
}
|
}
|
||||||
|
|
||||||
"work for larger functions" in {
|
"work for larger functions" in {
|
||||||
// because how java Lambdas are implemented/designed
|
// because how java Lambdas are implemented/designed
|
||||||
LineNumbers(l.f2()) should ===(NoSourceInfo)
|
LineNumbers(l.f2()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 24, 25))
|
||||||
}
|
}
|
||||||
|
|
||||||
"work for anonymous classes" in {
|
"work for anonymous classes" in {
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,9 @@ object LineNumberSpecCodeForScala {
|
||||||
case "a" ⇒
|
case "a" ⇒
|
||||||
case "b" ⇒
|
case "b" ⇒
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def method(s: String) = () ⇒ {
|
||||||
|
println(s)
|
||||||
|
Integer.parseInt(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@
|
||||||
*/
|
*/
|
||||||
package akka.util
|
package akka.util
|
||||||
|
|
||||||
import java.io.DataInputStream
|
import java.io.{ DataInputStream, InputStream }
|
||||||
import scala.annotation.{ switch }
|
import java.lang.invoke.SerializedLambda
|
||||||
|
|
||||||
|
import scala.annotation.switch
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
import java.io.InputStream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a minimized byte-code parser that concentrates exclusively on line
|
* This is a minimized byte-code parser that concentrates exclusively on line
|
||||||
|
|
@ -196,10 +197,10 @@ object LineNumbers {
|
||||||
val writeReplace = c.getDeclaredMethod("writeReplace")
|
val writeReplace = c.getDeclaredMethod("writeReplace")
|
||||||
writeReplace.setAccessible(true)
|
writeReplace.setAccessible(true)
|
||||||
writeReplace.invoke(l) match {
|
writeReplace.invoke(l) match {
|
||||||
// case serialized: SerializedLambda ⇒
|
case serialized: SerializedLambda ⇒
|
||||||
// if (debug) println(s"LNB: found Lambda implemented in ${serialized.getImplClass}:${serialized.getImplMethodName}")
|
if (debug) println(s"LNB: found Lambda implemented in ${serialized.getImplClass}:${serialized.getImplMethodName}")
|
||||||
// Option(c.getClassLoader.getResourceAsStream(serialized.getImplClass + ".class"))
|
Option(c.getClassLoader.getResourceAsStream(serialized.getImplClass + ".class"))
|
||||||
// .map(_ -> Some(serialized.getImplMethodName))
|
.map(_ -> Some(serialized.getImplMethodName))
|
||||||
case _ ⇒ None
|
case _ ⇒ None
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue