Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Dinduks/Mireille
base: 8f548c77e1
...
head fork: Dinduks/Mireille
compare: 82406c0a22
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
23 src/main/scala/com/dindane/mireille/Reader.scala
@@ -0,0 +1,23 @@
+package main.scala.com.dindane.mireille
+
+import models.InvokeVirtualCall
+import java.io.InputStream
+import java.nio.file.{StandardOpenOption, Files, Path}
+import org.objectweb.asm.ClassReader
+import visitors.InvokeVirtualVisitor
+
+object Reader {
+
+ def getInvokeVirtualCalls(is: InputStream): Seq[InvokeVirtualCall] = {
+ val classReader: ClassReader = new ClassReader(is)
+ val invokeVirtualVisitor = new InvokeVirtualVisitor(classReader.getClassName)
+ classReader.accept(invokeVirtualVisitor, 0)
+
+ invokeVirtualVisitor.invokeVirtualCalls
+ }
+
+ def getInvokeVirtualCalls(path: Path): Seq[InvokeVirtualCall] = {
+ getInvokeVirtualCalls(Files.newInputStream(path, StandardOpenOption.READ))
+ }
+
+}
View
13 src/main/scala/com/dindane/mireille/models/InvokeVirtualCall.scala
@@ -0,0 +1,13 @@
+package main.scala.com.dindane.mireille.models
+
+import org.objectweb.asm.Type
+
+case class InvokeVirtualCall(
+ className: String,
+ methodName: String,
+ owner: String,
+ arguments: Seq[Type],
+ returnType: Type,
+ file: String,
+ lineNumber: Int
+)
View
27 src/main/scala/com/dindane/mireille/visitors/InvokeVirtualVisitor.scala
@@ -0,0 +1,27 @@
+package main.scala.com.dindane.mireille.visitors
+
+import collection._
+import org.objectweb.asm._
+import main.scala.com.dindane.mireille.models.InvokeVirtualCall
+
+class InvokeVirtualVisitor(className: String) extends ClassVisitor(Opcodes.ASM4) {
+
+ val invokeVirtualCalls: mutable.MutableList[InvokeVirtualCall] = mutable.MutableList.empty
+
+ 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)) {
+ override def visitMethodInsn(opcode: Int, owner: String, name: String, description: String) = {
+ if (opcode == Opcodes.INVOKEVIRTUAL) {
+ invokeVirtualCalls += InvokeVirtualCall(className,
+ name,
+ owner,
+ Type.getArgumentTypes(description),
+ Type.getReturnType(description),
+ "",
+ 0)
+ }
+ }
+ }
+ }
+
+}
View
46 src/test/scala/com/dindane/mireille/ReaderSpec.scala
@@ -0,0 +1,46 @@
+package test.scala.com.dindane.mireille
+
+import org.specs2.mutable._
+import java.nio.file._
+import main.scala.com.dindane.mireille.Reader
+import org.objectweb.asm.Type
+
+
+class ReaderSpec extends Specification {
+ "Reader.getInvokeVirtualInfo" should {
+ "return a Seq whose size is the number of INVOKEVIRTUAL calls" in {
+ val path: Path = Paths.get(System.getProperty("user.dir"))
+ .resolve("src/test/scala/com/dindane/mireille/resources/A.class")
+ val invokeVirtualCalls = Reader.getInvokeVirtualCalls(path)
+
+ invokeVirtualCalls must be size(4)
+ }
+
+ "return InvokeVirtualCall objects with the correct information" in {
+ val path: Path = Paths.get(System.getProperty("user.dir"))
+ .resolve("src/test/scala/com/dindane/mireille/resources/A.class")
+ val invokeVirtualCalls = Reader.getInvokeVirtualCalls(path)
+
+ invokeVirtualCalls(0).className must_== "foo/A"
+ 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(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(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(3).methodName must_== "toString"
+ invokeVirtualCalls(3).returnType.getInternalName must_== "java/lang/String"
+ invokeVirtualCalls(3).owner must_== "java/lang/Object"
+ }
+ }
+}
View
19 src/test/scala/com/dindane/mireille/SampleSpec.scala
@@ -1,19 +0,0 @@
-package test.scala.com.dindane.mireille.SampleSpec
-
-import org.specs2.mutable._
-
-class SampleSpec extends Specification {
-
- "The 'Hello world' string" should {
- "contain 11 characters" in {
- "Hello world" must have size(11)
- }
- "start with 'Hello'" in {
- "Hello world" must startWith("Hello")
- }
- "end with 'world'" in {
- "Hello world" must endWith("world")
- }
- }
-
-}
View
BIN  src/test/scala/com/dindane/mireille/resources/A.class
Binary file not shown
View
23 src/test/scala/com/dindane/mireille/resources/main.java
@@ -0,0 +1,23 @@
+package foo;
+
+class A {
+ public String foo = bar("hello");
+
+ public void main (String [] args)
+ {
+ B b = new B();
+ b.foo(1, 2.0F);
+ bar("hello again");
+ }
+
+ public String bar(String baz) {
+ this.toString();
+ return baz;
+ }
+}
+
+class B {
+ public boolean foo(int i, float j) {
+ return true;
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.