package pfff

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

Source file refactoring_code.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, 2013 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

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

(*****************************************************************************)
(* Types *)
(*****************************************************************************)


type refactoring_kind =
  | AddInterface of string option (* specific class *) 
                  * string (* the interface to add *)
  | RemoveInterface of string option * string

  | SplitMembers
  (* todo: Rename of entity * entity *)

  (* type related *)
  | AddReturnType of string
  | AddTypeHintParameter of string
  | OptionizeTypeParameter
  | AddTypeMember of string

type position = { 
  file: Common.filename;
  line: int;
  col: int;
}

type refactoring = refactoring_kind * position option

(*****************************************************************************)
(* IO *)
(*****************************************************************************)

(* format: file;RETURN;line;col;value *)
let load file =
  Common.cat file +> List.map (fun s ->
    let xs = Common.split ";" s in
    match xs with
    | [file;action;line;col;value] when
          line =~ "[0-9]+" && col =~ "[0-9]+" && 
          (List.mem action [
            "RETURN";"PARAM";"MEMBER"; "MAKE_OPTION_TYPE"; "SPLIT_MEMBERS";
          ]) ->
      (match action with
      | "RETURN" -> AddReturnType value
      | "PARAM" -> AddTypeHintParameter value
      | "MEMBER" -> AddTypeMember value
      | "MAKE_OPTION_TYPE" -> OptionizeTypeParameter
      | "SPLIT_MEMBERS" -> SplitMembers
      | _ -> raise Impossible
      ), Some 
        { file;
          line = int_of_string line;
          col = int_of_string col;
        }

    | _ -> failwith ("wrong format for refactoring action: " ^ s)
  )

OCaml

Innovation. Community. Security.