We have written a custom pmd rule where we want to throw violations if a string concatenation occurs with + operator.
But the violations are being thrown even for arithmetic additions containing + in the statement.
Please find the attachment for the snippet of violations flagged for an arithmetic operation.
Below is our code:
public class InefficientStringOperationRule extends AbstractApexRule {
@Override public Object visit(ASTExpressionStatement node, Object data) { //to check string concatination try { String str = node.getNode().toString(); if( str.contains("+") && !str.contains("System.debug") ) { if(!str.contains("system.debug") ) addViolation(data, node); } }catch(java.util.NoSuchElementException e) { //Re throwing it does not make sense, nothing to do. Even puttting in logs adds no value. }
return data;
} }
Thanks for the question. Would you mind to create this question in our new discussions place at github? https://github.com/pmd/pmd/discussions
Log in to post a comment.
We have written a custom pmd rule where we want to throw violations if a string concatenation occurs with + operator.
But the violations are being thrown even for arithmetic additions containing + in the statement.
Please find the attachment for the snippet of violations flagged for an arithmetic operation.
Below is our code:
public class InefficientStringOperationRule extends AbstractApexRule {
@Override
public Object visit(ASTExpressionStatement node, Object data) {
//to check string concatination
try {
String str = node.getNode().toString();
if( str.contains("+") && !str.contains("System.debug") ) {
if(!str.contains("system.debug") )
addViolation(data, node);
}
}catch(java.util.NoSuchElementException e) {
//Re throwing it does not make sense, nothing to do. Even puttting in logs adds no value.
}
}
}
Thanks for the question. Would you mind to create this question in our new discussions place at github? https://github.com/pmd/pmd/discussions