Improve Java snippets with variable transformations
See https://code.visualstudio.com/updates/v1_17#_snippet-transforms
The VS Code snippet engine now supports variable transformations.
Transformations can change the value of a variable before inserting it.
The format is var_name/regular_expression/format_string/options.
The sample below is a snippet that creates a public Java class whose name
is derived from the filename.
"Public Class": {
"prefix": "pclass",
"body": [
"public class ${1:${TM_FILENAME/(.*)\\.java/${1:/capitalize}/}} {",
"\tpublic $1 (${2:params}) {",
"\t\t$0",
"\t}",
"}"
],
"description": "New public class"
}
The new part is this: ${TM_FILENAME/(.*)\\.java/${1:/capitalize}/} and this is what it does:
Resolve the value for TM_FILENAME, for example myClass.java.
Use the regular expression /(.*)\\.java to create a matching group for everything that precedes
the .java ending, for example myClass.
Take the value of the first matching group, ensure it start with capital letters (/capitalize),
and insert it (MyClass).