Summary: Extract `Typ.Name.Java.Split` into a standalone module. - This module is really only used in `Procname` so no need to be in `Typ`. - Remove some pointless conversions to strings and back. - Reduce the interface of `Split` to the minimum ahead of possible removal in favour of normal types. Reviewed By: mityal Differential Revision: D20322887 fbshipit-source-id: 7963757cbmaster
parent
95807702fc
commit
711c48aa86
@ -0,0 +1,39 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
module F = Format
|
||||||
|
|
||||||
|
type t = {package: string option; type_name: string} [@@deriving compare, equal]
|
||||||
|
|
||||||
|
let make ?package type_name = {type_name; package}
|
||||||
|
|
||||||
|
(** Given a package.class_name string, it looks for the latest dot and split the string in two
|
||||||
|
(package, class_name) *)
|
||||||
|
let of_string package_classname =
|
||||||
|
match String.rsplit2 package_classname ~on:'.' with
|
||||||
|
| Some (package, type_name) ->
|
||||||
|
{type_name; package= Some package}
|
||||||
|
| None ->
|
||||||
|
{type_name= package_classname; package= None}
|
||||||
|
|
||||||
|
|
||||||
|
let package {package} = package
|
||||||
|
|
||||||
|
let type_name {type_name} = type_name
|
||||||
|
|
||||||
|
let java_lang_object = make ~package:"java.lang" "Object"
|
||||||
|
|
||||||
|
let java_lang_string = make ~package:"java.lang" "String"
|
||||||
|
|
||||||
|
let void = make "void"
|
||||||
|
|
||||||
|
let pp_type_verbosity ~verbose fmt = function
|
||||||
|
| {package= Some package; type_name} when verbose ->
|
||||||
|
F.fprintf fmt "%s.%s" package type_name
|
||||||
|
| {type_name} ->
|
||||||
|
F.pp_print_string fmt type_name
|
@ -0,0 +1,35 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
module F = Format
|
||||||
|
|
||||||
|
(** Module for representing a Java type. *)
|
||||||
|
|
||||||
|
type t [@@deriving compare, equal]
|
||||||
|
|
||||||
|
val make : ?package:string -> string -> t
|
||||||
|
|
||||||
|
val of_string : string -> t
|
||||||
|
(** Given a package.type_name string, it looks for the latest dot and splits the string in two
|
||||||
|
(package, rest-of-type-name). If there is no dot symbol, assumes the whole string is a type
|
||||||
|
name. NB the RHS is not just a classname, eg it can be an array type. *)
|
||||||
|
|
||||||
|
val java_lang_object : t
|
||||||
|
(** [java.lang.Object] type *)
|
||||||
|
|
||||||
|
val java_lang_string : t
|
||||||
|
(** [java.lang.String] type *)
|
||||||
|
|
||||||
|
val void : t
|
||||||
|
(** Java [void] type *)
|
||||||
|
|
||||||
|
val package : t -> string option
|
||||||
|
|
||||||
|
val type_name : t -> string
|
||||||
|
|
||||||
|
val pp_type_verbosity : verbose:bool -> F.formatter -> t -> unit
|
Loading…
Reference in new issue