Search in sources :

Example 1 with TypeRef

use of apex.jorje.data.ast.TypeRef in project pmd by pmd.

the class ApexCRUDViolationRule method visit.

@Override
public Object visit(final ASTFieldDeclaration node, Object data) {
    ASTFieldDeclarationStatements field = node.getFirstParentOfType(ASTFieldDeclarationStatements.class);
    if (field != null) {
        TypeRef a = field.getNode().getTypeName();
        List<Identifier> names = a.getNames();
        List<TypeRef> typeArgs = a.getTypeArguments();
        if (!names.isEmpty()) {
            StringBuffer sb = new StringBuffer();
            for (Identifier id : names) {
                sb.append(id.getValue()).append(".");
            }
            sb.deleteCharAt(sb.length() - 1);
            switch(sb.toString().toLowerCase(Locale.ROOT)) {
                case "list":
                case "map":
                    addParametersToMapping(node, typeArgs);
                    break;
                default:
                    varToTypeMapping.put(Helper.getFQVariableName(node), getSimpleType(sb.toString()));
                    break;
            }
        }
    }
    final ASTSoqlExpression soql = node.getFirstChildOfType(ASTSoqlExpression.class);
    if (soql != null) {
        checkForAccessibility(soql, data);
    }
    return data;
}
Also used : Identifier(apex.jorje.data.Identifier) ASTFieldDeclarationStatements(net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclarationStatements) ArrayTypeRef(apex.jorje.data.ast.TypeRefs.ArrayTypeRef) TypeRef(apex.jorje.data.ast.TypeRef) ClassTypeRef(apex.jorje.data.ast.TypeRefs.ClassTypeRef) ASTSoqlExpression(net.sourceforge.pmd.lang.apex.ast.ASTSoqlExpression)

Example 2 with TypeRef

use of apex.jorje.data.ast.TypeRef in project pmd by pmd.

the class Helper method getFQVariableName.

static String getFQVariableName(final ASTNewKeyValueObjectExpression variable) {
    NewKeyValueObjectExpression n = variable.getNode();
    TypeRef typeRef = n.getTypeRef();
    String objType = typeRef.getNames().get(0).getValue();
    StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objType);
    return sb.toString();
}
Also used : TypeRef(apex.jorje.data.ast.TypeRef) NewKeyValueObjectExpression(apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression) ASTNewKeyValueObjectExpression(net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression)

Aggregations

TypeRef (apex.jorje.data.ast.TypeRef)2 Identifier (apex.jorje.data.Identifier)1 ArrayTypeRef (apex.jorje.data.ast.TypeRefs.ArrayTypeRef)1 ClassTypeRef (apex.jorje.data.ast.TypeRefs.ClassTypeRef)1 NewKeyValueObjectExpression (apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression)1 ASTFieldDeclarationStatements (net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclarationStatements)1 ASTNewKeyValueObjectExpression (net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression)1 ASTSoqlExpression (net.sourceforge.pmd.lang.apex.ast.ASTSoqlExpression)1