Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support reading the line number for Reader.getInvokeVirtualCalls

  • Loading branch information...
commit 4d93c1afd683e40808dfb91c2ecf2d0de788f416 1 parent 3b0c556
@Dinduks authored
View
12 src/main/scala/com/dindane/mireille/visitors/InvokeVirtualVisitor.scala
@@ -15,6 +15,14 @@ class InvokeVirtualVisitor(className: String) extends ClassVisitor(Opcodes.ASM4)
override def visitMethod(access: Int, name: String, description: String, signature: String, exceptions: Array[String]): MethodVisitor = {
new MethodVisitor(Opcodes.ASM4, super.visitMethod(access, name, description, signature, exceptions)) {
+ private var lineNumber: Option[Int] = None
+
+ override def visitLineNumber(line: Int, startLabel: Label) {
+ lineNumber = Some(line)
+
+ super.visitLineNumber(line, startLabel)
+ }
+
override def visitMethodInsn(opcode: Int, owner: String, name: String, description: String) = {
if (opcode == Opcodes.INVOKEVIRTUAL) {
invokeVirtualCalls += InvokeVirtualCall(className,
@@ -23,8 +31,10 @@ class InvokeVirtualVisitor(className: String) extends ClassVisitor(Opcodes.ASM4)
Type.getArgumentTypes(description),
Type.getReturnType(description),
fileName.getOrElse(""),
- 0)
+ lineNumber.getOrElse(0))
}
+
+ super.visitMethodInsn(opcode, owner, name, description)
}
}
}
View
4 src/test/scala/com/dindane/mireille/ReaderSpec.scala
@@ -28,21 +28,25 @@ class ReaderSpec extends Specification {
invokeVirtualCalls(0).arguments(0).getInternalName must_== "java/lang/String"
invokeVirtualCalls(0).returnType.getInternalName must_== "java/lang/String"
invokeVirtualCalls(0).owner must_== "foo/A"
+ invokeVirtualCalls(0).lineNumber must_== 4
invokeVirtualCalls(1).methodName must_== "foo"
invokeVirtualCalls(1).arguments(0) must_== Type.INT_TYPE
invokeVirtualCalls(1).arguments(1) must_== Type.FLOAT_TYPE
invokeVirtualCalls(1).returnType must_== Type.BOOLEAN_TYPE
invokeVirtualCalls(1).owner must_== "foo/B"
+ invokeVirtualCalls(1).lineNumber must_== 9
invokeVirtualCalls(2).methodName must_== "bar"
invokeVirtualCalls(2).arguments(0).getInternalName must_== "java/lang/String"
invokeVirtualCalls(2).returnType.getInternalName must_== "java/lang/String"
invokeVirtualCalls(2).owner must_== "foo/A"
+ invokeVirtualCalls(2).lineNumber must_== 10
invokeVirtualCalls(3).methodName must_== "toString"
invokeVirtualCalls(3).returnType.getInternalName must_== "java/lang/String"
invokeVirtualCalls(3).owner must_== "java/lang/Object"
+ invokeVirtualCalls(3).lineNumber must_== 14
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.