use of apex.jorje.semantic.ast.statement.VariableDeclaration in project pmd by pmd.
the class Helper method getFQVariableName.
static String getFQVariableName(final ASTVariableDeclaration variable) {
VariableDeclaration n = variable.getNode();
StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(n.getLocalInfo().getName());
return sb.toString();
}
use of apex.jorje.semantic.ast.statement.VariableDeclaration in project pmd by pmd.
the class ApexSOQLInjectionRule method findSanitizedVariables.
private void findSanitizedVariables(AbstractApexNode<?> node) {
final ASTVariableExpression left = node.getFirstChildOfType(ASTVariableExpression.class);
final ASTLiteralExpression literal = node.getFirstChildOfType(ASTLiteralExpression.class);
final ASTMethodCallExpression right = node.getFirstChildOfType(ASTMethodCallExpression.class);
// look for String a = 'b';
if (literal != null) {
if (left != null) {
Object o = literal.getNode().getLiteral();
if (o instanceof Integer || o instanceof Boolean || o instanceof Double) {
safeVariables.add(Helper.getFQVariableName(left));
}
if (o instanceof String) {
if (SELECT_PATTERN.matcher((String) o).matches()) {
selectContainingVariables.put(Helper.getFQVariableName(left), Boolean.TRUE);
} else {
safeVariables.add(Helper.getFQVariableName(left));
}
}
}
}
// look for String a = String.escapeSingleQuotes(foo);
if (right != null) {
if (Helper.isMethodName(right, STRING, ESCAPE_SINGLE_QUOTES)) {
if (left != null) {
safeVariables.add(Helper.getFQVariableName(left));
}
}
}
if (node instanceof ASTVariableDeclaration) {
VariableDeclaration o = (VariableDeclaration) node.getNode();
switch(o.getLocalInfo().getType().getApexName().toLowerCase(Locale.ROOT)) {
case INTEGER:
case ID:
case BOOLEAN:
case DECIMAL:
case LONG:
case DOUBLE:
safeVariables.add(Helper.getFQVariableName(left));
break;
default:
break;
}
}
}
Aggregations