use of net.sourceforge.pmd.lang.apex.ast.ASTField in project pmd by pmd.
the class ApexDangerousMethodsRule method collectBenignVariables.
private void collectBenignVariables(ASTUserClass node) {
List<ASTField> fields = node.findDescendantsOfType(ASTField.class);
for (ASTField field : fields) {
if (BOOLEAN.equalsIgnoreCase(field.getNode().getFieldInfo().getType().getApexName())) {
whiteListedVariables.add(Helper.getFQVariableName(field));
}
}
List<ASTVariableDeclaration> declarations = node.findDescendantsOfType(ASTVariableDeclaration.class);
for (ASTVariableDeclaration decl : declarations) {
if (BOOLEAN.equalsIgnoreCase(decl.getNode().getLocalInfo().getType().getApexName())) {
whiteListedVariables.add(Helper.getFQVariableName(decl));
}
}
}
use of net.sourceforge.pmd.lang.apex.ast.ASTField in project pmd by pmd.
the class ApexSuggestUsingNamedCredRule method visit.
@Override
public Object visit(ASTUserClass node, Object data) {
if (Helper.isTestMethodOrClass(node)) {
return data;
}
List<ASTVariableDeclaration> variableDecls = node.findDescendantsOfType(ASTVariableDeclaration.class);
for (ASTVariableDeclaration varDecl : variableDecls) {
findAuthLiterals(varDecl);
}
List<ASTField> fieldDecl = node.findDescendantsOfType(ASTField.class);
for (ASTField fDecl : fieldDecl) {
findFieldLiterals(fDecl);
}
List<ASTMethodCallExpression> methodCalls = node.findDescendantsOfType(ASTMethodCallExpression.class);
for (ASTMethodCallExpression method : methodCalls) {
flagAuthorizationHeaders(method, data);
}
listOfAuthorizationVariables.clear();
return data;
}
use of net.sourceforge.pmd.lang.apex.ast.ASTField in project pmd by pmd.
the class Helper method getFQVariableName.
static String getFQVariableName(final ASTField variable) {
Field n = variable.getNode();
StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(n.getFieldInfo().getName());
return sb.toString();
}
use of net.sourceforge.pmd.lang.apex.ast.ASTField in project pmd by pmd.
the class Helper method getVariableType.
static String getVariableType(final ASTField variable) {
Field n = variable.getNode();
StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(n.getFieldInfo().getName());
return sb.toString();
}
use of net.sourceforge.pmd.lang.apex.ast.ASTField in project pmd by pmd.
the class TooManyFieldsRule method visit.
@Override
public Object visit(ASTUserClass node, Object data) {
int maxFields = getProperty(MAX_FIELDS_DESCRIPTOR);
stats = new HashMap<>(5);
nodes = new HashMap<>(5);
List<ASTField> l = node.findDescendantsOfType(ASTField.class);
for (ASTField fd : l) {
if (fd.getNode().getModifierInfo().all(FINAL, STATIC)) {
continue;
}
ASTUserClass clazz = fd.getFirstParentOfType(ASTUserClass.class);
if (clazz != null) {
bumpCounterFor(clazz);
}
}
for (Map.Entry<String, Integer> entry : stats.entrySet()) {
int val = entry.getValue();
Node n = nodes.get(entry.getKey());
if (val > maxFields) {
addViolation(data, n);
}
}
return data;
}
Aggregations