【问题标题】:auto-checking java code for correct conventions and documentation [closed]自动检查 Java 代码以获取正确的约定和文档 [关闭]
【发布时间】:2011-05-24 18:57:44
【问题描述】:

我正在评估一些学生,我正在寻找一种自动检查 Java 约定(驼峰式大小写)和文档的方法,是否有任何工具可以做到这一点? (最好是在线工具)

【问题讨论】:

    标签: java documentation conventions camelcasing


    【解决方案1】:

    您可以使用Checkstyle。但是,标准检查(sun 编码标准)非常严格,您可能希望根据您的喜好从用于配置的 XML 中删除一些检查

    【讨论】:

      【解决方案2】:

      虽然 Checkstyle 等工具可以检查对样式约定的遵守情况,但它们不应用于评估文档。是的,checkstyle 可以检查文档是否存在,但不能检查该文档是否正确或以任何方式有用 - 无用的文档比没有更糟糕,因为它至少不会弄乱源代码。例如,checkstyle 会考虑:

      /**
       * Gets the amount.
       * @return the amount
       */
      BigDecimal getAmount() {
          return amount;
      }
      
      
      /**
       * Sets the amount.
       * @param amount the amount to set
       */
      void setAmount(BigDecimal amount) {
          this.amount = amount;
      }
      

      更好(因为存在 cmets 并且所有参数和返回值都记录在案)
      /**
       * @return the amount of this transaction (positive for deposits, negative for withdrawals)
       */
      BigDecimal getAmount() {
          return amount;
      }
      
      
      /**
       * @see #getAmount()
       */
      void setAmount(BigDecimal amount) {
          this.amount = amount;
      }
      

      因为后者没有记录方法参数...

      简而言之,机器无法验证文档是否足够,并且容易获得的指标仅显示部分图片 - 在我看来,这在很大程度上是不相关的部分。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-06
        • 2014-05-15
        相关资源
        最近更新 更多