LineNumbers for Lambda's #24480

This commit is contained in:
Josep Prat 2018-02-22 11:29:08 +01:00 committed by Johan Andrén
parent c15c22622e
commit 5040ce82f1
3 changed files with 19 additions and 9 deletions

View file

@ -40,6 +40,10 @@ class LineNumberSpec extends AkkaSpec {
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 19, 21))
}
"work for `def`" in {
LineNumbers(method("foo")) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 24, 26))
}
}
"writing Java" must {
@ -47,12 +51,12 @@ class LineNumberSpec extends AkkaSpec {
"work for small functions" in {
// 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 {
// 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 {

View file

@ -20,4 +20,9 @@ object LineNumberSpecCodeForScala {
case "a"
case "b"
}
def method(s: String) = () {
println(s)
Integer.parseInt(s)
}
}

View file

@ -3,10 +3,11 @@
*/
package akka.util
import java.io.DataInputStream
import scala.annotation.{ switch }
import java.io.{ DataInputStream, InputStream }
import java.lang.invoke.SerializedLambda
import scala.annotation.switch
import scala.util.control.NonFatal
import java.io.InputStream
/**
* This is a minimized byte-code parser that concentrates exclusively on line
@ -196,10 +197,10 @@ object LineNumbers {
val writeReplace = c.getDeclaredMethod("writeReplace")
writeReplace.setAccessible(true)
writeReplace.invoke(l) match {
// case serialized: SerializedLambda
// if (debug) println(s"LNB: found Lambda implemented in ${serialized.getImplClass}:${serialized.getImplMethodName}")
// Option(c.getClassLoader.getResourceAsStream(serialized.getImplClass + ".class"))
// .map(_ -> Some(serialized.getImplMethodName))
case serialized: SerializedLambda
if (debug) println(s"LNB: found Lambda implemented in ${serialized.getImplClass}:${serialized.getImplMethodName}")
Option(c.getClassLoader.getResourceAsStream(serialized.getImplClass + ".class"))
.map(_ -> Some(serialized.getImplMethodName))
case _ None
}
} catch {