Add Hh_prelude to src/naming
[hiphop-php.git] / hphp / hack / src / naming / naming_attributes_deprecated.ml
blobfe22618804da0e5bbe958d11394a9117b315fbbd
1 (*
2 * Copyright (c) Facebook, Inc. and its affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the "hack" directory of this source tree.
7 *)
9 open Hh_prelude
10 module SN = Naming_special_names
12 (* TODO: generalize the arity check / argument check here to handle attributes
13 * in general, not just __Deprecated *)
14 let deprecated ~kind (_, name) attrs =
15 let attr = Naming_attributes.find SN.UserAttributes.uaDeprecated attrs in
16 let open Aast in
17 match attr with
18 | Some { ua_name = _; ua_params = [msg] }
19 | Some { ua_name = _; ua_params = [msg; _] } ->
20 begin
21 match Nast_eval.static_string msg with
22 | Ok msg ->
23 let name = Utils.strip_ns name in
24 let deprecated_prefix =
25 Printf.sprintf "The %s %s is deprecated: " kind name
27 Some (deprecated_prefix ^ msg)
28 | Error p ->
29 Errors.attribute_param_type p "static string literal";
30 None
31 end
32 | Some { ua_name = (pos, _); ua_params = [] } ->
33 Errors.attribute_too_few_arguments pos SN.UserAttributes.uaDeprecated 1;
34 None
35 | Some { ua_name = (pos, _); ua_params = _ } ->
36 Errors.attribute_too_many_arguments pos SN.UserAttributes.uaDeprecated 2;
37 None
38 | None -> None