【发布时间】: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 页面具有...以及基本的 ;)
【问题讨论】: