【问题标题】:PMD Xpath, how to compare 2 @Image?PMD Xpath,如何比较 2 @Image?
【发布时间】:2016-06-29 13:40:24
【问题描述】:

将一个路径的@Image 与静态字符串进行比较非常容易,但是如何比较两个路径的@Image 呢?

应该触发规则的代码:

public class Foo implements {
      public String checkDBConnexion() {
        try {
            int result = jdbcTemplate.queryForObject("SELECT 1 FROM dual ", Integer.class);

        } catch (DataAccessException e) {
            // This is Ok : throw new MyException(test, e);
            // this is not : hrow new MyException(test);
            // This is also not ok if there are no thrown;
            return "KO : " + e.getMessage();
        }
    }
}

Catch 块的参数名称的 Xpath:

//CatchStatement[//FormalParameter//VariableDeclaratorId]

被抛出方法的变量名的Xpath:

//ThrowStatement//Arguments//Expression//Name

很容易将两者与“e”进行比较:

//CatchStatement[//FormalParameter//VariableDeclaratorId[@Image = 'e']]

//CatchStatement[//ThrowStatement//Arguments//Expression//Name[@Image = 'e']]

如何比较它们?

另外,如果您有详细的 PMD XPath 合成器示例的链接。 基本的 PMD 页面具有...以及基本的 ;)

【问题讨论】:

    标签: xpath pmd


    【解决方案1】:

    回答我自己:

    //CatchStatement[//FormalParameter//VariableDeclaratorId/@Image = 
    //ThrowStatement//Arguments//Expression//Name/@Image]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 2014-10-10
      • 2022-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多