Where can I find list of variables available in Android Studio "Code and File Templates"?

642 Views Asked by At

When customizing java code and file templates, where can I get a list of variables that are available?

For example, in customizing java class, I know I can use ${USER} and ${DATE}, I guessed (correctly) that ${YEAR} was available ... but I would like to find all predefined variables that are available for use.

I have looked at the general VTL language documentation from Apache, but have not found the information I am searching for.

1

There are 1 best solutions below

0
On

I found the list! In Android Studio, I went to File | New | Edit File Templates That brought up a dialog "File and Code Templates" and the default tab was "File". The default file type is HTML. In the description box it has a nice long text that shows them. The HTML for this was in default.html inside java_resources_en.jar located in C:\Program Files\Android\Android Studio\lib\java_resources_en.jar

Along with static text, code and comments, you can also use predefined variables (listed below) that will then be expanded like macros into the corresponding values.
It is also possible to specify an arbitrary number of custom variables in the format ${<VARIABLE_NAME>}. In this case, before the new file is created, you will be prompted with a dialog where you can define particular values for all custom variables.
Using the #parse directive, you can include templates from the Includes tab, by specifying the full name of the desired template as a parameter in quotation marks. For example:
#parse("File Header.java")
Predefined variables will take the following values:
${PACKAGE_NAME}         name of the package in which the new file is created
${NAME}         name of the new file specified by you in the New <TEMPLATE_NAME> dialog
${USER}         current user system login name
${DATE}         current system date
${TIME}         current system time
${YEAR}         current year
${MONTH}        current month
${MONTH_NAME_SHORT}         first 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL}      full name of the current month. Example: January, February, etc.
${DAY}      current day of the month
${DAY_NAME_SHORT}       first 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_FULL}        full name of the current day. Example: Monday, Tuesday, etc.
${HOUR}         current hour
${MINUTE}       current minute
${PROJECT_NAME}         the name of the current project