private InsertDirectiveArgs fetchInsertDirectiveArgs()

in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java [769:842]


        private InsertDirectiveArgs fetchInsertDirectiveArgs(
                String subvarName, InsertDirectiveType insertDirectiveType) throws
                TemplateException {
            InsertDirectiveArgs args = new InsertDirectiveArgs();
            args.toOptional = true;
            args.printCommand = true;

            if (insertDirectiveType == INSERT_FILE) {
                skipWS();
                args.path = fetchRequiredString();
            }

            Set<String> paramNamesSeen = new HashSet<>();
            String paramName;
            while (skipWS() && (paramName = fetchOptionalVariableName()) != null) {
                skipRequiredToken("=");
                if (!paramNamesSeen.add(paramName)) {
                    throw new DocgenTagException(
                            "Duplicate docgen." + subvarName +  " parameter " + StringUtil.jQuote(paramName) + ".",
                            env);
                }
                boolean insertFileOrOutput = insertDirectiveType == INSERT_FILE || insertDirectiveType ==
                        INSERT_WITH_OUTPUT;
                if (insertFileOrOutput && paramName.equals("charset")) {
                    args.charset = fetchRequiredString();
                } else if (insertFileOrOutput && paramName.equals("from")) {
                    args.from = parseRegularExpressionParam(paramName, fetchRequiredString());
                } else if (insertFileOrOutput && paramName.equals("to")) {
                    args.to = parseRegularExpressionParam(paramName, fetchRequiredString());
                } else if (insertFileOrOutput && paramName.equals("fromOptional")) {
                    args.fromOptional = fetchRequiredBoolean();
                } else if (insertFileOrOutput && paramName.equals("toOptional")) {
                    args.toOptional = fetchRequiredBoolean();
                } else if (insertDirectiveType == INSERT_WITH_OUTPUT && paramName.equals("printCommand")) {
                    args.printCommand = fetchRequiredBoolean();
                } else if ((insertDirectiveType == INSERT_WITH_OUTPUT || insertDirectiveType == CHECK_COMMAND)
                        && paramName.equals("systemProperties")) {
                    args.systemProperties = fetchRequiredStringToStringMap();
                } else {
                    throw new DocgenTagException(
                            "Unsupported docgen." + subvarName +  " parameter " + StringUtil.jQuote(paramName) + ".",
                            env);
                }
            }

            skipRequiredToken(DOCGEN_TAG_END);
            skipLineBreak();
            int indexAfterStartTag = cursor;

            if (insertDirectiveType == INSERT_WITH_OUTPUT || insertDirectiveType == CHECK_COMMAND) {
                int endTagIndex = findNextDocgenEndTag(cursor);
                if (endTagIndex == -1) {
                    throw new DocgenTagException(
                            "Missing docgen end-tag after " + DOCGEN_TAG_START + "." + subvarName + " ...]", env);
                }
                lastDocgenTagStart = endTagIndex;

                args.body = StringUtil.chomp(text.substring(indexAfterStartTag, endTagIndex));

                cursor = endTagIndex + DOCGEN_END_TAG_START.length();
                skipRequiredToken(".");
                String endSubvarName = fetchRequiredVariableName();
                if (!endSubvarName.equals(subvarName)) {
                    throw new DocgenTagException(
                            "End-tag " + DOCGEN_END_TAG_START + "." + endSubvarName + "] doesn't match "
                                    + DOCGEN_TAG_START + "." + subvarName + " ...] tag.", env);
                }
                skipRequiredToken("]");
            }

            args.indexAfterDirective = cursor;

            return args;
        }