Changes between Version 5 and Version 6 of howto


Ignore:
Timestamp:
Aug 31, 2020, 2:41:29 AM (4 years ago)
Author:
tothm
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • howto

    v5 v6  
    4747 * This mode helps !RefactorErl to find the include files in the appropriate include folders. 
    4848 
     49= Using the tool 
     50!RefactorErl, as stated in its name, originally started as a refactoring project for Erlang. During the years of development, the focus of the project was shifted to the direction of code comprehension and software maintenance support. The main features of the tool are: 
     51 * Refactoring 
     52 * Semantic queries 
     53 * Dependency detection and visualisation  
     54 * Software complexity metrics 
     55 * Bad smell detection 
     56 * Checking design rules 
     57 * Vulnerability detection 
     58 * Clustering 
     59 * Duplicated code detection 
     60 * etc  
    4961 
     62= Demo 
    5063 
    51 = Using the web interface 
     64In the next examples we will use the source of the Mnesaia database as a target software.  
     65 * starting the tool: {{{bin/referl -db kcmini}}} 
     66 * building the database:  
     67{{{ 
     68Eshell V10.6.1  (abort with ^G) 
     69(refactorerl@localhost)1> ri:ls(). 
     70{{ok,[]},{error,[]}} 
     71ok 
     72(refactorerl@localhost)2> ri:envs(). 
     73output = original 
     74appbase = "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib" 
     75ok 
     76(refactorerl@localhost)3> ri:add(erlang, mnesia). 
     77Adding: /usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src 
     78| 5.20 kB/s >>>>>>>>>>>>>>>>>>>| [ 420/ 420] mnesia.erl 
     79| 6.78 kB/s >>>>>>>>>>>>>>>>>>>| [   5/   5] mnesia_app.erl 
     80| 8.12 kB/s >>>>>>>>>>>>>>>>>>>| [   3/   3] mnesia_backend_type.erl 
     81| 5.13 kB/s >>>>>>>>>>>>>>>>>>>| [  12/  12] mnesia_backup.erl 
     82|>>>>>>>>>>>>         6.05 kB/s| [  48/  87] mnesia_bup.erl 
     83.... 
     84(refactorerl@localhost)4> ri:ls(). 
     85{{ok,["/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_app.erl", 
     86      "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_controller.erl", 
     87      "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_ext_sup.erl", 
     88      "/usr/local/Cellar/erlang/22.2.1/lib/erlang/lib/mnesia-4.16.2/src/mnesia_frag_hash.erl", 
     89.... 
     90}}} 
     91 
     92{{{ri:ls()}}} checks the content of the database, so it lists the already analysed files.  
     93{{{ri:envs()}}} checks the environmental variables of !RefactorErl. You might realise that the path of the Erlang installation library was already set, so we can use its subkey to add the mnesia application: {{{ri:add(erlang, mnesia).}}} 
     94 
     95The query {{{ri:q("mods.loc:sum").}}} returns the line of code analyzed: 
     96{{{ 
     97(refactorerl@localhost)5> ri:q("mods.loc:sum"). 
     98    sum = 24299 
     99}}} 
    52100 
    53101= Using the query language 
    54102 
    55 = Dependency analysis 
     103The semantic query language of !RefactorErl can be used to gather information about the source code according to the interest of the developer.  
    56104 
    57 = Code duplicates 
     105The query language was designed according to the syntactic/semantic entities of the Erlang language. So it introduces files, macros, modules, functions, expressions, records, record fields, etc. 
     106 
     107The detailed description of the queries can be found [wiki:SemanticQuery here]. The description of the entities, its properties and selectors are defined [http://pnyf.inf.elte.hu/trac/refactorerl/wiki/SemanticQuery/Components here], but you can use the {{{?}}} selector in {{{ri}}}: {{{ri:q("mods.?")}}}. For further examples please check this [http://pnyf.inf.elte.hu/trac/refactorerl/wiki/SemanticQuery/Examples page]. 
     108 
     109Once you build a query, you need an initial selector to start. That can be either a position based entity selection {{{@fun}}} -- the function pointed in the web interface, or a global starting point, like {{{mods}}} -- all analysed modules.  
     110 
     111Once you selected an entity, you may ask some property of that entity: 
     112 * {{{mods.name}}} -- the name of the module 
     113or ask its connected entities: 
     114 * {{{mods.funs}}} -- functions defined in the modules 
     115 
     116You can also filter the entities: 
     117 * {{{mods[name=foo].funs.calls}}} -- what are the functions that are called in the functions of the foo module 
     118 
     119In the following, we will show some queries on the previously built database from the source of Mnesia. 
     120 
     121== Detecting relations, gathering information about the source code 
     122 
     123 * {{{ri:q(mods[name=mnesia_log].funs).}}} -- listing all the functions from the mnesia_log module 
     124 * {{{ri:q(mods[name=mnesia_log].funs.name).}}} -- listing the name of the functions from the mnesia_log module 
     125 * {{{ri:q(mods[name=mnesia_log].funs.refs).}}} -- listing the references (the function applications) of the the functions from the mnesia_log module 
     126 * {{{ri:q(mods[name=mnesia_log].funs[.refs]).}}} 
     127 * {{{mods[name=mnesia_log].funs[name=open_log]}}} 
     128 * {{{mods[name=mnesia_log].funs[name=open_log, arity=4]}}} 
     129 * {{{mods[name=mnesia_log].funs[name=open_log].refs}}} 
     130 * {{{mods[name=mnesia_log].funs[name=open_log].called_by}}} 
     131 * {{{@fun.called_by}}} 
     132 * {{{mods[name=mnesia_log].funs[name=open_log].calls}}} 
     133 * {{{@fun.calls}}} 
     134 
     135== Checking design rules 
     136 
     137== Detecting vulnerabilities 
     138 
     139==