public synchronized Object init()

in velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java [101:170]


    public synchronized Object init(InternalContextAdapter context, Object data)
    throws TemplateInitException
    {
        /* This method is synchronized to prevent double initialization or initialization while rendering */

        if (!isInitialized)
        {
            /*
             *  init the tree correctly
             */

            super.init( context, data );

            /*
             * handle '$' and '#' chars prefix
             */
            Token t = getFirstToken();
            int pos = -1;
            while (t != null && (pos = t.image.lastIndexOf(rsvc.getParserConfiguration().getHashChar())) == -1)
            {
                t = t.next;
            }
            if (t != null && pos > 0)
            {
                morePrefix = t.image.substring(0, pos);
            }


            uberInfo = new Info(getTemplateName(),
                    getLine(), getColumn());

            right = getRightHandSide();
            left = getLeftHandSide();

            strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);

            /*
             *  grab this now.  No need to redo each time
             */
            leftReference = left.firstImage.substring(1);

            /* handle backward compatible space gobbling if asked so */
            if (rsvc.getSpaceGobbling() == SpaceGobbling.BC)
            {
                Node previousNode = null;
                for (int brother = 0; brother < parent.jjtGetNumChildren(); ++brother)
                {
                    Node node = parent.jjtGetChild(brother);
                    if (node == this) break;
                    previousNode = node;
                }
                if (previousNode == null) prefix = "";
                else if (previousNode instanceof ASTText)
                {
                    ASTText text = (ASTText)previousNode;
                    if (text.getCtext().matches("[ \t]*"))
                    {
                        text.setCtext("");
                    }
                }
                else prefix = "";
            }

            isInitialized = true;

            cleanupParserAndTokens();
        }

        return data;
    }