[java] translate `final` keyword as annotation

Reviewed By: jeremydubreil

Differential Revision: D5500344

fbshipit-source-id: d401c51
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent 7642d86c68
commit e43090bdc2

@ -23,6 +23,8 @@ type t =
let volatile = {class_name= "volatile"; parameters= []}
let final = {class_name= "final"; parameters= []}
(** Pretty print an annotation. *)
let prefix = match Config.curr_language_is Config.Java with true -> "@" | false -> "_"

@ -21,7 +21,10 @@ type t =
[@@deriving compare]
val volatile : t
(** annotation for fields/methods marked with the "volatile" keyword *)
(** annotation for fields marked with the "volatile" keyword *)
val final : t
(** annotation for fields marked with the "final" keyword *)
val pp : F.formatter -> t -> unit
(** Pretty print an annotation. *)

@ -33,6 +33,8 @@ let expensive = "Expensive"
let false_on_null = "FalseOnNull"
let final = "final"
let for_ui_thread = "ForUiThread"
let for_non_ui_thread = "ForNonUiThread"
@ -163,6 +165,8 @@ let field_has_annot fieldname (struct_typ: Typ.Struct.t) predicate =
let struct_typ_has_annot (struct_typ: Typ.Struct.t) predicate = predicate struct_typ.annots
let ia_is_final ia = ia_contains ia final
let ia_is_not_thread_safe ia = ia_ends_with ia not_thread_safe
let ia_is_propagates_nullable ia = ia_ends_with ia propagates_nullable

@ -84,6 +84,8 @@ val ia_is_verify : Annot.Item.t -> bool
val ia_is_expensive : Annot.Item.t -> bool
val ia_is_final : Annot.Item.t -> bool
val ia_is_functional : Annot.Item.t -> bool
val ia_is_performance_critical : Annot.Item.t -> bool

@ -226,17 +226,18 @@ let fieldname_create cn fs =
let classname = JBasics.cn_name cn in
Typ.Fieldname.Java.from_string (classname ^ "." ^ fieldname)
let create_sil_class_field cn cf =
let fs = cf.Javalib.cf_signature in
let field_name = fieldname_create cn fs
and field_type = get_named_type (JBasics.fs_type fs)
let create_sil_class_field cn {Javalib.cf_signature; cf_annotations; cf_kind} =
let field_name = fieldname_create cn cf_signature
and field_type = get_named_type (JBasics.fs_type cf_signature)
and annotation =
let real_annotations = JAnnotation.translate_item cf.Javalib.cf_annotations in
let real_annotations = JAnnotation.translate_item cf_annotations in
(* translate modifers like "volatile" as annotations *)
match cf.Javalib.cf_kind with
match cf_kind with
| Javalib.Volatile
-> (Annot.volatile, true) :: real_annotations
| Javalib.NotFinal | Final
| Javalib.Final
-> (Annot.final, true) :: real_annotations
| Javalib.NotFinal
-> real_annotations
in
(field_name, field_type, annotation)

Loading…
Cancel
Save