【问题标题】:Specifying argument attributes using JavaDoc notation (CFscript)使用 JavaDoc 表示法 (CFscript) 指定参数属性
【发布时间】:2016-10-25 19:57:42
【问题描述】:

我最近尝试使用cfcomponentcfscript 版本以及JavaDoc 表示法并出现错误:

系统试图使用未定义的值,通常 表示您的代码或某些系统代码中的编程错误。

空指针是未定义值的另一个名称。

来自CF docs

/** 
 * custom metadata for a cfc defined using annotation as well as key-value pairs 
 * @cfcMetadata1 "cfc metadata1"
 */ 
component cfcMetadata2 = "cfc metadata2"
{ 
    /** 
     * custom metadata for a property defined using annotation as well as key-value pairs 
     * @propMetadata1 "property metadata1"
     */ 
    property type="numeric" name="age" default="10" propMetadata2="property metadata2"; 

    /** 
     * custom metadata for a function/argument using both annotation and key-value pairs 
     * @arg1.argmdata1 "arg metadata1"
     * output true 
     * @fnMetadata1 "function metadata1"
     */ 
    public string function foo(required numeric arg1=20 argmdata2="arg metadata2") fnMetadata2="function metadata2"
    { 
        writedump(getmetadata(this)); 
        return arg1; 
    } 
}

我的代码:

/**
 * @displayName Test
 * @output false
 *
 * @since 2016-10-25
 * @version 1.0
 */
component {

    /**
     * I am a test function.
     * 
     * @limitFrom.required false
     * @limitFrom.default 0
     *
     * @limitBy.required false
     * @limitBy.default 0
     *
     * @returnFormat "json"
     *
     * @since 2016-10-25
     * @version 1.0
     */
    remote query function test(
        numeric limitFrom,
        numeric limitBy
    ) {
        return queryNew("");
    }
}

仅当我尝试使用 JavaDoc 表示法为参数分配默认值时才会发生这种情况,即,

@limitFrom.default 0

@limitBy.default 0

删除这些,一切都很好。不知道为什么会这样?

【问题讨论】:

  • 由于所有其他属性似乎都有效,可能是一个错误。完全猜测,但是......鉴于“默认”是许多语言中的关键字,如果它以某种方式导致内部解析失败,我不会感到惊讶......
  • 你有没有弄清楚这是错误还是代码问题?
  • @Leigh 我又试了一次,只有当我使用default 作为函数参数时才会出现错误。我还将default 用于property,它按预期工作,所以看起来像一个错误。
  • 是的,听起来像。可能想为下一个人提交错误报告(如果您还没有)。

标签: coldfusion cfml cfc coldfusion-11


【解决方案1】:

我知道您专门询问过 JavaDoc 表示法,但我不是粉丝,您可能还没有看到任何替代方法。我更喜欢这种语法。

component
  displayName="test"
  output="false"
  hint="blah blah description..."
{

    // beware of `default`--it doesn't do what you might think.
    //  it's ignored unless you use ORM
    property type="numeric" name="age" default="10"
        hint="blah blah description..."
        propMetadata2="property metadata2";

    remote query function test(
        numeric limitFrom=0 hint="blah blah description...",
        numeric limitBy=0 hint="blah blah description..."
    )
    hint="I am a test function"
    {
        return queryNew("");
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    相关资源
    最近更新 更多