{"id":7525,"date":"2021-10-26T11:26:40","date_gmt":"2021-10-26T18:26:40","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7525"},"modified":"2021-11-05T18:01:16","modified_gmt":"2021-11-06T01:01:16","slug":"refactorscript","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/refactorscript\/","title":{"rendered":"RefactorScript"},"content":{"rendered":"<h2>Contents<\/h2>\n<p><a href=\"#overview\">Overview<\/a><br \/>\n<a href=\"#running\">Running RefactorScripts<\/a><br \/>\n<a href=\"#window\">RefactorScript Window<\/a><br \/>\n<a href=\"#language\">RefactorScript Language<\/a><br \/>\n<a href=\"#datamodel\">Data Model<\/a><br \/>\n<a href=\"#scripts\">Common RefactorScripts<\/a><\/p>\n<h2><a id=\"overview\"><\/a>Overview<\/h2>\n<p>RefactorScript is a mechanism for generating boilerplate code based on the existing C\/C++ structures or functions. The typical uses for RefactorScript are:<\/p>\n<ul>\n<li>Automatically generating constructors or operators based on fields<\/li>\n<li>Automatically generating NULL checks for functions<\/li>\n<li>Automatically generating mock classes<\/li>\n<li>Automatically generating implementations for function pointer fields<\/li>\n<\/ul>\n<p>RefactorScript is supported in VisualGDB Custom Edition and higher.<\/p>\n<h2><a id=\"running\"><\/a>Running RefactorScripts<\/h2>\n<p>There are 2 ways of running a RefactorScript:<\/p>\n<ol>\n<li>Selecting one or more classes, fields, methods, variables, etc. in <a href=\"https:\/\/visualgdb.com\/documentation\/codeexplorer\/outline\/\">Code Explorer -&gt; Outline<\/a>, and using the <strong>Run RefactorScript<\/strong> button.<\/li>\n<li>Using the smart tags directly in the code editor<\/li>\n<\/ol>\n<h2><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7526\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/run.png\" alt=\"\" width=\"800\" height=\"595\" \/><\/a><a id=\"window\"><\/a>RefactorScript Window<\/h2>\n<p>Running a RefactorScript using either of the ways opens the RefactorScript window with the following controls:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/wnd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7527\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/wnd.png\" alt=\"\" width=\"1132\" height=\"622\" \/><\/a><\/p>\n<ul>\n<li>The script selector <strong>(1)<\/strong> showing both the scripts shipped with VisualGDB (in <strong>C:\\Program Files (x86)\\Sysprogs\\VisualGDB\\RefactorScripts<\/strong>) and the user-defined scripts (stored in <strong>%LOCALAPPDATA%\\VisualGDB\\RefactorScripts<\/strong>).<\/li>\n<li><strong>Save<\/strong> and <strong>Save As<\/strong> buttons that allow saving the scripts <strong>(2)<\/strong>. Note that the scripts in <strong>Program Files<\/strong> cannot be modified, however creating a script with the same name under <strong>%LOCALAPPDATA%<\/strong> will automatically override the script from Program Files.<\/li>\n<li>The instant update button <strong>(3) <\/strong>that controls whether the output is updated each time you edit the script. RefactorScript is designed to run very fast, so we recommend keeping this setting on.<\/li>\n<li>The controls for the script arguments <strong>(4)<\/strong> automatically derived from the arguments to the main generator of the script.<\/li>\n<li>Script input inspector showing the inputs passed to the main generator <strong>(5)<\/strong> and the properties of the selected element <strong>(6)<\/strong>.<\/li>\n<li>The output from the current script <strong>(7)<\/strong> or a list of errors.<\/li>\n<li>Buttons <strong>(8)<\/strong> for copying the script output to Clipboard, or inserting it in the code (the latter is only available when using SmartTags). You can also insert the results of running a RefactorScript by pressing Ctrl-Enter.<\/li>\n<\/ul>\n<p>The script editor provides very basic suggestion popups triggered by the &#8216;$&#8217; and &#8216;.&#8217; symbols:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/suggestions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7528\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/suggestions.png\" alt=\"\" width=\"846\" height=\"310\" \/><\/a>The suggestion popups work by quickly running the script until the edited position. This ensures accurate results, but will not work for the code branches that are never executed (e.g. disabled via main generator arguments).<\/p>\n<h2><a id=\"language\"><\/a>RefactorScript Language<\/h2>\n<p>RefactorScripts are an advanced form of code snippets. Lines prefixed with &#8220;&gt;&#8221; are copied to the output, while expanding the $-expressions. Lines not prefixed with &#8220;&gt;&#8221; follow C#-like syntax and are used to iterate over arrays, check conditions (e.g. skip non-pointers) and define intermediate variables.<\/p>\n<p>You can find a detailed description of the RefactorScript language on <a href=\"https:\/\/visualgdb.com\/documentation\/refactorscript\/language\/\">this page<\/a>.<\/p>\n<h2><a id=\"datamodel\"><\/a>Data Model<\/h2>\n<p>RefactorScripts can access exhaustive information about the selected classes, functions, fields or other C\/C++ entities, that can be used to fine-tune their output. You can easily explore this information via the right side of the RefactorScript window, or see our <a href=\"https:\/\/visualgdb.com\/documentation\/refactorscript\/datamodel\/\">RefactorScript data model reference<\/a> for the full list of all provided fields.<\/p>\n<h2><a id=\"scripts\"><\/a>Common RefactorScripts<\/h2>\n<p>See <a href=\"https:\/\/visualgdb.com\/reference\/refactorscripts\/\">this section<\/a> for a list of RefactorScripts shipped with VisualGDB, along with practical use examples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents Overview Running RefactorScripts RefactorScript Window RefactorScript Language Data Model Common RefactorScripts Overview RefactorScript is a mechanism for generating boilerplate<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[236,52,238],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7525"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=7525"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7525\/revisions"}],"predecessor-version":[{"id":7692,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7525\/revisions\/7692"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}