java-callgraph

Support native methods when resolving dynamic calls ref:

10/24/2018 4:51:25 AM

Details

diff --git a/src/main/java/gr/gousiosg/javacg/stat/DynamicCallManager.java b/src/main/java/gr/gousiosg/javacg/stat/DynamicCallManager.java
index 3da426a..2c4e881 100644
--- a/src/main/java/gr/gousiosg/javacg/stat/DynamicCallManager.java
+++ b/src/main/java/gr/gousiosg/javacg/stat/DynamicCallManager.java
@@ -70,7 +70,7 @@ public class DynamicCallManager {
      * @see #linkCalls(Method)
      */
     public void retrieveCalls(Method method, JavaClass jc) {
-        if (method.isAbstract()) {
+        if (method.isAbstract() || method.isNative()) {
             // No code to consider
             return;
         }
diff --git a/src/test/resources/gr/gousiosg/javacg/native.feature b/src/test/resources/gr/gousiosg/javacg/native.feature
new file mode 100644
index 0000000..877a69c
--- /dev/null
+++ b/src/test/resources/gr/gousiosg/javacg/native.feature
@@ -0,0 +1,20 @@
+#Author: matthieu.vergne@gmail.com
+Feature: Native
+  I want to identify all native methods within the analyzed code.
+
+  Scenario: Retrieve native method call
+    Given I have the class "NativeTest" with code:
+      """
+      public class NativeTest {
+       public void methodA() {
+        methodB();
+       }
+
+       public native void methodB();
+      }
+      """
+    When I run the analyze
+    Then the result should contain:
+      """
+      M:NativeTest:methodA() (M)NativeTest:methodB()
+      """
\ No newline at end of file