Example usage for jdk.nashorn.internal.ir LexicalContext getFunctions

List of usage examples for jdk.nashorn.internal.ir LexicalContext getFunctions

Introduction

In this page you can find the example usage for jdk.nashorn.internal.ir LexicalContext getFunctions.

Prototype

public Iterator<FunctionNode> getFunctions() 

Source Link

Document

Returns an iterator over all functions in the context, with the top (innermost open) function first.

Usage

From source file:IDE.SyntaxTree.ParserTest.java

/**
 * Test of parse method, of class Parser.
 *//*from   w w  w  .ja v a2s . c o  m*/
@Test
public void testParse() {
    try {

        String input = readServerFile(new File("c:\\Projects\\JWeb\\www\\Controller\\indexController.jap"));
        ExpNode expResult = null;
        JWebParser result = new JWebParser(input);
        FunctionNode fNode = result.parse();

        //Logger.logMsg(Level.ALL.intValue(),);
        // System.out.println( fNode.getName());
        // System.out.println( fNode.getBody());
        LexicalContext lc = new LexicalContext();

        fNode.accept(new NodeVisitor(lc) {

            @Override
            public boolean enterFunctionNode(FunctionNode functionNode) {

                if (!functionNode.isProgram()) {

                    if (functionNode.isAnonymous()) {

                        String name = ((IdentNode) functionNode.getIdent().accept(this)).getName();
                        if (name.contains(":")) {

                            System.out.println("<anonymous> FUNCTION_ICON");
                        } else {
                            System.out.println(name + " METHOD_ICON");
                        }

                    } else {

                        System.out.println(((IdentNode) functionNode.getIdent().accept(this)).getName());
                    }
                }

                return super.enterFunctionNode(functionNode); //To change body of generated methods, choose Tools | Templates.
            }

        });
        Iterator<FunctionNode> sss = lc.getFunctions();
        IdentNode ident = fNode.getIdent();

        // assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        //fail("The test case is a prototype.");
    } catch (IOException ex) {
        Logger.getLogger(ParserTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}