package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file package_java.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(* Yoann Padioleau
 *
 * Copyright (C) 2012 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
 * license.txt for more details.
 *)
open Common

module G = Graph_code
module E = Entity_code

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

let (lookup_fully_qualified2: 
  Graph_code.graph -> string list -> Graph_code.node option) = 
 fun g xs ->
  let rec aux current xs =
    match xs with
    | [] -> Some current
    | x::xs ->
        let children = G.children current g in
        (* because have File intermediate (noisy) nodes *)
        let children = children +> List.map (fun child ->
          match child with
          | (_, E.File) -> G.children child g
          (* we prefer Package to Dir when we lookup, we don't want
           * The "multiple entities" warning when have both
           * a "net" package and "net" directory.
           *)
          | (_, E.Dir) -> []
          | _ -> [child]
        ) +> List.flatten
        in
        (* sanity check, quite expansive according to -profile *)
        Common.group_assoc_bykey_eff children +> List.iter (fun (k, xs) ->
          if List.length xs > 1 
             (* issue warnings lazily, only when the ambiguity concerns
              * something we are actually looking for 
              *) 
             && k =$= x
          then begin
            (* todo: this will be a problem when go from class-level
             * to method/field level dependencies
             *)
            pr2 "WARNING: multiple entities with same name";
            pr2_gen (k, xs);
          end
        );
        
        let str =
          match current with
          | ".", E.Dir -> x
          | s, _ -> s ^ "." ^ x
        in
        let new_current = 
          children +> Common.find_some_opt (fun (s2, kind) ->
            if str =$= s2
            then Some (s2, kind)
            else None
          ) in
        (match new_current with
        (* less: could return at least what we were able to resolve *)
        | None -> None
        | Some current -> aux current xs
        )
  in
  aux G.root xs
OCaml

Innovation. Community. Security.