Package org.python.pydev.parser.jython.ast

Examples of org.python.pydev.parser.jython.ast.FunctionDef


        if (nodeHelper.isClassDef(node)) {

            ClassDef classNode = (ClassDef) node;
            for (stmtType statement : classNode.body) {
                if (nodeHelper.isInit(statement)) {
                    FunctionDef func = (FunctionDef) statement;
                    stmtType lastStmt = func.body[func.body.length - 1];
                    LastLineVisitor visitor = VisitorFactory.createVisitor(LastLineVisitor.class, lastStmt);
                    return visitor.getLastLine();
                }
            }
View Full Code Here


        fail("The token requested (" + req + ") was not found.");
        return null;
    }

    private FunctionDef createFuncDef(String metName) {
        return new FunctionDef(new NameTok(metName, NameTok.FunctionName), null, null, null, null);
    }
View Full Code Here

            } else if (node instanceof Attribute) {
                Attribute attribute = (Attribute) node;
                node = attribute.attr;

            } else if (node instanceof FunctionDef) {
                FunctionDef def = (FunctionDef) node;
                node = def.name;

            } else if (node instanceof Import) {
                ArrayList<SimpleNode> ret = new ArrayList<SimpleNode>();
                Import importToken = (Import) node;
View Full Code Here

            }
        }));
    }

    public void testPyAstFactory() throws Exception {
        FunctionDef functionDef = astFactory.createFunctionDef("MyMethod");

        String expected = "" +
                "def MyMethod():\n" +
                "    pass\n" +
                "";
View Full Code Here

                "    A.__init__(self,arg)\n"
                +
                "    self.attribute = attribute\n" +
                "";

        FunctionDef functionDef = astFactory.createFunctionDef("__init__");
        functionDef.args = astFactory.createArguments(true, "arg", "attribute");
        astFactory.setBody(functionDef, astFactory.createCall("A.__init__", "self", "arg"), astFactory.createAssign(
                astFactory.createAttribute("self.attribute"), new Name("attribute", Name.Load, false)));
        checkExpected(functionDef, expected);
    }
View Full Code Here

        String expected = "" +
                "def test(self,arg,attribute):\n" +
                "    Parent.test(self,arg,attribute)\n" +
                "";

        FunctionDef functionDef = astFactory.createFunctionDef("test");
        functionDef.args = astFactory.createArguments(true, "arg", "attribute");
        astFactory.setBody(functionDef, astFactory.createOverrideBody(functionDef, "Parent", "Current"));
        checkExpected(functionDef, expected);
    }
View Full Code Here

                +
                "    return Parent.test(arg,attribute,*args,**kwargs)\n" +
                "";

        Module module = (Module) parseLegalDocStr(expected);
        FunctionDef functionDef = (FunctionDef) module.body[0];
        FunctionDef createdFunctionDef = astFactory.createFunctionDef("test");
        createdFunctionDef.args = functionDef.args.createCopy();
        astFactory.setBody(createdFunctionDef, astFactory.createOverrideBody(functionDef, "Parent", "Current"));
        checkExpected(createdFunctionDef, expected);
    }
View Full Code Here

                +
                "    Parent.test(arg,attribute,a=a,b=b,*args,**kwargs)\n" +
                "";

        Module module = (Module) parseLegalDocStr(base);
        FunctionDef functionDef = (FunctionDef) module.body[0];
        FunctionDef createdFunctionDef = astFactory.createFunctionDef("test");
        createdFunctionDef.args = functionDef.args.createCopy();
        astFactory.setBody(createdFunctionDef, astFactory.createOverrideBody(functionDef, "Parent", "Current"));
        checkExpected(createdFunctionDef, expected);
    }
View Full Code Here

        //        Module m = (Module) parseLegalDocStr(expected);
        //        FunctionDef func = (FunctionDef) m.body[0];
        //        System.out.println(func.body[0]);

        Module module = (Module) parseLegalDocStr(base);
        FunctionDef functionDef = (FunctionDef) module.body[0];
        FunctionDef createdFunctionDef = functionDef.createCopy();
        astFactory.setBody(createdFunctionDef, astFactory.createOverrideBody(functionDef, "Parent", "Current"));
        checkExpected(createdFunctionDef, expected);
    }
View Full Code Here

                "def test(cls):\n" +
                "    super(Current,cls).test()\n" +
                "";

        Module module = (Module) parseLegalDocStr(base);
        FunctionDef functionDef = (FunctionDef) module.body[0];
        FunctionDef createdFunctionDef = functionDef.createCopy(false);
        astFactory.setBody(createdFunctionDef, astFactory.createOverrideBody(functionDef, "Parent", "Current"));
        checkExpected(createdFunctionDef, expected);
    }
View Full Code Here

TOP

Related Classes of org.python.pydev.parser.jython.ast.FunctionDef

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.