1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(* 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.
*)openCommonmoduleE=Entity_codemoduleG=Graph_code(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Extracing package/class definitions from a set of sources.
*)(*****************************************************************************)(* Helpers *)(*****************************************************************************)letgen_package_file_with_class_defsprxsg=letrecauxdepth((_str,kind)ascurrent)=letstr=Graph_code.shortname_of_nodecurrentinmatchkindwith|E.Class->pr(spf"%sclass %s {"(Common2.n_spacedepth)str);List.iter(aux(depth+2))(G.childrencurrentg);pr(spf"%s}"(Common2.n_spacedepth));|E.File->List.iter(auxdepth)(G.childrencurrentg)|E.Constant|E.Field->pr(spf"%sint %s;"(Common2.n_spacedepth)str);|E.Method|E.ClassConstant->()|_->()inList.iter(aux0)xs(*****************************************************************************)(* Main entry point *)(*****************************************************************************)letextract_from_sources~src~dstfiles=letg=Graph_code_java.build~verbose:false~only_defs:truesrcfilesinCommon.command2("mkdir -p "^dst);letrecauxcurrent=letxs=G.childrencurrentginletclasses_or_files=xs|>List.filter(function|_,E.Class->true|_,E.File->true|_->false)inletsubpackages=xs|>List.filter(function|_,E.Package->true|_->false)in(matchcurrent,classes_or_fileswith|_,[]->()|(str,E.Package),xs->letfilename=Filename.concatdst(str^".java")inpr2(spf"generating %s"filename);Common.with_open_outfilefilename(fun(pr,_chan)->letprs=pr(s^"\n")inpr(spf"package %s;"str);gen_package_file_with_class_defsprxsg)|_->());List.iterauxsubpackages;inauxG.root