Changes between Version 3 and Version 4 of ScriptableInterface
- Timestamp:
- Apr 19, 2012, 7:17:15 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ScriptableInterface
v3 v4 10 10 * you can perform a series of batch refactorings in a single step by selecting multiple entities at once. \\ 11 11 12 == Usage examples == 13 14 '''Adding files''' 12 === File manipulations === 15 13 16 14 {{{ 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. 17 Added = ris:add_byname("path/to/mymod.erl"). 18 ... 19 % Readd the file. 20 ReAdded = ris:add(Added). 19 21 }}} 20 22 21 '''Dropping files''' 23 It is possible to drop files from the database: 22 24 23 25 {{{ 24 ris:drop('mods[name ~ "mymo.*"]'). 26 #!erlang 27 ris:drop('mods[name==mymod]'). 28 29 % or 30 31 % 'Added' is the previous entity. 32 ris:drop(Added). 25 33 }}} 26 34 27 '''Refactorings''' 35 === Refactorings === 36 37 Transformations are listed in [[RefactoringSteps|refactoring functionalities]]. 38 Here is the list of transformations that you can use via this interface: 39 40 '''rename/2''' 41 42 Renames [[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]]. 43 Example: 28 44 29 45 {{{ 30 RenamedVars = ris:rename("mods.fun.var[name=="Colour"]", "Color"). 46 #!erlang 47 ris:rename("mods[name=='mymod'].fun[name=='Colour']", "Color"). 48 }}} 31 49 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''' 36 51 37 Moved = ris:move("mods[name==mod1].fun[name==fun1 and arity==3]", mod2). 52 Moves the given [[RefactoringSteps/MoveFunction|function]], [[RefactoringSteps/MoveMacro|macro]], or [[RefactoringSteps/MoveRecord|record]] to another module. 53 Example: 54 {{{ 55 #!erlang 56 % Move every unexported function to another_module and move it back: 57 ris:move( 58 ris:move("mods[name=='mymod'] 59 .fun[exported==false]", 60 "other_mod"), 61 "mymod"). 62 }}} 38 63 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''' 43 65 44 NewVar = ris:intvar("mods[name==module1]45 .fun[name==f and arity==0]46 .expr[index==1].esub[class/=pattern]",47 "Varname").48 66 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]}).53 67 54 NewFun = ris:reorder("mod[name==mod1].fun[name==fun1,arity==3]",55 [3,2,1]).56 68 57 NewFun = ris:tupfun("mod[name==mod1].fun[name==fun1,arity==3]",58 {1,2}).59 69 70 71 72 73 Let's see some examples: 74 75 Rename a function (Of course, not just functions can be renamed): 76 {{{ 77 #!erlang 78 ris:rename("mods[name=='mymod'].fun[name=='Colour']", "Color"). 79 }}} 80 81 Move every unexported function to another_module and move it back: 82 {{{ 83 #!erlang 84 ris:move( 85 ris:move("mods[name=='mymod'] 86 .fun[exported==false]", 87 "other_mod"), 88 "mymod"). 89 }}} 90 91 In every modul, reorder every functions' parameters, whose name is fun1 and the arity is 3: 92 93 {{{ 94 #!erlang 95 ris:reorder("mod.fun[name==fun1,arity==3]", 96 [3,1,2]). 97 }}} 98 99 100 101 {{{ 102 #!erlang 103 ris:tupfun("mod[name==mod1].fun[name==fun1,arity==3]", 104 {1,2}). 105 }}} 106 107 {{{ 60 108 ris:generalize("mod[name==china].fun[name==sum].var[name=="A"]"). 61 109 … … 70 118 71 119 The 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. 73 121 74 122 {{{ … … 77 125 }}} 78 126 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. 82 130 83 131 {{{ … … 94 142 95 143 {{{ 144 #!erlang 96 145 ris:q([ris:add_byname("mymodule.erl"),".includes.name"]). 97 146 }}} … … 121 170 122 171 {{{ 172 #!erlang 123 173 ris:print(ris:q("mods.fun")). 124 174 }}} … … 129 179 130 180 {{{ 181 #!erlang 131 182 ris:print(ris:q("mods.fun"), 132 183 [{out,"funs.txt"}, linenum]).