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

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


    protected SimpleNode getEditNode() {
        NameTok functionName = new NameTok(accessorName, NameTok.FunctionName);
        argumentsType args = createArguments();
        stmtType[] body = createBody();

        return new FunctionDef(functionName, args, body, null, null);
    }
View Full Code Here


    protected SimpleNode getEditNode() {
        NameTok functionName = new NameTok(accessorName, NameTok.FunctionName);
        argumentsType args = createArguments();
        stmtType[] body = createBody();

        return new FunctionDef(functionName, args, body, null, null);
    }
View Full Code Here

                    addSpecialsAndClearOriginal(funcDefReturnAnn, actualReturnAnnotation);
                }
                argumentsType arguments = makeArguments(arity - 1);
                NameTok nameTok = makeName(NameTok.FunctionName);
                //decorator is always null at this point... it's decorated later on
                FunctionDef funcDef = new FunctionDef(nameTok, arguments, body, null, actualReturnAnnotation);
                addSpecialsAndClearOriginal(suite, funcDef);
                setParentForFuncOrClass(body, funcDef);
                return funcDef;
            case JJTTFPDEF:
                Name tfpdefName = null;
                exprType typeDef = null;
                if (arity == 1) {
                    tfpdefName = (Name) stack.popNode();
                } else if (arity == 2) {
                    typeDef = (exprType) stack.popNode();
                    tfpdefName = (Name) stack.popNode();
                } else {
                    throw new RuntimeException("Unexpected arity: " + arity);
                }

                return new JfpDef(tfpdefName, typeDef);
            case JJTONLYKEYWORDARG2:
            case JJTDEFAULTARG2:
                DefaultArg defaultArg;
                JfpDef jfpDef;
                if (arity == 1) {
                    jfpDef = (JfpDef) stack.popNode();
                    defaultArg = new DefaultArg(jfpDef.nameNode, null, jfpDef.typeDef, n.getId());
                } else if (arity == 2) {
                    exprType defaultValue = (exprType) stack.popNode();
                    jfpDef = (JfpDef) stack.popNode();
                    defaultArg = new DefaultArg(jfpDef.nameNode, defaultValue, jfpDef.typeDef, n.getId());
                } else {
                    throw new RuntimeException("Unexpected arity: " + arity);
                }
                return defaultArg;
            case JJTONLYKEYWORDARG:
            case JJTDEFAULTARG:
                //no type definition in this case
                if (arity == 1) {
                    return new DefaultArg(((exprType) stack.popNode()), null, null, n.getId());
                }
                exprType parameter = (exprType) stack.popNode();
                return new DefaultArg((exprType) stack.popNode(), parameter, null, n.getId());
            case JJTEXTRAARGLIST:
                if (arity == 0) {
                    //nothing here (just '*')
                    return new ExtraArg(null, JJTEXTRAARGLIST, null);
                }
                return new ExtraArg(makeName(NameTok.VarArg), JJTEXTRAARGLIST);
            case JJTEXTRAKEYWORDLIST:
                return new ExtraArg(makeName(NameTok.KwArg), JJTEXTRAKEYWORDLIST);
            case JJTEXTRAARGLIST2: //with type declaration
                if (arity == 0) {
                    //nothing here (just '*')
                    return new ExtraArg(null, JJTEXTRAARGLIST, null);
                }
                jfpDef = (JfpDef) stack.popNode();
                NameTok jfpDefName = makeName(NameTok.VarArg, jfpDef.nameNode);
                ExtraArg extra = new ExtraArg(jfpDefName, JJTEXTRAARGLIST, jfpDef.typeDef);
                return extra;
            case JJTEXTRAKEYWORDLIST2: //with type declaration
                jfpDef = (JfpDef) stack.popNode();
                return new ExtraArg(makeName(NameTok.KwArg, jfpDef.nameNode), JJTEXTRAKEYWORDLIST, jfpDef.typeDef);
            case JJTDECORATED:
                if (stack.nodeArity() != 2) {
                    throw new RuntimeException("Expected 2 nodes at this context, found: " + arity);
                }
                SimpleNode def = stack.popNode();
                Decorators decorators = (Decorators) stack.popNode();
                if (def instanceof ClassDef) {
                    ClassDef classDef = (ClassDef) def;
                    classDef.decs = decorators.exp;
                } else {
                    FunctionDef fDef = (FunctionDef) def;
                    fDef.decs = decorators.exp;
                }
                return def;
            case JJTCLASSDEF:
                suite = (Suite) stack.popNode();
View Full Code Here

            ClassDef c = (ClassDef) a;
            line = c.name.beginLine;
            col = c.name.beginColumn;

        } else if (a instanceof FunctionDef) {
            FunctionDef c = (FunctionDef) a;
            line = c.name.beginLine;
            col = c.name.beginColumn;
        }

        return new Tuple<Integer, Integer>(line, col);
View Full Code Here

                                    Log.log(e);
                                }
                            }

                            for (ImmutableTuple<IToken, String> tokenAndBaseClass : map.values()) {
                                FunctionDef functionDef = null;

                                //No checkings needed for type (we already did that above).
                                if (tokenAndBaseClass.o1 instanceof SourceToken) {
                                    SourceToken sourceToken = (SourceToken) tokenAndBaseClass.o1;
                                    SimpleNode ast = sourceToken.getAst();
View Full Code Here

                    FastStack<SimpleNode> scopeStack = visitor.scope.getScopeStack();
                    for (Iterator<SimpleNode> it = scopeStack.topDownIterator(); scopeCorrect == false && it.hasNext();) {
                        SimpleNode node = it.next();
                        if (node instanceof FunctionDef) {
                            FunctionDef funcDef = (FunctionDef) node;
                            if (funcDef.args != null && funcDef.args.args != null && funcDef.args.args.length > 0) {
                                //ok, we have some arg, let's check for self or cls
                                String rep = NodeUtils.getRepresentationString(funcDef.args.args[0]);
                                if (rep != null && (rep.equals("self") || rep.equals("cls"))) {
                                    scopeCorrect = true;
View Full Code Here

        return new AssignCompletionInfo(defs, ret);
    }

    private void addFunctionDefCompletionsFromReturn(ICodeCompletionASTManager manager, ICompletionState state,
            ArrayList<IToken> ret, SourceModule s, Definition definition) throws CompletionRecursionException {
        FunctionDef functionDef = (FunctionDef) definition.ast;
        for (Return return1 : ReturnVisitor.findReturns(functionDef)) {
            ICompletionState copy = state.getCopy();
            String act = NodeUtils.getFullRepresentationString(return1.value);
            if (act == null) {
                return; //may happen if the return we're seeing is a return without anything
View Full Code Here

        this.offsetStrategy = req.offsetStrategy;
    }

    @Override
    protected SimpleNode getEditNode() {
        FunctionDef origin = method.getASTNode();
        stmtType[] body = initBody(origin);

        return new FunctionDef(origin.name, origin.args, body, null, null);
    }
View Full Code Here

        if (node instanceof ClassDef) {
            node = getClassDefInit((ClassDef) node);
        }

        if (node instanceof FunctionDef) {
            FunctionDef f = (FunctionDef) node;

            String startPar = "( ";
            FastStringBuffer buffer = new FastStringBuffer(startPar, 40);

            for (int i = 0; i < f.args.args.length; i++) {
View Full Code Here

        if (ast != null) {
            if (ast instanceof ClassDef) {
                ast = NodeUtils.getClassDefInit((ClassDef) ast);
            }
            if (ast instanceof FunctionDef) {
                FunctionDef functionDef = (FunctionDef) ast;
                if (functionDef.args != null) {
                    String printed = PrettyPrinterV2.printArguments(new IGrammarVersionProvider() {

                        public int getGrammarVersion() throws MisconfigurationException {
                            return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_0;
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.