Search in sources :

Example 1 with ScopeNode

use of org.dbflute.twowaysql.node.ScopeNode 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)

Aggregations

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