Search in sources :

Example 1 with Identifier

use of apex.jorje.data.Identifier in project pmd by pmd.

the class ApexCRUDViolationRule method innerAddParametrizedClassToMapping.

private void innerAddParametrizedClassToMapping(final ASTFieldDeclaration node, final ClassTypeRef innerClassRef) {
    List<Identifier> ids = innerClassRef.getNames();
    StringBuffer argType = new StringBuffer();
    for (Identifier id : ids) {
        argType.append(id.getValue()).append(".");
    }
    argType.deleteCharAt(argType.length() - 1);
    addVariableToMapping(Helper.getFQVariableName(node), argType.toString());
}
Also used : Identifier(apex.jorje.data.Identifier)

Example 2 with Identifier

use of apex.jorje.data.Identifier in project pmd by pmd.

the class ApexCRUDViolationRule method extractObjectTypeFromESAPI.

private void extractObjectTypeFromESAPI(final ASTMethodCallExpression node, final String dmlOperation) {
    final ASTVariableExpression var = node.getFirstChildOfType(ASTVariableExpression.class);
    if (var != null) {
        final ASTReferenceExpression reference = var.getFirstChildOfType(ASTReferenceExpression.class);
        if (reference != null) {
            List<Identifier> identifiers = reference.getNode().getNames();
            if (identifiers.size() == 1) {
                StringBuilder sb = new StringBuilder().append(node.getNode().getDefiningType().getApexName()).append(":").append(identifiers.get(0).getValue());
                checkedTypeToDMLOperationViaESAPI.put(sb.toString(), dmlOperation);
            }
        }
    }
}
Also used : ASTReferenceExpression(net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) Identifier(apex.jorje.data.Identifier)

Example 3 with Identifier

use of apex.jorje.data.Identifier in project pmd by pmd.

the class ApexCRUDViolationRule method collectCRUDMethodLevelChecks.

private void collectCRUDMethodLevelChecks(final ASTMethodCallExpression node) {
    final String method = node.getNode().getMethodName();
    final ASTReferenceExpression ref = node.getFirstChildOfType(ASTReferenceExpression.class);
    if (ref == null) {
        return;
    }
    List<Identifier> a = ref.getNode().getNames();
    if (!a.isEmpty()) {
        extractObjectAndFields(a, method, node.getNode().getDefiningType().getApexName());
    } else {
        // see if ESAPI
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_VIEW)) {
            extractObjectTypeFromESAPI(node, IS_ACCESSIBLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_CREATE)) {
            extractObjectTypeFromESAPI(node, IS_CREATEABLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_UPDATE)) {
            extractObjectTypeFromESAPI(node, IS_UPDATEABLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_DELETE)) {
            extractObjectTypeFromESAPI(node, IS_DELETABLE);
        }
        // see if getDescribe()
        final ASTMethodCallExpression nestedMethodCall = ref.getFirstChildOfType(ASTMethodCallExpression.class);
        if (nestedMethodCall != null) {
            if (isLastMethodName(nestedMethodCall, S_OBJECT_TYPE, GET_DESCRIBE)) {
                String resolvedType = getType(nestedMethodCall);
                if (!typeToDMLOperationMapping.get(resolvedType).contains(method)) {
                    typeToDMLOperationMapping.put(resolvedType, method);
                }
            }
        }
    }
}
Also used : ASTReferenceExpression(net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression) Identifier(apex.jorje.data.Identifier) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 4 with Identifier

use of apex.jorje.data.Identifier in project pmd by pmd.

the class ApexOpenRedirectRule method checkNewObjects.

/**
 * Traverses all new declarations to find PageReferences
 *
 * @param node
 * @param data
 */
private void checkNewObjects(ASTNewObjectExpression node, Object data) {
    ASTMethod method = node.getFirstParentOfType(ASTMethod.class);
    if (method != null && Helper.isTestMethodOrClass(method)) {
        return;
    }
    ClassTypeRef classRef = (ClassTypeRef) node.getNode().getTypeRef();
    Identifier identifier = classRef.getNames().get(0);
    if (identifier.getValue().equalsIgnoreCase(PAGEREFERENCE)) {
        getObjectValue(node, data);
    }
}
Also used : ClassTypeRef(apex.jorje.data.ast.TypeRefs.ClassTypeRef) Identifier(apex.jorje.data.Identifier) ASTMethod(net.sourceforge.pmd.lang.apex.ast.ASTMethod)

Example 5 with Identifier

use of apex.jorje.data.Identifier in project pmd by pmd.

the class Helper method getFQVariableName.

static String getFQVariableName(final ASTFieldDeclaration variable) {
    FieldDeclaration n = variable.getNode();
    String name = "";
    try {
        java.lang.reflect.Field f = n.getClass().getDeclaredField("name");
        f.setAccessible(true);
        Identifier nameField = (Identifier) f.get(n);
        name = nameField.getValue();
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(name);
    return sb.toString();
}
Also used : ASTFieldDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration) FieldDeclaration(apex.jorje.semantic.ast.statement.FieldDeclaration) Identifier(apex.jorje.data.Identifier)

Aggregations

Identifier (apex.jorje.data.Identifier)9 Field (java.lang.reflect.Field)3 ClassTypeRef (apex.jorje.data.ast.TypeRefs.ClassTypeRef)2 ASTReferenceExpression (net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression)2 TypeRef (apex.jorje.data.ast.TypeRef)1 ArrayTypeRef (apex.jorje.data.ast.TypeRefs.ArrayTypeRef)1 FieldDeclaration (apex.jorje.semantic.ast.statement.FieldDeclaration)1 ASTFieldDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration)1 ASTFieldDeclarationStatements (net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclarationStatements)1 ASTMethod (net.sourceforge.pmd.lang.apex.ast.ASTMethod)1 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)1 ASTSoqlExpression (net.sourceforge.pmd.lang.apex.ast.ASTSoqlExpression)1 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)1