Skip to content
Browse files

[bytecode/java]: extract location information for nested and generic …

…classes

Test Plan:
included unit test
$ make test

Reviewers: pieter

Reviewed By: pieter

CC: subodh, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D654327
  • Loading branch information...
1 parent 13bb232 commit 4bec1244bb61c641df2415f91217b12e74e4c254 @aryx aryx committed
View
21 lang_bytecode/analyze/graph_code_bytecode.ml
@@ -201,6 +201,20 @@ let lookup g n s =
)
)
+let unmangle graph_java (full_str_bytecode_name, kind) =
+ let xs = Common.split "\\." full_str_bytecode_name in
+ let (package, bytecode_name_entity) =
+ (match List.rev xs with
+ | [] -> raise Impossible
+ | x::xs -> List.rev xs, x
+ )
+ in
+ let ys = Common.split "\\$" bytecode_name_entity in
+
+ let full_name = package ++ ys in
+ Common.join "." full_name, kind
+
+
(*****************************************************************************)
(* Defs *)
(*****************************************************************************)
@@ -214,12 +228,13 @@ let extract_defs ~g ~file ~graph_code_java ast =
g +> G.add_node node;
g +> G.add_edge (current, node) G.Has;
graph_code_java +> Common.do_option (fun g2 ->
+ let node' = unmangle g2 node in
try
- let nodeinfo = G.nodeinfo node g2 in
+ let nodeinfo = G.nodeinfo node' g2 in
g +> G.add_nodeinfo node nodeinfo
with Not_found ->
- pr2 (spf "could not find the corresponding nodeinfo in the java graph: %s"
- (G.string_of_node node))
+ pr2 (spf "could not find nodeinfo in the java graph of %s (guess was %s)"
+ (G.string_of_node node) (G.string_of_node node'))
);
let current = node in
View
9 lang_bytecode/analyze/unit_analyze_bytecode.ml
@@ -96,10 +96,17 @@ class Bar {
"Foo.java", " // line 1
// line 2
class Foo { // line 3
+ class NestedFoo { // line 4
+ }
}
";] in
assert_equal
- ["3"] (prolog_query ~files "at('Foo', _, X), writeln(X)")
+ ["3"] (prolog_query ~files "at('Foo', _, X), writeln(X)");
+ (* todo: at some point we need to also expose the original java entity
+ * name in the bytecode codegraph.
+ *)
+ assert_equal
+ ["4"] (prolog_query ~files "at('Foo\\$NestedFoo', _, X), writeln(X)");
);
])
View
2 tests/bytecode/codegraph/GenericClass.java
@@ -0,0 +1,2 @@
+class GenericClass<T> {
+}
View
2 tests/bytecode/codegraph/Makefile
@@ -1,4 +1,4 @@
-SRC=Clone.java TestException.java
+SRC=Clone.java TestException.java NestedClass.java GenericClass.java
OBJS=$(SRC:.java=.class)
View
8 tests/bytecode/codegraph/NestedClass.java
@@ -0,0 +1,8 @@
+class NestedClass {
+
+ class IndeedNestedClass {
+
+ class ReallyNestedClass {
+ }
+ }
+}

0 comments on commit 4bec124

Please sign in to comment.
Something went wrong with that request. Please try again.