Search in sources :

Example 1 with ForNode

use of org.dbflute.twowaysql.node.ForNode in project dbflute-core by dbflute.

the class DfParameterAutoDetectForNode method analyzeForNodeElementType.

protected DfForNodeDetectedPropertyInfo analyzeForNodeElementType(Node node, String propertyName) {
    if (isPmCommentNestedProperty(propertyName) || isPmCommentMethodCall(propertyName)) {
        return null;
    }
    final DfLanguageGrammar grammar = getLanguageGrammar();
    DfForNodeDetectedPropertyInfo detected = null;
    for (int i = 0; i < node.getChildSize(); i++) {
        final Node childNode = node.getChild(i);
        if (childNode instanceof BindVariableNode) {
            final BindVariableNode bindNode = (BindVariableNode) childNode;
            final String expression = bindNode.getExpression();
            if (!isPmCommentEqualsCurrent(expression)) {
                continue;
            }
            if (isPmCommentNestedProperty(expression) || isPmCommentMethodCall(expression)) {
                continue;
            }
            // /*#current*/ here
            final String testValue = bindNode.getTestValue();
            if (testValue == null) {
                continue;
            }
            final String propertyType = derivePropertyTypeFromTestValue(testValue);
            final String propertyOption = derivePropertyOptionFromTestValue(testValue);
            if (Srl.is_NotNull_and_NotTrimmedEmpty(propertyType)) {
                detected = new DfForNodeDetectedPropertyInfo();
                final String generic = grammar.buildGenericOneClassHint(propertyType);
                detected.setPropertyType("List" + generic);
                detected.setPropertyOption(propertyOption);
            }
        } else if (childNode instanceof ForNode) {
            final ForNode nestedNode = (ForNode) childNode;
            final String expression = nestedNode.getExpression();
            if (!isPmCommentStartsWithCurrent(expression)) {
                continue;
            }
            // /*FOR #current.xxx*/ here
            final String nestedForPropName = substringPmCommentCurrentRear(expression);
            // recursive call
            detected = analyzeForNodeElementType(nestedNode, nestedForPropName);
            if (detected != null) {
                final String generic = grammar.buildGenericOneClassHint(detected.getPropertyType());
                detected.setPropertyType("List" + generic);
            }
        } else if (childNode instanceof ScopeNode) {
            // IF, Begin, First, ...
            // recursive call
            detected = analyzeForNodeElementType(childNode, propertyName);
        }
        if (detected != null) {
            break;
        }
    }
    if (detected == null) {
        return null;
    }
    return detected;
}
Also used : ForNode(org.dbflute.twowaysql.node.ForNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) ScopeNode(org.dbflute.twowaysql.node.ScopeNode) Node(org.dbflute.twowaysql.node.Node) ForNode(org.dbflute.twowaysql.node.ForNode) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) ScopeNode(org.dbflute.twowaysql.node.ScopeNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode)

Example 2 with ForNode

use of org.dbflute.twowaysql.node.ForNode in project dbflute-core by dbflute.

the class DfParameterAutoDetectProcess method doProcessAutoDetect.

protected void doProcessAutoDetect(String sql, Map<String, String> propertyNameTypeMap, Map<String, String> propertyNameOptionMap, Set<String> autoDetectedPropertyNameSet, Node node) {
    // because simple specification is very important here
    if (node instanceof BindVariableNode) {
        final BindVariableNode bindNode = (BindVariableNode) node;
        processAutoDetectBindNode(sql, propertyNameTypeMap, propertyNameOptionMap, autoDetectedPropertyNameSet, bindNode);
    } else if (node instanceof IfNode) {
        final IfNode ifNode = (IfNode) node;
        processAutoDetectIfNode(sql, propertyNameTypeMap, propertyNameOptionMap, ifNode);
        // process alternate boolean methods, supported with auto-detect
        processAlternateBooleanMethodIfNode(sql, ifNode);
    } else if (node instanceof ForNode) {
        processAutoDetectForNode(sql, propertyNameTypeMap, propertyNameOptionMap, (ForNode) node);
    }
    for (int i = 0; i < node.getChildSize(); i++) {
        final Node childNode = node.getChild(i);
        // recursive call
        doProcessAutoDetect(sql, propertyNameTypeMap, propertyNameOptionMap, autoDetectedPropertyNameSet, childNode);
    }
}
Also used : ForNode(org.dbflute.twowaysql.node.ForNode) IfNode(org.dbflute.twowaysql.node.IfNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) Node(org.dbflute.twowaysql.node.Node) ForNode(org.dbflute.twowaysql.node.ForNode) IfNode(org.dbflute.twowaysql.node.IfNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode)

Example 3 with ForNode

use of org.dbflute.twowaysql.node.ForNode in project dbflute-core by dbflute.

the class SqlAnalyzer method parseFor.

protected void parseFor() {
    final String comment = _tokenizer.getToken();
    final String condition = comment.substring(ForNode.PREFIX.length()).trim();
    if (Srl.is_Null_or_TrimmedEmpty(condition)) {
        throwForCommentExpressionEmptyException();
    }
    final ForNode forNode = createForNode(condition);
    peek().addChild(forNode);
    push(forNode);
    parseEnd();
}
Also used : ForNode(org.dbflute.twowaysql.node.ForNode)

Aggregations

ForNode (org.dbflute.twowaysql.node.ForNode)3 BindVariableNode (org.dbflute.twowaysql.node.BindVariableNode)2 Node (org.dbflute.twowaysql.node.Node)2 DfLanguageGrammar (org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)1 IfNode (org.dbflute.twowaysql.node.IfNode)1 ScopeNode (org.dbflute.twowaysql.node.ScopeNode)1