【问题标题】:Is there a standard way to document groovy map properties?是否有标准方法来记录 groovy 地图属性?
【发布时间】:2020-09-28 16:24:16
【问题描述】:

是否有在 Groovy 中记录地图属性的标准方法?

对于以下功能,配置包含多个可选属性,例如:

  • ignore
  • dir
  • tags
def publish(Map config) {
  config.ignore ?= true
  // ...
}

我看了What is the standard way to use JavaDoc to document a Map? ;但是,这不适用于动态地图。理想情况下,我正在寻找类似 JSDoc 的 @typedef@property

【问题讨论】:

    标签: groovy javadoc groovydoc


    【解决方案1】:

    除了为您的方法添加一些 JavaDoc 选项之外,没有真正的方法来记录这些...

    如果这是一个需要文档的公共 API,您可以转到传递实际参数,或者您可以创建一个用于传递这些选项的类,即:

    import groovy.transform.ToString
    import groovy.transform.Immutable
    
    @ToString
    @Immutable
    class Options {
        boolean debug = false
        File dir = new File('.')
        List<String> tags = []
    }
    
    println new Options()
    println new Options(debug: true, dir: new File("/tmp"))
    println new Options(tags: ['a', 'b'])
    

    打印出来的

    Options(false, ., [])
    Options(true, /tmp, [])
    Options(false, ., [a, b])
    

    【讨论】:

      猜你喜欢
      • 2020-09-19
      • 2015-11-03
      • 2013-08-04
      • 2018-03-11
      • 2014-10-21
      • 2010-09-15
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      相关资源
      最近更新 更多