<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marc Picone on Medium]]></title>
        <description><![CDATA[Stories by Marc Picone on Medium]]></description>
        <link>https://medium.com/@piconemarc?source=rss-76b40bb5220c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ubvPDIcbxxa6O9y8EalhDg.png</url>
            <title>Stories by Marc Picone on Medium</title>
            <link>https://medium.com/@piconemarc?source=rss-76b40bb5220c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:06:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piconemarc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency]]></title>
            <link>https://medium.com/mwm-io/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/da158335ecbc</guid>
            <category><![CDATA[code-maintainability]]></category>
            <category><![CDATA[code-organization]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[file-templates]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 06:37:46 GMT</pubDate>
            <atom:updated>2023-08-14T06:37:46.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbh-Koxxx4BG-iP5h3-uhw.png" /></figure><h4>SUPERCHARGE YOUR WORKFLOW: A STEP-BY-STEP GUIDE TO ADVANCED FILE TEMPLATES</h4><h4>Unveiling File Template Magic: A Practical Guide to Structured File Templates</h4><h4>Introduction</h4><p>Welcome back to our series on making Android development easier with IntelliJ file templates. We’ve covered a lot so far — creating files, automating structures — and now we’re diving into an essential topic: <strong>how to keep your code organized in templates.</strong></p><p>Have you ever felt overwhelmed when small changes in your code’s names make you update lots of templates?</p><p>We’ve got your back. In this article, we’ll explore how to solve this challenge. We’ll revisit what we’ve learned about the parse function and include tab, and show you how to use them to make your code cleaner and simpler. You’ll see how to easily handle common tasks like string manipulation.</p><p>So, let’s jump in! We’ll help you get your code templates organized and reusable, so you can focus on what you do best — crafting awesome Android apps!</p><h4>Link</h4><h4>Articles:</h4><ul><li><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development (Basic)</a>.</li><li><a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts (Advance)</a>.</li><li><a href="https://medium.com/mwm-io/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers (Expert)</a></li></ul><h4>Gists:</h4><ul><li><a href="https://gist.github.com/marcpicone/8708e3ec4248b23494de24a83f47709b">UtilsStringFormat</a></li><li><a href="https://gist.github.com/marcpicone/d2e8fc2fecb9e92754866c7f8e7c6cbe">UtilsPathFormat</a></li><li><a href="https://gist.github.com/marcpicone/b5cce2a190598bc8b91755b2e495ea36">CustomViewState</a></li><li><a href="https://gist.github.com/marcpicone/f31a6c0423b4e0a55b9d7c225d3e5699">CustomView(View)</a></li><li><a href="https://gist.github.com/marcpicone/962ce5639fcc686fa4ee1edc3dbbabd5">CustomViewPresenter</a></li><li><a href="https://gist.github.com/marcpicone/84645f5e08dd8561737b734c6f230206">CustomViewContract</a></li><li><a href="https://gist.github.com/marcpicone/e216542f86b2f38c86e9a7994464a914">CustomViewLayout</a></li><li><a href="https://github.com/marcpicone/template_factorization_article/tree/main">Whole MVP template zip</a></li></ul><h4>Before We Begin</h4><p>Now that we’re comfortable using the parse function to reveal specific values or functions, let’s pause and reflect. Up until now, our include file templates have been all about generating content that we can directly use within the template.</p><p>But here’s the thing: the parse function is essentially a function that carries out the code within the provided template. So, if we make the include template simply assign values without actually printing anything, what happens next?</p><p>This approach opens up an interesting possibility. We can parse templates that don’t output anything directly, yet we can still access all the values defined within. It’s a subtle shift in perspective, and the results are quite remarkable!</p><h4>1.1 Introducing the UtilsStringFormat Template</h4><p>Our first template is dedicated to making your life easier by centralizing string manipulation tasks, providing a more efficient approach when crafting various file templates.</p><p>As you review the following code, take note of the “INIT” section’s significance, a detail we’ll unravel in part <strong>2.2</strong> of this article.</p><pre>## ****************************** HOW TO USE ********************************************<br>## This template is used to help manipulating String in your template creation<br>##<br>## To use this template use the parse directive on top of your template :<br>## `#parse(&quot;UtilsStringFormat.kt&quot;)`<br>##<br>## Then you can access all the following :<br>##<br>## **************** NAME to transform the variable `$NAME` ******************************* <br>##<br>## NameToCamelCase -&gt; transform the variable `$NAME` from `snake case` to `camel case`<br>##                 usage -&gt; directly call the reference : `${NameToCamelCase}`<br>##<br>## NameToUpperCase -&gt; transform the variable `$NAME` to `upper case`<br>##                 usage -&gt; directly call the reference : `${NameToUpperCase}`<br>##<br>## NameToLowerCamelCase -&gt; transform the variable `$NAME` from `snake case` to `lower camel case`<br>##                 usage -&gt; directly call the reference : `${NameToLowerCamelCase}`<br>##<br>## NameToSnakeCase -&gt; transform the variable `$NAME` from `camel case` to `snake case`<br>##                 usage -&gt; directly call the reference : `${NameToSnakeCase}`<br>##<br>## -------------------------------------------------------------------------------------<br>## ****** MACRO to transform the variable `$Arg` that will be passed in argument ******* <br>##<br>## ToArray -&gt; split the $Arg String on the $Delimiter<br>##                 usage -&gt; 1. Call the macro : `#ToArray ( $my_list $my_delimiter)`<br>##                 // the value passed in the list could be either reference `$my_ref` <br>##                 // or String `&quot;my_element1, my_element2&quot; &quot;,&quot;`<br>##                          2. Use the reference to print or use the result array `${ToArray}`<br>##<br>## ToLowerCamelCase -&gt; transform the $Arg String in `lower camel case` accept either `snake case`<br>##                     or `camel_case` format for the $Arg<br>##                 usage -&gt; 1. Call the macro : `#ToLowerCamelCase ( $my_string )`<br>##                 // the value passed in the list could be either reference `$my_ref` <br>##                 // or String `&quot;my_element1&quot;`<br>##                          2. Use the reference to print or use the value `${ToLowerCamelCase}`<br>##<br>## ToUpperCamelCase -&gt; transform the $Arg String in `upper camel case` accept either `snake case`<br>##                     or `lower camel case` format for the $Arg<br>##                 usage -&gt; 1. Call the macro : `#ToUpperCamelCase ( $my_string )`<br>##                 // the value passed in the list could be either reference `$my_ref` <br>##                 // or String `&quot;my_element1&quot;`<br>##                          2. Use the reference to print or use the value `${ToUpperCamelCase}`<br>##<br>## ToSnakeCase -&gt; transform the $Arg String in `snake case` accept either `camel case`<br>##                     or `lower camel case` format for the $Arg<br>##                 usage -&gt; 1. Call the macro : `#ToSnakeCase ( $my_string )`<br>##                 // the value passed in the list could be either reference `$my_ref` <br>##                 // or String `&quot;my_element1&quot;`<br>##                          2. Use the reference to print or use the value `${ToSnakeCase}`<br>##<br>## ------------------------------------ INIT -------------------------------------------<br>## If `$NAME` does not exist assign `$FEATURE_NAME` value to `$NAME` in order to prompt it.<br>## This happen when we use a reference for the path of a parent template<br>#if (${NAME} &amp;&amp; ${NAME} != &quot;&quot;)<br>## // Nothimg to do, the $NAME has been prompt<br>#else<br>#set($NAME = $FEATURE_NAME)<br>#end<br>##<br>## ---------------------------- NAME TRANSFORMATION --------------------------------------<br>#set( $TrimName = ${StringUtils.collapseSpaces(${NAME})})<br>## ----------------- NameToCamelCase<br>#set($NameToCamelCase = ${StringUtils.removeAndHump(${TrimName}, &quot;_&quot;)})<br>##<br>## ----------------- NameToUpperCase<br>#set($NameToUpperCase = $TrimName.toUpperCase())<br>##<br>## ----------------- NameToLowerCamelCase<br>#set($firstLetter = $NameToCamelCase.substring(0,1).toLowerCase())<br>#set($theRest = $NameToCamelCase.substring(1))<br>#set($NameToLowerCamelCase = ${firstLetter} + ${theRest})<br>##<br>## ----------------- NameToSnakeCase<br>#set( $regex = &quot;([a-z])([A-Z]+)&quot;)<br>#set( $replacement = &quot;$1_$2&quot;)<br>#set( $NameToSnakeCase = $TrimName.replaceAll($regex, $replacement).toLowerCase())<br>##<br>## ------------------------------- MACRO --------------------------------------<br>## ----------------- ToArray<br>#set($Arg = &quot;&quot;)<br>#set($Delimiter = &quot;&quot;)<br>#macro( ToArray $Arg $Delimiter )<br>#set($ToArray = ${StringUtils.split($Arg, $Delimiter)})<br>#end<br>##<br>## ----------------- ToLowerCamelCase<br>#set($Arg = &quot;&quot;)<br>#macro ( ToLowerCamelCase $Arg )<br>#set($modifiedName = ${StringUtils.removeAndHump(${Arg}, &quot;_&quot;)})<br>#set($firstLetter = $modifiedName.substring(0,1).toLowerCase())<br>#set($theRest = $modifiedName.substring(1))<br>#set($ToLowerCamelCase = ${firstLetter} + ${theRest})<br>#set( $ToLowerCamelCase = ${StringUtils.collapseSpaces(${ToLowerCamelCase})})<br>#end<br>##<br>## ----------------- ToUpperCamelCase<br>#set($Arg = &quot;&quot;)<br>#macro( ToUpperCamelCase  $Arg)<br>#set($ToUpperCamelCase = ${StringUtils.removeAndHump(${Arg}, &quot;_&quot;)})<br>#set( $ToUpperCamelCase = ${StringUtils.collapseSpaces(${ToUpperCamelCase})})<br>#end<br>##<br>## ----------------- ToSnakeCase<br>#set($Arg = &quot;&quot;)<br>#macro( ToSnakeCase  $Arg)<br>#set( $regex = &quot;([a-z])([A-Z]+)&quot;)<br>#set( $replacement = &quot;$1_$2&quot;)<br>#set( $ToSnakeCase = $Arg.replaceAll($regex, $replacement).toLowerCase())<br>#set( $ToSnakeCase = ${StringUtils.collapseSpaces(${ToSnakeCase})})<br>#end</pre><p>While engaging with your code, be mindful of spaces and line breaks. As templates are designed for printing, even spaces and line breaks are printed, potentially affecting path formatting in unexpected ways.</p><p>Thanks to this approach, you now have a single location for modifications — the include template.</p><p>Let’s explore applying the same logic to create a template for path formatting and optimize the organization of your code.</p><h4>1.2 Introducing the UtilsPathFormat Template</h4><p>Our next template is dedicated to streamlining path formatting, simplifying the access to various common paths within your project.</p><pre>## ****************************** HOW TO USE ********************************************<br>## This template is used to have easy access to different common path.<br>##<br>## To use this template use the parse directive on top of your template :<br>## `#parse(&quot;UtilsPathFormat.kt&quot;)`<br>##<br>## Then you can access all the following :<br>## ****************************** PATH ********************************************<br>## ---------------------------- ROOT PATH<br>#set($folder = &quot;&quot;)<br>#set($foreach = &quot;&quot;)<br>#set($RootPath = &quot;&quot;)<br>#set($endRootPath = &quot;..&quot;)<br>#foreach ($folder in ${StringUtils.split(${PACKAGE_NAME},&quot;.&quot;)})<br>#set($RootPath = &quot;$!RootPath../&quot;)<br>#if ($foreach.hasNext == false)<br>#set($RootPath = &quot;$!RootPath$endRootPath&quot;)<br>#end<br>#end<br>## ---------------------------- FOLDER<br>#set($folder = &quot;&quot;)<br>#set($foreach = &quot;&quot;)<br>#foreach ($folder in ${StringUtils.split(${PACKAGE_NAME},&quot;.&quot;)})<br>#if ($foreach.hasNext == false)<br>#set($Folder = ${folder})<br>#end<br>#end<br>## ---------------------------- FOLDER TO CAMEL CASE<br>#set($folder = &quot;&quot;)<br>#set($foreach = &quot;&quot;)<br>#set($FolderToCamelCase = &quot;&quot;)<br>#foreach ($folder in ${StringUtils.split(${PACKAGE_NAME},&quot;.&quot;)})<br>#if ($foreach.hasNext == false)<br>#set($FolderToCamelCase = ${StringUtils.removeAndHump($folder,&quot;_&quot;)})<br>#end<br>#end<br>## ---------------------------- COMMOM PATH<br>#set($ResPath = &quot;${RootPath}/res&quot;)<br>#set($AndroidTestPath = &quot;${RootPath}/../androidTest/java/com&quot;)<br>#set($TestPath = &quot;${RootPath}/../test/java/com&quot;)</pre><p>Really cool, now we could use this value in every new file template we create. With this powerful tool at your disposal, you’re ready to embrace enhanced efficiency and organization in your template-based development process.</p><p>Let’s dive into the practical aspects of integrating these templates into your Android development workflow.</p><h4>2.1 Accessing Template Values</h4><p>To start utilizing these values, you can seamlessly integrate them into your file templates.</p><p>Begin by opening a new file template in the IDE. In the template body, initiate the parsing of the required template file using the #parse directive. This simple step grants you access to all the values defined in the template.</p><p>Exemple :</p><pre>#parse(&quot;UtilsStringFormat.kt&quot;)<br>#set($VIEW_NAME = ${NameToCamelCase})<br>class ${VIEW_NAME} @JvmOverloads constructor(<br>    context: Context,<br>    attrs: AttributeSet? = null,<br>    defStyleAttr: Int = 0<br>) : FrameLayout(context, attrs, defStyleAttr) {<br>    //<br>}</pre><p>In this example, we’ve used the NameToCamelCase value from the UtilsStringFormat template to define the format for the view name. By parsing the UtilsStringFormat file, we gain access to this transformation.</p><p>But often, a single template might not suffice, and several child templates could require the same value. Similar to how we handled the Utils template, we can create an include file to encapsulate the state of your entire template. This approach ensures consistent value usage throughout the template.</p><p>By adopting this method, any modifications to the value can be made in one central location, simplifying the process of applying changes across the entire template.</p><p>Now, let’s put these principles into action with a straightforward example of creating a custom view template. This example will highlight the benefits of integrating template values in your daily workflow.</p><h4>2.2 Leveraging Template State with Includes</h4><p>To illustrate this concept, let’s consider an example where we want to create a CustomViewState include file to hold and manage the state of our custom view template.</p><p>Begin by generating a new file using the IDE’s include tab. We’ll name the file CustomViewState and assign the .kt extension.</p><p>Example :</p><pre>#parse(&quot;UtilsStringFormat.kt&quot;)<br>#parse(&quot;UtilsPathFormat.kt&quot;)<br>##<br>## Package ---------------------------------------------<br>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)<br>#set($package = &quot;package ${PACKAGE_NAME}.${NAME}<br>&quot;)<br>#end<br>## Imports ---------------------------------------------<br>#set($viewImports = &quot;import android.content.Context<br>import android.util.AttributeSet<br>import android.view.View<br>import android.widget.FrameLayout<br>import androidx.annotation.IdRes<br>import ${PACKAGE_NAME}.R<br>&quot;)<br>##<br>## *************** EXPOSED VALUES *************************<br>#set($VIEW_IMPORTS = ${viewImports})<br>#set($PACKAGE = ${package})<br>#set($VIEW_NAME = ${NameToCamelCase})<br>#set($PRESENTER_NAME = &quot;${NameToCamelCase}Presenter&quot;)<br>#set($CONTRACT_NAME = &quot;${NameToCamelCase}Contract&quot;)<br>#set($CONTRACT_SCREEN_NAME = &quot;${CONTRACT_NAME}.Screen&quot;)<br>#set($CONTRACT_USER_ACTION_NAME = &quot;${CONTRACT_NAME}.UserAction&quot;)<br>## ******************** PATH **********************************<br>#set($VIEW_PATH = &quot;${NAME}/${VIEW_NAME}&quot;)<br>#set($CONTRACT_PATH = &quot;${NAME}/${CONTRACT_NAME}&quot;)<br>#set($PRESENTER_PATH = &quot;${NAME}/${PRESENTER_NAME}&quot;)<br>#set($LAYOUT_PATH = &quot;${ResPath}/${NAME}/layout/${NAME}&quot;)</pre><p>To maintain clarity and precision, I have adopted a naming convention using upper snake case for values within the template. This strategy enhances readability and helps avoid errors, especially since templates lack linting functionality.</p><p>Now that we have our state holder CustomViewState prepared, let&#39;s put it to use and begin crafting our CustomView in the Files tab.</p><p><strong>View Details (Parent template):</strong></p><ul><li>Name: CustomView</li><li>Extension: kt</li><li>File Name: #parse(&quot;CustomViewState.kt&quot;)${VIEW_PATH}</li></ul><p><strong>Note</strong> :</p><p>A quick pause to address a slight nuance, while employing the parse function in the file name is possible, it does necessitate a minor adjustment in the UtilsStringFormat.kt template:</p><pre>## ------------------------------------ INIT -------------------------------------------<br>## If `$NAME` does not exist assign `$FEATURE_NAME` value to `$NAME` in order to prompt it.<br>## This happen when we use a reference for the path of a parent template<br>#if (${NAME} &amp;&amp; ${NAME} != &quot;&quot;)<br>## // Nothimg to do, the $NAME has been prompt<br>#else<br>#set($NAME = $FEATURE_NAME)<br>#end<br>##</pre><p>This INIT section ensures that if the $NAME variable isn&#39;t explicitly defined, the value of $FEATURE_NAME is assigned to it. This covers cases where references to parent template paths are involved. Now, let&#39;s continue exploring our example scenario:</p><ul><li>Body :</li></ul><pre>#parse(&quot;CustomViewState.kt&quot;)<br>${PACKAGE}<br>${VIEW_IMPORTS}<br>class ${VIEW_NAME} @JvmOverloads constructor(<br>    context: Context,<br>    attrs: AttributeSet? = null,<br>    defStyleAttr: Int = 0<br>) : FrameLayout(context, attrs, defStyleAttr) {<br><br>    private val view = inflate(context, R.layout.${NAME}, this)<br>    private val userAction by lazy { createUserAction() }<br><br>    override fun onAttachedToWindow() {<br>        super.onAttachedToWindow()<br>        userAction.onAttachedToWindow()<br>    }<br><br>    override fun onDetachedFromWindow() {<br>        super.onDetachedFromWindow()<br>        userAction.onDetachedFromWindow()<br>    }<br><br>    private fun createScreen() = object : ${CONTRACT_SCREEN_NAME} {<br>    }<br><br>    private fun createUserAction(): ${CONTRACT_USER_ACTION_NAME} {<br>        if (isInEditMode) {<br>            return object : ${CONTRACT_USER_ACTION_NAME} {<br>                override fun onAttachedToWindow() {}<br>                override fun onDetachedFromWindow() {}<br>            }<br>        }<br>        return ${PRESENTER_NAME}(<br>            createScreen()<br>        )<br>    }<br>}</pre><p><strong>Presenter Details (Child template):</strong></p><ul><li>File Name: #parse(&quot;CustomViewState.kt&quot;)${PRESENTER_PATH}</li><li>Extention : kt</li></ul><p>Body :</p><pre>#parse(&quot;CustomViewState.kt&quot;)<br>${PACKAGE}<br>class ${PRESENTER_NAME}(<br> private val screen : ${CONTRACT_SCREEN_NAME}<br>) : ${CONTRACT_USER_ACTION_NAME} {<br><br>    override fun onAttachedToWindow(){<br>    <br>    }<br>    <br>     override fun onDetachedFromWindow(){<br>     <br>     }<br>}</pre><p><strong>Contract Details (Child Template):</strong></p><ul><li>File name : #parse(&quot;CustomViewState.kt&quot;)${CONTRACT_PATH}</li><li>Extension: kt</li><li>Body :</li></ul><pre>#parse(&quot;CustomViewState.kt&quot;)<br>${PACKAGE}<br>interface ${CONTRACT_NAME} {<br><br>    interface UserAction {<br><br>        fun onAttachedToWindow()<br><br>        fun onDetachedFromWindow()<br>    }<br><br>    interface Screen {<br>    <br>    }<br>}</pre><p><strong>Layout Details (Child Template):</strong></p><ul><li>File Name : #parse(&quot;CustomViewState.kt&quot;)${LAYOUT_PATH}</li><li>Extention : kt</li><li>Body :</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;merge xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:parentTag=&quot;android.widget.FrameLayout&quot;&gt;<br>    <br><br><br>&lt;/merge&gt;</pre><p>And that’s it, with this we could use our file template to quickly create a MVP structure like we done before. But now our template is much more easy to maintain!</p><h4>Conclusion:</h4><p>In this article, we’ve harnessed the full potential of advanced file templates. By wielding the parse function’s magic, we’ve seamlessly integrated values and functions, fueling our templates with adaptability and precision.</p><p>The introduction of UtilsStringFormat and UtilsPathFormat has changed our string manipulation and path formatting, offering a streamlined and organized approach. With include templates at our side, we’ve centralized value management, ensuring consistency and effortless modifications.</p><p>As we wrap up this journey, remember that this is just one facet of a multi-dimensional exploration. If you’re hungry for more template magic, venture further into the series. Discover the intricacies of <a href="https://medium.com/mwm-io/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4"><strong>MVP architectures</strong></a> and delve into the world of <a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1"><strong>Room database templates</strong></a>. The possibilities are vast, limited only by your creativity.</p><p>Happy coding, and may your templates continue to light your path toward exceptional app creation! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da158335ecbc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers]]></title>
            <link>https://medium.com/mwm-io/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/70e8dcdcbbe1</guid>
            <category><![CDATA[room-database]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[file-templates]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:06:27 GMT</pubDate>
            <atom:updated>2023-08-14T07:28:31.250Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h4>Elevate Your Android Development Workflow with Custom File Templates: A Room Database Walkthrough</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbh-Koxxx4BG-iP5h3-uhw.png" /></figure><h3>Introduction</h3><p>Welcome to the third article in our series on using IntelliJ file templates. In the first article, we learned how to customise file and folder paths to our liking, and in the second, we explored how to use this customisation to quickly create an MVP structure for an Android app.</p><p>Now, in this article, we’ll take things even further and learn how to use file templates to create a Room database in Android Studio. But don’t worry, the goal here is not just to create a database — it’s to show you how to master file templates and leverage their power to automate repetitive tasks and speed up your development process.</p><p>So let’s dive in and learn how to take your file template game to the next level!</p><h3>Link</h3><h4>Articles:</h4><ul><li><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development (Basic)</a>.</li><li><a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts (Advance)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gists:</h4><ul><li><a href="https://gist.github.com/marcpicone/dc21cb224315ce650d18264155088e99">ArgToSnakeCase</a></li><li><a href="https://gist.github.com/marcpicone/4a2c8ff62585f68c7c002fb93da5d493">RoomDbEntitiesDeclaration</a></li><li><a href="https://gist.github.com/marcpicone/63c101b3434ad78e11196d31eca7d7a1">ArgToLowerCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/6606e914ec33860ba8437028e225df54">NameToLowerCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/05aead9f65cc85070aa3cf137d1d1636">Database</a></li><li><a href="https://gist.github.com/marcpicone/d9eca1af9dd8b8db20a3eeaf073642e7">Repository</a></li><li><a href="https://gist.github.com/marcpicone/8a5947be56bea8745d00262e7e4b925e">RepositoryImpl</a></li><li><a href="https://gist.github.com/marcpicone/acc1c9a8c910b110707e58d79e140775">Dao</a></li><li><a href="https://gist.github.com/marcpicone/99ffc2991d135c99323425a9b137b776">Entity</a></li><li><a href="https://gist.github.com/marcpicone/ac8a6da753ae0c4f1fa2f4fd3519649e">DTO</a></li></ul><h4>Template ZIP file:</h4><ul><li><a href="https://github.com/marcpicone/file_template_room_db_article">file_template_room_db_article</a></li></ul><h4>1. Room Database</h4><p>In this section, we’ll create a custom file template to create the Room database with our preferred package structure, entity imports, and DAO declarations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBLiA5tvO1Z-P6nXlGYogw.png" /></figure><p>Let’s start by creating a new file template and naming it RoomDatabase. We want the Room database to be in a package named <strong>data/my_package_room_database/MyPackageRoomDatabase</strong>. We’ll use the <strong>NameToCamelCase</strong> template (<a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Created in the second article</a>) to convert the file name to camel case.</p><p>In the body of the template, we’ll start with the usual package declaration:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.$NAME<br>#end</pre><p>Now, we’ll fill in the necessary imports:</p><pre>import android.content.Context<br>import androidx.room.Database<br>import androidx.room.Room<br>import androidx.room.RoomDatabase</pre><p>We want to be able to have the entity and Dao imports already filled in the template. To do this, we’ll create a custom variable that will prompt the user for the entities they want to use in the database. We’ll assume that the entered value will be a comma-separated list of Entity names.</p><p>To create the custom variable, we’ll jump to the top of the template, before the package declaration, and enter the following code:</p><pre>#set($entitiesArray = ${StringUtils.split($ENTITIES_LIST,&quot;,&quot;)})<br>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ....</pre><p>This sets the value of <strong>$entitiesArray</strong> by splitting the $<strong>ENTITIES_LIST</strong> on the comma. Since $<strong>ENTITIES_LIST</strong> is not set, it will be prompted by the IDE when the template is created.</p><p>Now, we can use our list of entities to import their respective Dao and DTO classes. Here’s what that looks like:</p><pre>#foreach($entity in $entitiesArray )<br>#set($ARG1 = &quot;$entity&quot;)<br>import ${PACKAGE_NAME}.data.#parse(&quot;ArgToSnakeCase.kt&quot;)_repository.${ARG1}Dao<br>import ${PACKAGE_NAME}.domain.#parse(&quot;ArgToSnakeCase.kt&quot;).${ARG1}DTO<br>#end</pre><p>Here, we’re using the <strong>ArgToSnakeCase</strong> template to convert the entity names to snake case for use in the package names. This is a simple include template that uses the removeAndHump method. We’re also using the parse directive to include an undefined variable named <strong>$ARG1</strong> that allows us to set a name to pass into the removeAndHump method.</p><p>Let’s create the <strong>ArgToSnakeCase</strong> template. We’ll create a new child template in the include tab, name it <strong>ArgToSnakeCase</strong>, and enter the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd38aeab64e5075c9b1c0f80cfe649f7/href">https://medium.com/media/cd38aeab64e5075c9b1c0f80cfe649f7/href</a></iframe><p>Now, we’ll create another include template to declare the entities. We’ll call this template <strong>RoomDbEntitiesDeclaration</strong>. In the template body, we’ll declare the entities by using the <strong>StringUtils.capitalizeFirstLetter</strong> method to capitalise the entity names and concatenate them with a hardcoded “DTO::class”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b66d0e1f5bb2fbd0fae5965e00304c2/href">https://medium.com/media/8b66d0e1f5bb2fbd0fae5965e00304c2/href</a></iframe><p>Now, let’s use this template in our RoomDatabase file template. Here’s what the template looks like now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e0907563a14afabf3518a9d5e776ee/href">https://medium.com/media/95e0907563a14afabf3518a9d5e776ee/href</a></iframe><p>Here, we’re using the Room database annotation to declare our database with the list of entities that we created in the <strong>RoomDbEntitiesDeclaration</strong> template. We’re also using the <strong>ArgToSnakeCase</strong> template to convert the entity names to snake case for use in the package names.</p><p>We could also see <strong>ArgToLowerCamelCase</strong> that is used to format variable name. Let’s create it in the include tab.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12235b995b5e01b6ff1f2b7c9c2610d5/href">https://medium.com/media/12235b995b5e01b6ff1f2b7c9c2610d5/href</a></iframe><p>That’s it for the Room database file template!</p><h4>2. Entity.kt</h4><p>To create a new file template for entities, we’ll call it RoomEntity and set its extension to .kt. We want the entity to be in a package named <strong>domain/entity_name/EntityName</strong>, so the file name should be:</p><pre>domain/${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)</pre><p>In the body of the template, we’ll define the package and class declaration.</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.domain.${NAME}<br>#end<br>#parse(&quot;File Header.java&quot;)<br>data class #parse(&quot;NameToCamelCase.kt&quot;)(<br>    #formatArgumentListForDataClass()<br> )</pre><p>In order to populate our <strong>Entity</strong>, we will use a similar workaround as before and create a custom variable that we assume will be a list of (arg : type). This is where we introduce <a href="https://velocity.apache.org/engine/1.7/user-guide.html#velocimacros"><strong>Macros</strong></a>, which are used to create functions in the VTL world. Macros will be used here to format the name of the arguments over the snippet. Let’s take a look at the macro code:</p><pre>#macro( formatArgumentListForDataClass )<br>#set($argumentType = &quot;&quot;)<br>#set($foreach = &quot;&quot;)<br>#foreach($argumentType in ${StringUtils.split($ARGUMENT_LIST, &quot;,&quot;)})<br>val ${argumentType} #if($foreach.hasNext()), <br>#end<br>#end<br>#end</pre><p>Look at the way I add a coma and return to the Line if the list is not ended. The formatArgumentListForDataClass macro will format the argument list correctly, adding commas and returning to a new line if the list is not yet ended.</p><p>Now, let’s create a function to map the Entity to DTO. We’ll use a macro called formatArgumentListForDTOMapper to format the argument list.</p><pre>#macro( formatArgumentListForDTOMapper )<br>#set($argumentType = &quot;&quot;)<br>#set($argumentNameArray = [])<br>#set($foreach = &quot;&quot;)<br>#foreach($argumentType in ${StringUtils.split($ARGUMENT_LIST, &quot;,&quot;)})<br>#set($argumentNameArray = ${StringUtils.split($argumentType, &quot;:&quot;)})<br>$argumentNameArray.get(0) = this.$argumentNameArray.get(0) #if($foreach.hasNext()),<br>#end<br>#end<br>#end</pre><p>With this macro, we’ll create the entity body as follows:</p><pre>{<br>    fun toDTO(): #parse(&quot;NameToCamelCase.kt&quot;)DTO{<br>    return #parse(&quot;NameToCamelCase.kt&quot;)DTO(<br>       #formatArgumentListForDTOMapper()<br>    )<br> }</pre><p>We can now create a DTO template in a child template to our entity. We’ll set the file name to :</p><pre>domain/${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)DTO</pre><p>and set its extension to .kt.</p><p>In the body of the template, we’ll define the package and class declaration, the tableName, and use the <strong>formatArgumentListForDataClass</strong> and <strong>formatArgumentListForModelMapper</strong> macros to create the argument list and the function to map the model to the DTO.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52b4b44c31e17dee90d22cd569120f0e/href">https://medium.com/media/52b4b44c31e17dee90d22cd569120f0e/href</a></iframe><p>Now that we have our entity created, it’s time to move on to the next step in our journey towards mastering file templates in IntelliJ — creating the repository.</p><h4>3. Repository.kt</h4><p>In this section, we will create a new include template called <strong>NameToLowerCamelCase</strong> that converts the variable $<strong>NAME</strong> to lower camel case. We will use this include template to create a new child template for our entity’s repository. The repository will have all CRUD methods, and we will also create an implementation of the repository.</p><p>First, let’s create the <strong>NameToLowerCamelCase</strong> include template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aef3847eb5b13b4789f61fb5cf73fb24/href">https://medium.com/media/aef3847eb5b13b4789f61fb5cf73fb24/href</a></iframe><p>Now, let’s create a new child template for our entity’s repository. We want the file name to be <strong>data/package_name_repository/PackageNameRepository</strong>, so the file name is:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)Repository</pre><p>The body will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ecea011374ab07e0e80f253dd77a76a/href">https://medium.com/media/5ecea011374ab07e0e80f253dd77a76a/href</a></iframe><p>And that’s done.</p><p>Now let’s create the implementation file.</p><p>The file name will be:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)RepositoryImpl</pre><p>And the body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac4bf7a700d61b16fc91396dc702ede9/href">https://medium.com/media/ac4bf7a700d61b16fc91396dc702ede9/href</a></iframe><p>In summary, we created a new include template <strong>NameToLowerCamelCase</strong> to convert the variable $<strong>NAME</strong> to lower camel case. We used this template to create a new child template for our entity’s repository, with all CRUD methods. Finally, we created an implementation of the repository, using the previously created child template and the necessary imports.</p><p>And the last, the DAO</p><p>The file name is:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)Dao</pre><p>And the body :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf1706f3be03de9afa24e1c77ff9bc56/href">https://medium.com/media/bf1706f3be03de9afa24e1c77ff9bc56/href</a></iframe><p>This DAO file template defines methods to insert, query, update, and delete items in the database. It also includes the Dao annotation required by Room, as well as a companion object to define the table name.</p><p>Feel free to modify this template to suit your needs. Remember, the goal of this series of articles is to give you a step-by-step approach to deep diving into file templates, so don’t be afraid to experiment and try new things!</p><h3>Conclusion</h3><p>In conclusion, file templates can be incredibly useful for streamlining repetitive tasks in Android development, and we’ve seen how they can be used to create custom formatting for paths and generate complex views with multiple files. In this third article, we explored how to use file templates to generate code for a Room database, showing that the possibilities for template creation are only limited by one’s creativity.</p><p>While we’ve focused on specific use cases in this series of articles, it’s important to remember that file templates can be applied to a wide range of scenarios in Android development. They can help save time and reduce errors by automating repetitive tasks and allowing developers to focus on the more creative aspects of their work.</p><p>I hope that these articles have helped demystify file templates and encouraged you to explore their potential in your own projects.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e8dcdcbbe1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with…]]></title>
            <link>https://medium.com/mwm-io/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/968b4c82b9f4</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:05:33 GMT</pubDate>
            <atom:updated>2023-08-14T07:27:33.483Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h3>Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts</h3><h4>Simplify Your App Architecture: Quick MVP and Layout Creation Using a Customisable File Template</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOPqoYHiOGYoAEq9t1vyxg.png" /></figure><h3>Introduction</h3><p>Creating file templates in IntelliJ is a great way to save time and effort while developing Android applications.</p><p>In the first article of this series, we learned how to customise file and folder paths to our liking.</p><p>In this article, we’ll explore how to create custom file templates for MVP (Model-View-Presenter) architecture in an Android app.</p><p>We’ll use file templates to generate the required code and layouts automatically. In this article, we’ll take it a step further and create templates with multiple files and folders.</p><p>When building MVP architecture for an Android app, there are three primary components to consider: the View, the Presenter, and the Contract. Let’s create templates for each of these components.</p><h3>Link</h3><h4>Articles:</h4><ul><li><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development (Basic)</a>.</li><li><a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers (Expert)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gists:</h4><ul><li><a href="https://gist.github.com/marcpicone/30c8b402196ec8d358cc75de86835a44">NameToCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/faf331b55d8c4817b1003a02c5c58073">View</a></li><li><a href="https://gist.github.com/marcpicone/f6ce5f53984d2d9e1d828484e7df6b3e">Presenter</a></li><li><a href="https://gist.github.com/marcpicone/d8fff9a58597d09315e7b97727600921">Contract</a></li><li><a href="https://gist.github.com/marcpicone/09a96959afc4701302ee5a5e302794c3">Layout</a></li></ul><h4>Template ZIP file:</h4><ul><li><a href="https://github.com/marcpicone/file_template_custom_view_article">file_template_custom_view_article</a></li></ul><h4>1. The View.kt</h4><p>To create the View file template, we’ll use the same approach as in the previous article, using a path with variables. We’ll simplify the process by passing the variable for the View name in the include tab.</p><p>First, we’ll create an include template named “NameToCamelCase” that will extract the CamelCase method to keep flexibility. Set the extension to kt and fill the body with <strong>${StringUtils.removeAndHump(“${NAME}”, “_”)}</strong>.</p><p>Now, we can use this include template in the path to generate the name for the View. To do this, create a new template and name it “CustomView” in the files tab. The new path will be :</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)View</pre><p>Remember to set the file extension to <strong>kt</strong>.</p><p>To start, declare the package name at the top of the file:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.${NAME}<br>#end</pre><p>Next, add the required imports:</p><pre>import android.content.Context <br>import android.util.AttributeSet <br>import android.view.View <br>import android.widget.FrameLayout <br>import androidx.annotation.IdRes <br>import ${PACKAGE_NAME}.R</pre><p>Notice how we could easily get the R class and keep it available for every app.</p><p>Then we could add the class declaration using our parse directive.</p><pre>class #parse(&quot;NameToCamelCase.kt&quot;)View @JvmOverloads constructor( <br>    context: Context,<br>    attrs: AttributeSet? = null,<br>    defStyleAttr: Int = 0 ) : FrameLayout(context, attrs, defStyleAttr){<br> <br>    private val view = inflate(context, R.layout.${NAME}, this) <br>}</pre><h4>2. The Presenter.kt</h4><p>To create the Presenter file template, we’ll need to create a new child template. Fill the File Name field with :</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)Presenter</pre><p>And set the extension to kt.</p><p>In the body, start by declaring the package name with:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.${NAME}<br>#end</pre><p>Next, add the class declaration using our NameToCamelCase.kt template:</p><pre>class #parse(&quot;NameToCamelCase.kt&quot;)Presenter(<br> private val screen : #parse(&quot;NameToCamelCase.kt&quot;)Contract.Screen<br>) : #parse(&quot;NameToCamelCase.kt&quot;)Contract.UserAction {<br><br>}</pre><p>Notice how easy it is to format all our file names with just one include template. This is a powerful feature that can save a lot of time and effort!</p><h4>3. The Contract.kt</h4><p>For the Contract, create a new child template with the following settings:</p><p>File Name:</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)Contract</pre><p>Extension: kt<br>Body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fbb3e45fec116a763401ea1460781e2/href">https://medium.com/media/5fbb3e45fec116a763401ea1460781e2/href</a></iframe><p>Note that this template follows the same structure as the Presenter and View templates, using the NameToCamelCase include template to format the file name.</p><h4>4. The Layout.XML</h4><p>To create a new XML file, we’ll create a child template in Android Studio. We’ll use the <strong>RootPath</strong> template that we created earlier to generate the file name.</p><p>We fill the File name with :</p><pre>#parse(&quot;RootPath.kt&quot;)/res/layout/${NAME}</pre><p>set extension to xml.</p><p>And finally the body :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5714d01554216316523c90f03d33e9ee/href">https://medium.com/media/5714d01554216316523c90f03d33e9ee/href</a></iframe><p>This template will generate a new XML file with a merge tag and a UI Link comment. The file will be created in the appropriate layout folder based on the RootPath template.</p><p>Now you can easily create a custom view by using this template.</p><h4>Conclusion</h4><p>In conclusion, we have learned how to streamline our MVP architecture in Android by creating file templates for the Presenter, View, Contract, and XML files. By using templates, we can save time and reduce errors in our code.</p><p>While this article focused on the MVP architecture, the same principles can be applied to other architectures, such as MVVM or MVI. By creating file templates that match the architecture, we can quickly create new screens or features and ensure that they adhere to the chosen architecture.</p><p>By utilising file templates for the MVP pattern, we’ve learned how to standardise our code and improve productivity. But our template approach doesn’t stop there. In the next article, we’ll take it up a notch and dive into <a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1"><strong>creating templates for Room database entities and DAO repositories</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=968b4c82b9f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with…</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crafting Custom Path Formatting in IntelliJ File Templates for Android Development]]></title>
            <link>https://medium.com/mwm-io/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c93c4c33689d</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:04:47 GMT</pubDate>
            <atom:updated>2023-08-14T07:27:50.987Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h4>Advanced IntelliJ File Templates: Templates with multiple files and folders</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqwMvw-dzmUk2EuiBZwQWw.png" /></figure><h3>Introduction</h3><p>Creating files and folders in a project can be a repetitive and time-consuming task, especially when following a specific architecture pattern. However, <a href="https://www.jetbrains.com/help/idea/using-file-and-code-templates.html"><strong>IntelliJ File Templates</strong></a> can automate this process and save you a lot of time.</p><p>In this article, we’ll show you how to create complex templates with multiple files and folders, using IntelliJ File Templates.</p><p>Moreover, file templates promote a shared understanding of best practices by providing predefined file structures that the team can adopt together.</p><p>So let’s dive in and take your IntelliJ File Template game to the next level!</p><h3>Link</h3><h4>Articles :</h4><ul><li><a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts (Advance)</a>.</li><li><a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers (Expert)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gist :</h4><ul><li><a href="https://gist.github.com/marcpicone/54f2ab28e53b6e35e36e93ab45befa36">RootPath</a></li></ul><h4>1. Introduction to Custom Path Formatting</h4><p>Let’s start by creating a simple Kotlin class file using IntelliJ’s File Templates.</p><p>To create a new template, navigate to “File” &gt; “New” &gt; “Edit File Template…” in the main menu. Select the “Files” tab under “File and Code Templates” and click the “+” button to create a new file template.</p><p>In the “Name” field, enter a name for your template that will identify it in the “New” menu.</p><p>You can use the <strong>${NAME}</strong> variable in the “File name” field and select the extension for the file, such as kt.</p><p>Once you’ve created your first file template, you can click “OK”, and the IDE will propose the creation of your file template with the name you specified when creating a new file.</p><p>To create a folder and organise your file in a package, you can add the package name to the “File name” field, separated by a slash. This will create a folder with the specified package name and place your file inside it.</p><p>For example, you can enter <strong>my_package/${NAME}</strong> in the “File name” field. This will create a package called “my_package” and a file with the name of your choosing.</p><p>Now, let’s take a look at how we can make this process even more efficient by using custom path formatting with Velocity Template Language.</p><h4>2. Velocity Template Language</h4><p><a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> (VTL) is a Java-based language that provides several useful methods for writing templates. Even predefined variables like <strong>${NAME}</strong> use VTL.</p><p>Let’s assume that the <strong>${NAME}</strong> variable no longer stands for the file name in CamelCase, but instead, it represents the package name in snake_case. We want our path to be the package name provided in snake_case followed by the file name in CamelCase.</p><p>To accomplish this, we can use the StringUtils class, which contains the removeAndHump method. Our new path would look like this:</p><pre>${NAME}/${StringUtils.removeAndHump(${NAME}, &quot;_&quot;)}</pre><p>With this template, the IDE will prompt you to enter the file name, but instead of entering the file name in CamelCase, you’ll enter the package name in snake_case, and the IDE will create the package with the provided name and attach the file in CamelCase.</p><p>You can also hardcode a string after the path. For example, if you want your file to be a view, you can add it this way:</p><pre>${NAME}/${StringUtils.removeAndHump(${NAME}, &quot;&quot;)}View</pre><p>Now, let’s create another package with its own file.</p><h4>3. Create the layout file</h4><p>To continue with our example, let’s say we need to create a custom layout for a view in our Android app. While we could hardcode the path of our app’s res folder to create the layout file, we want a more adaptable solution that works for all apps. To achieve this, we’ll need to find a way to determine the number of folders we are from the app’s root folder when creating the template.</p><p>Thankfully, IntelliJ provides a variable called <strong>${PACKAGE_NAME}</strong>, which gives us the current file’s package name separated by dots. While this variable is typically used to fill in the package name at the top of a file, we can use it to determine the path we need to create our layout file.</p><p>To do this, we’ll create a new snippet in the “Include” tab of the template editor called “RootPath”.</p><p>This script initialises variables that we’ll use to construct the path.</p><p>The foreach loop splits the <strong>${PACKAGE_NAME}</strong> variable on dots, and for each iteration, we add “<strong>../</strong>” to the <strong>$rootRelativePath</strong> variable to navigate up one folder in the root folder.</p><p>Once the loop completes, we check if it’s the last iteration and concatenate <strong>$endRootPath</strong> to access the “root” folder.</p><p>Finally, we call <strong>$rootRelativePath</strong>, which gives us the desired result and allows us to create a secondary package or navigate to other desired folders within the package.</p><p>Here is the updated code for the “RootPath” snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><p><strong>Note that there should be no spaces at the beginning or end of every line as this can cause issues with package creation.</strong></p><p>To create a child template for our custom layout, select the file template and click on the “Add New Child Template” button on the right of the “+” button. In the child template file name, enter the following:</p><pre>#parse(&quot;RootPath.kt&quot;)/res/layout/${NAME}</pre><p>Make sure to set the extension as XML.</p><p>With this template, you can now create both the folder and file for your custom layout in a quick and efficient manner.</p><h3>Conclusion</h3><p>In this guide, we have learned how to use file templates to automate the creation of Android app components. By using variables such as <strong>${PACKAGE_NAME}</strong>, we can create adaptable solutions that work for any app.</p><p>We have also seen how to use the <a href="https://velocity.apache.org/engine/1.7/user-guide.html#set"><strong>#set</strong></a> and <a href="https://velocity.apache.org/engine/1.7/user-guide.html#foreach-loop"><strong>#foreach</strong></a> directives to create a custom path and how to create a child template for a custom view.</p><p>By automating this process, you can save time and promote best practices across your team. With these techniques, you can quickly create new files and folders that adhere to your architecture pattern without worrying about the directory structure.</p><p>If you want to take your file template skills to the next level, check out my other articles on <a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4"><strong>creating a template for a custom view with MVP and a layout template</strong>,</a> and a more complex example on <a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1"><strong>templating Room database and Room entity</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c93c4c33689d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The power of file templates.]]></title>
            <link>https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd526bd815b2</guid>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 06:00:45 GMT</pubDate>
            <atom:updated>2023-03-22T08:18:24.579Z</atom:updated>
            <content:encoded><![CDATA[<h4>OPTIMIZE YOUR DEVELOPMENT WORKFLOW</h4><h3>The Power of Custom File Templates: Simplify Development and Boost Efficiency</h3><h4>Streamline Your Development Workflow: Boost Productivity with Custom File Templates and Naming Conventions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4qKbCXwUGS1PlH1Jr0M0A.gif" /></figure><p><strong>[Update 22/03/2023] -&gt; </strong><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d"><strong>Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</strong></a></p><p>Hi, as developers, we all want to write clean, maintainable code that is easy to understand and modify.</p><p>However, we often find ourselves spending more time creating boilerplate code than actually solving problems.</p><p>In this article, I’ll share some tips and tricks that have helped me streamline my workflow and create more efficient code. By using templates and custom file naming conventions, you can save time and reduce errors while keeping your code organised and consistent.</p><p>Whether you’re a seasoned pro or just starting out, these tips can help make your development process smoother and more enjoyable.</p><p>We’ll explore a simple and efficient approach to generating files in a flat architecture.</p><p><strong>External resources:</strong></p><ul><li>Here is a <a href="https://www.evandemond.com/programming/wide-and-flat">short article on benefits of Flat Architecture</a>.</li><li>Here is a <a href="https://medium.datadriveninvestor.com/model-view-presenter-mvp-5c3439227f83">short Medium Article</a> on MVP.</li><li>Here is the actual <a href="https://www.jetbrains.com/help/idea/templates-with-multiple-files.html">intelliJ</a> solution to create multiple files.</li><li>Here is the <a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> documentation.</li><li>Here is my IntelliJ File template article. <a href="https://medium.com/@piconemarc/86d1c5058516">IntelliJ File template. Create multiple folders and files in one operation</a>.</li></ul><h4>2-How to Use File Templates and Velocity Scripts</h4><p>In Intellij IDE, you can access the Preferences window and search for “file templates” in the search bar to find the file templates section.</p><p>In this section, the “Files” tab is used to implement the file templates, while the “Include” tab is used to store reusable code snippets using the Velocity template language’s #parse directive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_tvedlFBWznHej3eKL86g.png" /></figure><p>In my case, I created two Velocity scripts for my project. The first one, named “SnakeCaseToCamelCase,” helps to change the feature name from snake case to camel case.</p><p>The script is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc8744298fad6797142222f465d92e9c/href">https://medium.com/media/fc8744298fad6797142222f465d92e9c/href</a></iframe><p>The second script, named “ResPath,” retrieves the “Res” folder to create the related layout. It is a bit more complex and involves several Velocity template language features:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><h4><strong>3-Files and Folders.</strong></h4><p>So, with this let’s create the simplest part. In the “Files” tab, just add a new file template. The Name is to retrieve the template when it will be created, for me it will be “CustomView”, the extension could be “java”, “xml”, or others, for me “kt”, and finally the file name give the name and here the package name of the files.</p><p>As the first file I want to create is the <strong>View</strong> one, the first file name looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b026b13d0cf93cf074db7c3cc16cf84f/href">https://medium.com/media/b026b13d0cf93cf074db7c3cc16cf84f/href</a></iframe><p>This will be the parent file and will create a folder at the root of the selected file. Here the <strong>“$NAME”</strong> stands for the feature name. This file will be the opened one when creating multiple file templates, so if you are interested in opening another one on creating the file template, pass the selected one as parent.</p><p>In order to have the good package name, just add “<strong>${NAME}</strong>” at the end of the top line.</p><p>You could fill the template with whatever you want as a common part.</p><p>Just as example, mine look like this, I love the way the “#parse” is used to auto fill the class name and more:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f657d8e89add62f510c91eecd6c74954/href">https://medium.com/media/f657d8e89add62f510c91eecd6c74954/href</a></iframe><p>Now that we have the parent file, let’s create the <strong>Presenter</strong> file template. On the CustomView file template, add a new child template. Here I just have to fill the file extension, always “kt” for me, and the file path. as I want the presenter to be created in the same folder that the view, I enter the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d0ac13594792ef4eeba2f47cd1b459/href">https://medium.com/media/e0d0ac13594792ef4eeba2f47cd1b459/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXW61YdB3B5kawHiVHnLiQ.gif" /></figure><p>Like this, as the folder already exists, it just creates the file with the good name. Simply hardcode the extra “Presenter” information at the end of the parse directive.</p><p>And last the <strong>Contract</strong> the same way, I create a new child template and pass the following in the file name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a1bcd7ad0ce4147d6604a48937a8d66/href">https://medium.com/media/4a1bcd7ad0ce4147d6604a48937a8d66/href</a></iframe><p>Now the last file to create is the layout. I added a new child template and set extension to “xml”. As we already have the ResPath script, we just have to fill the file name with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1997bfbd703d8fe4f324dcfea0968606/href">https://medium.com/media/1997bfbd703d8fe4f324dcfea0968606/href</a></iframe><p>And that’s all. Now we could create the three files and their folder plus the layout folder and file by just naming the feature name in snake case, and that’s pretty useful!</p><h4><strong>3-Bonus.</strong></h4><p>As I use the same name convention for every new file in a package, I could use the $PACKAGE_NAME to retrieve the feature name and change it in camel case.</p><p>In the include tab I add a new file template named FolderToCamelCase.</p><p>The only thing I have to do here, is to split the package name on dot, loop on the created array and on the last iteration, I am on the feature name.</p><p>So my script for this is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1504ee92f1b86f4bc2ad7fb3032b8a65/href">https://medium.com/media/1504ee92f1b86f4bc2ad7fb3032b8a65/href</a></iframe><p>If I have to create a repository with this naming convention, I could create a file template and fill the file name like this:</p><p><strong>`#parse(“FolderToCamelCase.kt”)Repository`</strong></p><p>With this when you create a new file from an existing folder you no longer need to fill nothing, the IDE makes it for you. Coool!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bxTXmJ3AS29pq6UIYcpIaA.gif" /></figure><p>And of course we could create multiple files at the same time with the help of child templates.</p><p>I hope the time spent to read this article was useful for you and that you already know what you will template soon!!</p><p>Have a nice day!</p><p><strong>Enjoy, explore and keep coding !💪</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd526bd815b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2">The power of file templates.</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IntelliJ File templates. Create multiple folders and files in one operation!]]></title>
            <link>https://medium.com/mwm-io/intellij-file-templates-create-multiple-folders-and-files-in-one-operation-86d1c5058516?source=rss-76b40bb5220c------2</link>
            <guid isPermaLink="false">https://medium.com/p/86d1c5058516</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[scripting]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 05:59:50 GMT</pubDate>
            <atom:updated>2023-03-22T08:19:16.464Z</atom:updated>
            <content:encoded><![CDATA[<h4>Optimize your development workflow</h4><h4>A developer’s perspective on utilizing IntelliJ file templates for faster code creation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*2lW3mm9MfV5i2zRBBK2hmA.gif" /></figure><p><strong>[Update 22/03/2023] -&gt; </strong><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d"><strong>Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</strong></a></p><p>Hi, as a developer, we are always looking for ways to streamline our processes and make our work more efficient. One tool that I have found to be incredibly helpful in achieving this is IntelliJ file templates. In this article, I’ll be sharing my experience with using file templates and how they have helped me improve my development workflow.</p><ul><li><strong>Level:</strong> Medior to senior developers.</li><li><strong>Goal:</strong> Create folders with file templates.</li><li><strong>Requirement</strong>: Android Studio IDE or any IntelliJ based IDE.</li></ul><h4><strong>1-Why this article?</strong></h4><p>Before Android Studio 4.1, we had the possibility to create our own template with multiple files and folders, but unfortunately, this feature is no longer available.</p><p>However, with the help of IntelliJ file templates and Velocity Template language, we can still achieve a similar outcome.</p><p><strong>External resources:</strong></p><ul><li><a href="https://riggaroo.dev/custom-file-template-group-android-studiointellij/">Here</a> is the solution that existed before <strong>Android Studio 4.1</strong>.</li><li>Here the actual <a href="https://www.jetbrains.com/help/idea/templates-with-multiple-files.html">IntelliJ</a> solution to create multiple files</li><li>Here is the <a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> documentation, that will help us to manipulate variables.</li></ul><h4><strong>2-</strong>Creating Folder with File Templates</h4><p>File templates in IntelliJ IDEs can be a powerful tool for automating repetitive and tedious tasks. One of the most useful features is the ability to create multiple files and folders in one operation.</p><p>To use file templates, you’ll first need to create a new template. In the file name, you can use variables such as <strong>${NAME}</strong> to represent the name of the file or folder you want to create.</p><p>For example, you can use the variable <strong>${PACKAGE}</strong> to represent the name of the package you want to create. The template file name could look like this:</p><p>`<strong>${PACKAGE}/${NAME}`</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VcL8XfirX4oURJOK" /></figure><p>When you create a new file using this template, the IDE will prompt you to fill in the values for <strong>NAME</strong> and <strong>PACKAGE</strong>.</p><p>You can also use the Velocity Template Language (VTL) to format variables. For example, if we want to name the package in snake case “<strong>feature_name_view</strong>” and the associated file in camel case “<strong>FeatureNameView</strong>”, we don’t want to have to enter the same name in snake case and camel case every time we create a new file template, even if they are the same.</p><p>So, we could assume that now the <strong>${NAME}</strong> is no more the file name, but the feature name, and this is where VTL comes in.</p><p>We can use VTL’s<strong> StringUtils.removeAndHump()</strong> method to format the variables. This method will take the <strong>${NAME}</strong> variable (<em>which represents the feature name</em>) and remove the underscores, effectively converting it to camel case. This way, we don’t have to manually enter the same name in different cases, the IDE will do it for us. The resulting path would look like this: feature_name_view/${StringUtils.removeAndHump(feature_name_view, ”_”)}FileType.</p><p>And that’s the way it could be wrote in our file template file name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1513d0690f8a474d89bf650138e36b/href">https://medium.com/media/4e1513d0690f8a474d89bf650138e36b/href</a></iframe><p>This will allow you to only enter the feature name in snake case and have the IDE automatically create the file name in camel case. If the folder already exists, only the files will be created in the existing folder, otherwise the folder and attached files will be created.</p><h4><strong>3-Create a secondary folder with a child template.</strong></h4><p>You can also use the Velocity Template Language (VTL) to create a secondary folder with its own files at the same time. It’s important to note that to create multiple files or folders you will need to create a child template on your file template.</p><p>For example, to create a folder in the same root folder, you can simply copy-paste the previous example and change the variable <strong>${NAME}</strong> to a new custom variable in your child template file name, like:</p><p>${ATTACHED_FEATURE_NAME}/${StringUtils.removeAndHump(${ATTACHED_FEATURE_NAME}, “_”)}</p><p>The IDE will ask for the two feature names and will determine the two attached files names, creating them in their respective folder.</p><p>To create a folder in another root folder, you can use the <strong>${PACKAGE_NAME}</strong> (given by the IDE) variable from the parent file to retrieve the root folder.</p><p>One way to navigate to another root folder is to split the <strong>${PACKAGE_NAME}</strong> variable from the parent file on the dot, then create a loop on the resulting array. On each iteration, we can add “<strong>../</strong>” to a path variable. This way, we can go up one folder level at a time, until we reach the desired root folder. Once we have the root folder, we can create a new folder or file in any location within that folder tree.</p><p>It’s possible to write this script in the file name of the file template, but it could be a long line and hard to understand. A better solution is to use the “Includes” tab to store this script and use the <strong>#parse(“FileName.extention”)</strong> directive in your file templates to include it where you need it. This way you can easily reuse this script and keep your templates clean and readable.</p><p>For example, you can use a script like this to retrieve the “res” folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UuOZDBuFianPVpadMRxD9Q.png" /></figure><p>It’s important to note that there should be no spaces at the beginning or end of every line as this can cause issues with the creation of the package.</p><ul><li>The script begins by initializing all variables that will be used to create the path. This is necessary so that the Intellij IDE will not prompt the user to fill in the variable when creating the file.</li><li>Next, the script enters a foreach loop on the package name, which is split on the dot. The <strong>#set</strong> directive is used to set the value of the variable and avoid printing it. In the loop, on each iteration, “../” is added to the “$resRelativePath” variable, allowing the script to navigate up one folder in the root folder.</li><li>The script then checks if it is on the last iteration of the loop. If it is, it concatenates <strong>$endResPath</strong> to access the “res” folder.</li><li>Finally, the script calls the <strong>$resRelativePath</strong> variable, which is the desired result and can be used to create a secondary package or navigate to other desired folders within the package.</li></ul><p>Pretty cool, isn’t it? With this path we could now create a secondary package, and more if needed, with simply filling the package name.</p><p>In conclusion, file templates are a powerful tool in a developer’s toolbox. With a little bit of creativity and understanding of VTL, you can streamline your workflow and save time on repetitive tasks.</p><p>I hope you’ve seen the potential of the tips discussed in this article and how they can be applied to your own projects.</p><p>If you’re interested in seeing how I’ve used these techniques in my own work, check out my article “<a href="https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2"><strong>The power of file templates</strong></a>.”</p><p>Enjoy, explore, and keep coding! 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86d1c5058516" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/intellij-file-templates-create-multiple-folders-and-files-in-one-operation-86d1c5058516">IntelliJ File templates. Create multiple folders and files in one operation!</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>