[Typ.name] Move a function to JavaClassName

Summary:
We try to consolidate Java-specific stuff in JavaClassName.
Let's introduce the function in JavaClassName and make it clear that
its analog in Typ.Name.Java one throws if called on a wrong type.

Reviewed By: ngorogiannis

Differential Revision: D20386357

fbshipit-source-id: a1577ef8b
master
Mitya Lyubarskiy 5 years ago committed by Facebook GitHub Bot
parent a4c3925d9a
commit 544e4f2e6c

@ -40,6 +40,20 @@ let package {package} = package
let classname {classname} = classname
let is_anonymous_inner_class_name {classname} =
match String.rsplit2 classname ~on:'$' with
| Some (_, s) ->
let is_int =
try
ignore (int_of_string (String.strip s)) ;
true
with Failure _ -> false
in
is_int
| None ->
false
let is_external_via_config t =
let package = package t in
Option.exists ~f:Config.java_package_is_external package

@ -24,3 +24,7 @@ val classname : t -> string
val is_external_via_config : t -> bool
(** Considered external based on config flags. *)
val is_anonymous_inner_class_name : t -> bool
(** True if it is anonymous Java class:
https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html *)

@ -171,8 +171,8 @@ module Java = struct
let is_constructor {method_name} = String.equal method_name constructor_method_name
let is_anonymous_inner_class_constructor {class_name} =
Typ.Name.Java.is_anonymous_inner_class_name class_name
let is_anonymous_inner_class_constructor_exn {class_name} =
Typ.Name.Java.is_anonymous_inner_class_name_exn class_name
let is_static {kind} = match kind with Static -> true | _ -> false

@ -69,8 +69,9 @@ module Java : sig
val is_autogen_method : t -> bool
(** Check if the procedure name is of an auto-generated method containing '$'. *)
val is_anonymous_inner_class_constructor : t -> bool
(** Check if the procedure name is an anonymous inner class constructor. *)
val is_anonymous_inner_class_constructor_exn : t -> bool
(** Check if the procedure name is an anonymous inner class constructor. Throws if it is not a
Java type *)
val is_close : t -> bool
(** Check if the method name is "close". *)

@ -475,20 +475,9 @@ module Name = struct
L.die InternalError "Tried to split a non-java class name into a java split type@."
let is_anonymous_inner_class_name class_name =
let is_anonymous_inner_class_name_exn class_name =
let java_class_name = get_java_class_name_exn class_name in
let class_name_no_package = JavaClassName.classname java_class_name in
match String.rsplit2 class_name_no_package ~on:'$' with
| Some (_, s) ->
let is_int =
try
ignore (int_of_string (String.strip s)) ;
true
with Failure _ -> false
in
is_int
| None ->
false
JavaClassName.is_anonymous_inner_class_name java_class_name
let is_external t =

@ -230,7 +230,8 @@ module Name : sig
val is_external : t -> bool
(** return true if the typename is in the .inferconfig list of external classes *)
val is_anonymous_inner_class_name : t -> bool
val is_anonymous_inner_class_name_exn : t -> bool
(** Throws if it is not a Java class *)
val java_lang_object : t

@ -1074,7 +1074,7 @@ let typecheck_sil_call_function find_canonical_duplicate checks tenv instr_ref t
drop_unchecked_signature_params callee_attributes callee_annotated_signature
in
let is_anonymous_inner_class_constructor =
Procname.Java.is_anonymous_inner_class_constructor callee_pname_java
Procname.Java.is_anonymous_inner_class_constructor_exn callee_pname_java
in
let do_return (ret_ta, ret_typ) typestate' =
let mk_return_range () = (ret_typ, ret_ta) in

Loading…
Cancel
Save