Search in sources :

Example 1 with StandardFieldInfo

use of apex.jorje.semantic.symbol.member.variable.StandardFieldInfo in project pmd by pmd.

the class ApexOpenRedirectRule method findSafeLiterals.

private void findSafeLiterals(AbstractApexNode<?> node) {
    ASTBinaryExpression binaryExp = node.getFirstChildOfType(ASTBinaryExpression.class);
    if (binaryExp != null) {
        findSafeLiterals(binaryExp);
    }
    ASTLiteralExpression literal = node.getFirstChildOfType(ASTLiteralExpression.class);
    if (literal != null) {
        int index = literal.jjtGetChildIndex();
        if (index == 0) {
            if (node instanceof ASTVariableDeclaration) {
                addVariable((ASTVariableDeclaration) node);
            } else if (node instanceof ASTBinaryExpression) {
                ASTVariableDeclaration parent = node.getFirstParentOfType(ASTVariableDeclaration.class);
                if (parent != null) {
                    addVariable(parent);
                }
                ASTAssignmentExpression assignment = node.getFirstParentOfType(ASTAssignmentExpression.class);
                if (assignment != null) {
                    ASTVariableExpression var = assignment.getFirstChildOfType(ASTVariableExpression.class);
                    if (var != null) {
                        addVariable(var);
                    }
                }
            }
        }
    } else {
        if (node instanceof ASTField) {
            /*
                 * sergey.gorbaty: Apex Jorje parser is returning a null from
                 * Field.getFieldInfo(), but the info is available from an inner
                 * field. DO NOT attempt to optimize this block without checking
                 * that Jorje parser actually fixed its bug.
                 * 
                 */
            try {
                final Field f = node.getNode().getClass().getDeclaredField("fieldInfo");
                f.setAccessible(true);
                final StandardFieldInfo fieldInfo = (StandardFieldInfo) f.get(node.getNode());
                if (fieldInfo.getType().getApexName().equalsIgnoreCase("String")) {
                    if (fieldInfo.getValue() != null) {
                        addVariable(fieldInfo);
                    }
                }
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : ASTBinaryExpression(net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) Field(java.lang.reflect.Field) ASTAssignmentExpression(net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression) ASTLiteralExpression(net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression) ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) StandardFieldInfo(apex.jorje.semantic.symbol.member.variable.StandardFieldInfo)

Aggregations

StandardFieldInfo (apex.jorje.semantic.symbol.member.variable.StandardFieldInfo)1 Field (java.lang.reflect.Field)1 ASTAssignmentExpression (net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression)1 ASTBinaryExpression (net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression)1 ASTField (net.sourceforge.pmd.lang.apex.ast.ASTField)1 ASTLiteralExpression (net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression)1 ASTVariableDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration)1 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)1