[nullsafe] Log class hierarchy for file level analysis

Summary:
This will is useful for understanding and debugging file level analysis
flow.

Reviewed By: jvillard

Differential Revision: D21449240

fbshipit-source-id: 7c259674b
master
Mitya Lyubarskiy 5 years ago committed by Facebook GitHub Bot
parent 26c8b58054
commit bb37447bd5

@ -6,6 +6,7 @@
*)
open! IStd
module F = Format
module ClassInfo = struct
type t =
@ -59,6 +60,26 @@ module ClassInfo = struct
List.map t.nested_classes_info ~f:get_recursive_summaries |> List.concat
in
this_summaries @ nested_summaries @ anonymous_summaries
let rec pp fmt class_info =
let pp_anonymous fmt (class_name, summaries) =
F.fprintf fmt "Class name: %a, Summaries: %d" JavaClassName.pp class_name
(List.length summaries)
in
let pp_list fmt items ~pp =
if List.is_empty items then F.fprintf fmt "<empty>"
else List.iter items ~f:(F.fprintf fmt "%a@\n" pp)
in
let pp_content fmt {summaries; nested_anonymous_classes; nested_classes_info} =
F.fprintf fmt
"Summaries: %d@\nNested anonymous classes:@\n @[%a@]@\nNested classes:@\n @[%a@]"
(List.length summaries) (pp_list ~pp:pp_anonymous)
(JavaClassName.Map.bindings nested_anonymous_classes)
(pp_list ~pp) nested_classes_info
in
F.fprintf fmt "Class name: %a@\n @[%a@]" JavaClassName.pp class_info.class_name pp_content
class_info
end
(* If key (class_name) was not in the map yet, add it, otherwise modify the existing value.

@ -27,6 +27,8 @@ module ClassInfo : sig
val get_recursive_summaries : t -> (JavaClassName.t * NullsafeSummary.t) list
(** A flattened list of all summaries, user-level, nested, and anonymous, combined together *)
val pp : Format.formatter -> t -> unit
end
val aggregate : (JavaClassName.t * NullsafeSummary.t) list -> ClassInfo.t list

@ -47,7 +47,15 @@ let analyze_top_level_class tenv source_file issue_log top_level_class_info =
let analyze_file ({InterproceduralAnalysis.file_exe_env; source_file} as analysis_data) =
Logging.debug Analysis Medium "Starting file level analysis of %a@\n" SourceFile.pp source_file ;
let all_summaries = get_summaries analysis_data in
let tenv = Exe_env.load_java_global_tenv file_exe_env in
let top_level_classes = AggregatedSummaries.aggregate all_summaries in
List.iter top_level_classes ~f:(fun top_level_class ->
Logging.debug Analysis Medium "Hierarchy for a top level class:@\n%a@\n"
AggregatedSummaries.ClassInfo.pp top_level_class ) ;
let issue_log =
List.fold top_level_classes ~init:IssueLog.empty ~f:(analyze_top_level_class tenv source_file)
in
Logging.debug Analysis Medium "Finished file level analysis of %a@\n" SourceFile.pp source_file ;
issue_log

Loading…
Cancel
Save