[pmd-devel] How to check type of variable with PMD?
A source code analyzer
Brought to you by:
adangel,
juansotuyo
|
From: Valeriy M. <v.m...@gm...> - 2017-10-02 14:01:37
|
Hello,
I will begin immediately with an example:
void okMethod3() {
// ...
MyType con = connectionFactory.createConnection();
// ...
publisher.close();
session.close();
con.stop(); // !!! does not free jms resources
}
void okMethod3() {
// ...
Connection con = connectionFactory.createConnection();
// ...
publisher.close();
session.close();
con.stop(); // !!! does not free jms resources
other.close();
}
I need to add violation to line `con.stop()` when `con` have
`Connection` type. How to check type of variable with PMD using XPath?
I tried this, xpath expression:
//BlockStatement
[ends-with(Statement/StatementExpression/PrimaryExpression/PrimaryPrefix/Name/@Image,
'.stop')]
[starts-with(Statement/StatementExpression/PrimaryExpression/PrimaryPrefix/Name/@Image,
ancestor::MethodDeclaration//BlockStatement/LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId
[../Type/ReferenceType/ClassOrInterfaceType[@Image='Connection']]
[//ImportDeclaration/Name[@Image='javax.jms.Connection']]
)]
But it is not works
--
Regards,
Valeriy Manenkov
|