[nullsafe] A helper function to extract outer class.

Summary: To be used in the next diff.

Reviewed By: artempyanykh

Differential Revision: D21228077

fbshipit-source-id: f4220f953
master
Mitya Lyubarskiy 5 years ago committed by Facebook GitHub Bot
parent d3ad7880b2
commit fccf66968f

@ -63,6 +63,10 @@ let is_int s =
with Failure _ -> false
let get_outer_class_name {package; classname} =
String.rsplit2 classname ~on:'$' |> Option.map ~f:(fun (outer, _) -> {package; classname= outer})
(* Strips $<int> suffixes from the class name, and return how many were stripped *)
let strip_anonymous_suffixes_if_present classname =
let rec strip_recursively classname nesting_level =

@ -31,6 +31,10 @@ val classname : t -> string
val is_external_via_config : t -> bool
(** Considered external based on config flags. *)
val get_outer_class_name : t -> t option
(** If this is an inner class, return the closest outer, e.g. A$B for A$B$C. None if the class is
outermost *)
val is_anonymous_inner_class_name : t -> bool
(** True if it is either "classic" anonymous Java class:
https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html, or a synthetic Java

@ -105,4 +105,18 @@ let test_anonymous =
~expected_classname:"SomeClass$NestedClass$AgainNestedClass"
let tests = "JavaClassNameTests" >::: [test_from_string; test_anonymous]
let test_outer =
"test_outer"
>:: fun _ ->
get_outer_class_name (make ~package:(Some "some.package") ~classname:"SomeClass") |> assert_none ;
get_outer_class_name (make ~package:(Some "some.package") ~classname:"SomeClass$NestedClass")
|> assert_some
|> assert_equal_to ~expected_package:(Some "some.package") ~expected_classname:"SomeClass" ;
get_outer_class_name
(make ~package:(Some "some.package") ~classname:"SomeClass$NestedClass$AnotherNested")
|> assert_some
|> assert_equal_to ~expected_package:(Some "some.package")
~expected_classname:"SomeClass$NestedClass"
let tests = "JavaClassNameTests" >::: [test_from_string; test_anonymous; test_outer]

Loading…
Cancel
Save