PMD Xpath,如何比较2 @Image?
PMD Xpath, how to compare 2 @Image?
将一个路径的@Image 与静态字符串进行比较非常容易,但是如何比较 2 个路径的@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']]
如何将它们相互比较?
此外,如果您有 link 以及详细的 PMD XPath 语法示例。
基本的 PMD 页面有……基本的 ;)
自己回答:
//CatchStatement[//FormalParameter//VariableDeclaratorId/@Image =
//ThrowStatement//Arguments//Expression//Name/@Image]
将一个路径的@Image 与静态字符串进行比较非常容易,但是如何比较 2 个路径的@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']]
如何将它们相互比较?
此外,如果您有 link 以及详细的 PMD XPath 语法示例。 基本的 PMD 页面有……基本的 ;)
自己回答:
//CatchStatement[//FormalParameter//VariableDeclaratorId/@Image =
//ThrowStatement//Arguments//Expression//Name/@Image]