如何在 VsCode 中创建自定义 get 方法片段

How to create a custom get method snippet in VsCode

我想在 VsCode 上创建一个自定义 get 方法片段,我知道用户片段是这样创建的,但它没有按预期出现。

我试着创建了一个这样的片段(java):

"get": {
        "prefix": "get",
        "body": [
            "public ${1:Type} get${2:Property} () {",
            "\treturn ${2: property};",
            "}"
        ],
        "description": "Creates a get method"
    }

但是当我输入片段的第一个 "parameter" 时,它与第三个(在 return 行)相关联,这是我想要的,但都是小写的,如果可能的话驼峰式大小写,所以结果会是这样的:

public Type getPropertyName(){
    return propertyName;
}

而不是这个:

public Type getPropertyName(){
    return PropertyName;
}

经过对 Regex 的一些研究,我可以找到解决方案! get 方法的 sinppet 是这个:

"get": {
        "prefix": "get",
        "body": [
            "public ${1:Type} get${2:Property} () {",
            "\treturn ${2/([A-Z])/${1:/downcase}/};",
            "}"
        ],
        "description": "Creates a get method"
    }