是否有记录 groovy 地图属性的标准方法?

Is there a standard way to document groovy map properties?

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

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

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

我看了What is the standard way to use JavaDoc to document a Map? ; however, this doesn't work with dynamic Maps. Ideally I'm looking for something like JSDoc's @typedef or @property

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

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

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])