Changes between Version 3 and Version 4 of ScriptableInterface


Ignore:
Timestamp:
Apr 19, 2012, 7:17:15 PM (13 years ago)
Author:
manualwiki
Comment:

extended ScriptableInterface part

Legend:

Unmodified
Added
Removed
Modified
  • ScriptableInterface

    v3 v4  
    1010 * you can perform a series of batch refactorings in a single step by selecting multiple entities at once. \\ 
    1111 
    12 == Usage examples == 
    13  
    14 '''Adding files''' 
     12=== File manipulations === 
    1513 
    1614{{{ 
    17 Added = ris:add_byname("mymods.erl"). 
    18 ReAdded = ris:add('mods[name~"mymodu.*"]'). 
     15#!erlang 
     16% Here an entity is returned, which can be used later. 
     17Added = ris:add_byname("path/to/mymod.erl"). 
     18... 
     19% Readd the file. 
     20ReAdded = ris:add(Added). 
    1921}}} 
    2022 
    21 '''Dropping files''' 
     23It is possible to drop files from the database: 
    2224 
    2325{{{ 
    24 ris:drop('mods[name ~ "mymo.*"]'). 
     26#!erlang 
     27ris:drop('mods[name==mymod]'). 
     28 
     29% or 
     30 
     31% 'Added' is the previous entity. 
     32ris:drop(Added). 
    2533}}} 
    2634 
    27 '''Refactorings''' 
     35=== Refactorings === 
     36 
     37Transformations are listed in [[RefactoringSteps|refactoring functionalities]]. 
     38Here is the list of transformations that you can use via this interface: 
     39 
     40'''rename/2''' 
     41 
     42Renames [[RefactoringSteps/RenameVariable|variable]], [[RefactoringSteps/RenameFunction|function]], [[RefactoringSteps/RenameRecord|record]], [[RefactoringSteps/RenameRecordField|record field]], [[RefactoringSteps/RenameMacro|macro]], [[RefactoringSteps/RenameHeader|header file]] or [[RefactoringSteps/RenameModule|module file]].  
     43Example: 
    2844 
    2945{{{ 
    30 RenamedVars = ris:rename("mods.fun.var[name=="Colour"]", "Color"). 
     46#!erlang 
     47ris:rename("mods[name=='mymod'].fun[name=='Colour']", "Color"). 
     48}}} 
    3149 
    32 MovedFuns = ris:move("mods[name ~ "^referl_.*"].fun[exported==false]", 
    33                      fun(F)-> 
    34                          ris:qstr([F,".mod.name"])++"_util" 
    35                      end). 
     50'''move/2''' 
    3651 
    37 Moved = ris:move("mods[name==mod1].fun[name==fun1 and arity==3]", mod2). 
     52Moves the given [[RefactoringSteps/MoveFunction|function]], [[RefactoringSteps/MoveMacro|macro]], or [[RefactoringSteps/MoveRecord|record]] to another module. 
     53Example: 
     54{{{ 
     55#!erlang 
     56% Move every unexported function to another_module and move it back: 
     57ris:move( 
     58    ris:move("mods[name=='mymod'] 
     59                  .fun[exported==false]", 
     60             "other_mod"), 
     61    "mymod"). 
     62}}} 
    3863 
    39 NewFun = ris:extract("mods[name==module1] 
    40                          .fun[name==f and arity==0] 
    41                              .expr[last==false]", 
    42                       mynewfun). 
     64'''extfun/2, extract/2''' 
    4365 
    44 NewVar = ris:intvar("mods[name==module1] 
    45                         .fun[name==f and arity==0] 
    46                             .expr[index==1].esub[class/=pattern]", 
    47                     "Varname"). 
    4866 
    49 NewRec = ris:intrec("mods[name==module1] 
    50                         .fun[name==f and arity==0] 
    51                             .expr[index==1].esub[class/=pattern]", 
    52                      {newrec,[field1,field2]}). 
    5367 
    54 NewFun = ris:reorder("mod[name==mod1].fun[name==fun1,arity==3]", 
    55                      [3,2,1]). 
    5668 
    57 NewFun = ris:tupfun("mod[name==mod1].fun[name==fun1,arity==3]", 
    58                     {1,2}). 
    5969 
     70 
     71 
     72 
     73Let's see some examples: 
     74 
     75Rename a function (Of course, not just functions can be renamed): 
     76{{{ 
     77#!erlang 
     78ris:rename("mods[name=='mymod'].fun[name=='Colour']", "Color"). 
     79}}} 
     80 
     81Move every unexported function to another_module and move it back: 
     82{{{ 
     83#!erlang 
     84ris:move( 
     85    ris:move("mods[name=='mymod'] 
     86                  .fun[exported==false]", 
     87             "other_mod"), 
     88    "mymod"). 
     89}}} 
     90 
     91In every modul, reorder every functions' parameters, whose name is fun1 and the arity is 3: 
     92 
     93{{{ 
     94#!erlang 
     95ris:reorder("mod.fun[name==fun1,arity==3]", 
     96            [3,1,2]). 
     97}}} 
     98 
     99 
     100 
     101{{{ 
     102#!erlang 
     103ris:tupfun("mod[name==mod1].fun[name==fun1,arity==3]", 
     104           {1,2}). 
     105}}} 
     106 
     107{{{ 
    60108ris:generalize("mod[name==china].fun[name==sum].var[name=="A"]"). 
    61109 
     
    70118 
    71119The result of the queries can be combined with the following set operators: \\ 
    72 * '''Intersection''': The following example takes the intersection of the files included by the two modules. 
     120* '''intersect''': The following example takes the intersection of the files included by the two modules. 
    73121 
    74122{{{ 
     
    77125}}} 
    78126 
    79 * '''Union''': similar to the above (use key 'union'). \\ 
    80 * '''Substraction''': similar to the above (use key 'minus'). \\ 
    81 * '''Range''': Ranges of expressions can be selected which denotes a list of continuous expressions between two syntactical siblings. An empty semantic query denotes the beginning or end of a block when used as the initial or final limit respectively. In this example, the expression range starts from the (first) match expression that contains "Var1" in the pattern side up to the end of the syntactical block. 
     127* '''union''': The union set operation. \\ 
     128* '''minus''': The substraction set operation. \\ 
     129* '''range''': Ranges of expressions can be selected which denotes a list of continuous expressions between two syntactical siblings. An empty semantic query denotes the beginning or end of a block when used as the initial or final limit respectively. In this example, the expression range starts from the (first) match expression that contains "Var1" in the pattern side up to the end of the syntactical block. 
    82130 
    83131{{{ 
     
    94142 
    95143{{{ 
     144#!erlang 
    96145ris:q([ris:add_byname("mymodule.erl"),".includes.name"]). 
    97146}}} 
     
    121170 
    122171{{{ 
     172#!erlang 
    123173ris:print(ris:q("mods.fun")). 
    124174}}} 
     
    129179 
    130180{{{ 
     181#!erlang 
    131182ris:print(ris:q("mods.fun"), 
    132183          [{out,"funs.txt"}, linenum]).