【问题标题】:How to create a custom get method snippet in VsCode如何在 VsCode 中创建自定义 get 方法片段
【发布时间】:2019-08-22 21:12:48
【问题描述】:

我想在 VsCode 上创建一个自定义 get 方法 sn-p 并且我知道用户 sn-ps 所以创建了一个,但它没有按预期出现。

我尝试创建一个像这样的 sn-p(用于 java):

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

但是当我输入 sn-p 的第一个“参数”时,它与第三个(在返回行上)相关,我想要的但全部是小写的,如果可能的话是骆驼大小写,所以结果会是这样的:

public Type getPropertyName(){
    return propertyName;
}

不是这个:

public Type getPropertyName(){
    return PropertyName;
}

【问题讨论】:

  • 我并不是要粗鲁,但你为什么不使用 Java IDE? Eclipse 可以通过上下文菜单生成 getterssetters。您只需键入属性名称及其类。然后将鼠标指针放在名称上,右键单击以调出上下文菜单并选择 generate 选项。
  • 我知道这是 eclipse 中的一个东西,但我喜欢使用 Vscode,因为它轻巧且多功能。我不想只为一种语言下载 IDE,你知道吗?

标签: java visual-studio-code code-snippets


【解决方案1】:

在对 Regex 进行一些研究后,我可以找到解决方案! get 方法的简化是这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 2015-07-11
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    相关资源
    最近更新 更多