From e43090bdc24c4ea6aa955acf522d165b8ee7e9b8 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 27 Jul 2017 11:26:53 -0700 Subject: [PATCH] [java] translate `final` keyword as annotation Reviewed By: jeremydubreil Differential Revision: D5500344 fbshipit-source-id: d401c51 --- infer/src/IR/Annot.ml | 2 ++ infer/src/IR/Annot.mli | 5 ++++- infer/src/checkers/annotations.ml | 4 ++++ infer/src/checkers/annotations.mli | 2 ++ infer/src/java/jTransType.ml | 15 ++++++++------- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/infer/src/IR/Annot.ml b/infer/src/IR/Annot.ml index 171148f53..7b3d8f9e3 100644 --- a/infer/src/IR/Annot.ml +++ b/infer/src/IR/Annot.ml @@ -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 -> "_" diff --git a/infer/src/IR/Annot.mli b/infer/src/IR/Annot.mli index 187a16828..fe2f87f68 100644 --- a/infer/src/IR/Annot.mli +++ b/infer/src/IR/Annot.mli @@ -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. *) diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index 4b95748dc..da65cec47 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -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 diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 2db2fdded..f08d6afa4 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -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 diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index 74649c4e6..fad794c05 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -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)