- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Confusing LineNumberTables for case classes
Thu, 2010-09-02, 08:59
I have the following code in its own file:
------------------
case class A()
case class B()
case class C()
case class D()
case class E()
case class F()
------------------
I compile that code with debug information. This yields A.class,
A$.class, B.class, B$.class, etc. Then I print out the LineNumberTable
information for A.class, and I see:
Method: productIterator
line: 1
Method: productElements
line: 1
Method: hashCode
line: 1
Method: toString
line: 1
Method: equals
line: 1
Method: productPrefix
line: 1
Method: productArity
line: 1
Method: productElement
line: 1
Method: canEqual
line: 1
Method:
line: 1
Excellent. But, then I try B.class
Method: productIterator
line: 2
Method: productElements
line: 2
Method: hashCode
line: 2
Method: toString
line: 2
Method: equals
line: 2
line: 1
line: 2
Method: productPrefix
line: 2
Method: productArity
line: 2
Method: productElement
line: 2
Method: canEqual
line: 2
Method:
line: 2
Notice how the line #1 is now included under method 'equals'. Here's the
result for C.class:
Method: productIterator
line: 3
Method: productElements
line: 3
Method: hashCode
line: 3
Method: toString
line: 3
Method: equals
line: 3
line: 1
line: 3
Method: productPrefix
line: 3
Method: productArity
line: 3
Method: productElement
line: 3
Method: canEqual
line: 3
Method:
line: 3
The same continues for D,E,F. Can someone explain why this happens?
Thanks,
Aemon
p.s.
Here's my code for printing line number information ( I also tried bcel
and got the same result).
-------------------------
import java.io._
import org.objectweb.asm._
import org.objectweb.asm.commons.EmptyVisitor
object Main{
def main(args:Array[String]){
val fs = new FileInputStream(args(0))
val reader = new ClassReader(fs)
reader.accept(new EmptyVisitor() {
override def visitMethod(access: Int, name: String,
desc: String, signature: String,
exceptions: Array[String]): MethodVisitor = {
println("Method: " + name)
new EmptyVisitor() {
override def visitLineNumber(line: Int, start: Label) {
println(" line: " + line)
}
}
}
}, 0)
}
}
-----------------------------------------