Search in sources :

Example 1 with ASTField

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));
        }
    }
}
Also used : ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField)

Example 2 with ASTField

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;
}
Also used : ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 3 with ASTField

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();
}
Also used : ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) Field(apex.jorje.semantic.ast.member.Field)

Example 4 with ASTField

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();
}
Also used : ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) Field(apex.jorje.semantic.ast.member.Field)

Example 5 with ASTField

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;
}
Also used : ASTUserClass(net.sourceforge.pmd.lang.apex.ast.ASTUserClass) Node(net.sourceforge.pmd.lang.ast.Node) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ASTField (net.sourceforge.pmd.lang.apex.ast.ASTField)8 ASTVariableDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration)4 Field (apex.jorje.semantic.ast.member.Field)2 ASTAssignmentExpression (net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression)2 StandardFieldInfo (apex.jorje.semantic.symbol.member.variable.StandardFieldInfo)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ASTBinaryExpression (net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression)1 ASTLiteralExpression (net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression)1 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)1 ASTNewObjectExpression (net.sourceforge.pmd.lang.apex.ast.ASTNewObjectExpression)1 ASTUserClass (net.sourceforge.pmd.lang.apex.ast.ASTUserClass)1 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)1 Node (net.sourceforge.pmd.lang.ast.Node)1