Permalink
Browse files

Change lineNumber's and file's signatures to Option[x]

  • Loading branch information...
1 parent 4d93c1a commit 19ecb82232f3d5ca5a1eb8f13b357d01e7b00d49 @Dinduks committed Mar 4, 2013
@@ -27,14 +27,17 @@ object Main {
println("No INVOKEVIRTUAL calls were found.")
println("Exiting.")
} else {
- println("=== INVOKEVIRTUAL calls in '%s', from '%s':".format(
- fileName, invokeVirtualCalls(0).file
+ println("=== INVOKEVIRTUAL calls in %s, from %s:".format(
+ fileName, invokeVirtualCalls(0).file.getOrElse("an unknown file")
))
invokeVirtualCalls.map { invokeVirtualCall =>
println()
println("Method name: %s".format(invokeVirtualCall.methodName))
println("Called on: %s".format(invokeVirtualCall.owner))
+ if (None != invokeVirtualCall.lineNumber) {
+ println("In line: %s".format(invokeVirtualCall.lineNumber.get))
+ }
println("Takes these arguments: %s".format(invokeVirtualCall.arguments.mkString(", ")))
println("Returns: %s".format(invokeVirtualCall.returnType))
}
@@ -8,6 +8,6 @@ case class InvokeVirtualCall(
owner: String,
arguments: Seq[Type],
returnType: Type,
- file: String,
- lineNumber: Int
+ file: Option[String],
+ lineNumber: Option[Int]
)
@@ -30,8 +30,8 @@ class InvokeVirtualVisitor(className: String) extends ClassVisitor(Opcodes.ASM4)
owner,
Type.getArgumentTypes(description),
Type.getReturnType(description),
- fileName.getOrElse(""),
- lineNumber.getOrElse(0))
+ fileName,
+ lineNumber)
}
super.visitMethodInsn(opcode, owner, name, description)
@@ -22,31 +22,31 @@ class ReaderSpec extends Specification {
val invokeVirtualCalls = Reader.getInvokeVirtualCalls(path)
invokeVirtualCalls(0).className must_== "foo/A"
- invokeVirtualCalls(0).file must_== "main.java"
+ invokeVirtualCalls(0).file.get must_== "main.java"
invokeVirtualCalls(0).methodName must_== "bar"
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(0).lineNumber.get 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(1).lineNumber.get 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(2).lineNumber.get 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
+ invokeVirtualCalls(3).lineNumber.get must_== 14
}
}
}

0 comments on commit 19ecb82

Please sign in to comment.