Package net.sourceforge.htmlunit.corejs.javascript.ast

Examples of net.sourceforge.htmlunit.corejs.javascript.ast.AstNode


                final HtmlElement htmlElement) {

        try {
            final CompilerEnvirons environs = new CompilerEnvirons();
            environs.initFromContext(contextFactory_.enterContext());
            final AstNode root = new Parser(environs).parse(sourceCode, sourceName, lineNo_);
            final Map<Integer, Integer> strings = new TreeMap<Integer, Integer>();
            root.visit(new NodeVisitor() {

                public boolean visit(final AstNode node) {
                    if (node instanceof StringLiteral) {
                        strings.put(node.getAbsolutePosition() + 1, node.getLength() - 2);
                    }
View Full Code Here


        return Double.toString(literal.getNumber());
    }

    private boolean isExecutableBlock(final AstNode node) {
        final AstNode parent = node.getParent();
        if (parent == null) {
            return false;
        }

        final int type = node.getType();
        final int parentType = parent.getType();

        return type == SWITCH
                || type == FOR
                || type == DO
                || type == WHILE
View Full Code Here

                || (type == FUNCTION && (parentType == SCRIPT || parentType == BLOCK))
                || (type == VAR && node.getClass() == VariableDeclaration.class && parentType != FOR);
    }

    private void addInstrumentationSnippetFor(final AstNode node) {
        final AstNode parent = node.getParent();

        final int type = node.getType();
        final int parentType = parent.getType();

        if (type == WHILE || type == FOR || type == DO) {
            fixLoops((Loop) node);
        }

        if (type == IF) {
            fixIf((IfStatement) node);
        }

        if (type == CASE) {
            handleSwitchCase((SwitchCase) node);
        } else if (type == IF && parentType == IF) {
            final IfStatement elseIfStatement = (IfStatement) node;
            final IfStatement ifStatement = (IfStatement) parent;

            if (ifStatement.getElsePart() == elseIfStatement) {
                flattenElseIf(elseIfStatement, ifStatement);
                data.addExecutableLine(getActualLineNumber(node));
            }
        } else if (parentType != CASE) {
            // issue #54
            if (parent.getClass() == LabeledStatement.class) {
                return;
            }

            if (parent.hasChildren()) {
                parent.addChildBefore(newInstrumentationNode(getActualLineNumber(node)), node);
            } else {
                // if, else, while, do, for without {} around their respective 'blocks' for some reason
                // don't have children. Meh. Creating blocks to ease instrumentation.
                final Block block = newInstrumentedBlock(node);

                if (parentType == IF) {
                    final IfStatement ifStatement = (IfStatement) parent;

                    if (ifStatement.getThenPart() == node) {
                        ifStatement.setThenPart(block);
                    } else if (ifStatement.getElsePart() == node) {
                        ifStatement.setElsePart(block);
                    }
                } else if (parentType == WHILE || parentType == FOR || parentType == DO) {
                    ((Loop) parent).setBody(block);
                } else {
                    logger.warn("Cannot handle node with parent that has no children, parent class: {}, parent source:\n{}",
                            parent.getClass(), parent.toSource());
                }
            }

            data.addExecutableLine(getActualLineNumber(node));
        }
View Full Code Here

TOP

Related Classes of net.sourceforge.htmlunit.corejs.javascript.ast.AstNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.