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

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


            keywordType type = (keywordType) node;
            return discoverRep(type.arg);
        }

        if (node instanceof ClassDef) {
            ClassDef def = (ClassDef) node;
            return ((NameTok) def.name).id;
        }

        if (node instanceof FunctionDef) {
            FunctionDef def = (FunctionDef) node;
View Full Code Here


        stmtType body[] = null;
        if (node instanceof FunctionDef) {
            FunctionDef def = (FunctionDef) node;
            body = def.body;
        } else if (node instanceof ClassDef) {
            ClassDef def = (ClassDef) node;
            body = def.body;

        }
        if (body != null && body.length > 0) {
            if (body[0] instanceof Expr) {
View Full Code Here

        return false;
    }

    public static SimpleNode getNameTokFromNode(SimpleNode ast2) {
        if (ast2 instanceof ClassDef) {
            ClassDef c = (ClassDef) ast2;
            return c.name;
        }
        if (ast2 instanceof FunctionDef) {
            FunctionDef c = (FunctionDef) ast2;
            return c.name;
View Full Code Here

        return getClassOrFuncColDefinition(ast2);
    }

    public static int getClassOrFuncColDefinition(SimpleNode ast2) {
        if (ast2 instanceof ClassDef) {
            ClassDef def = (ClassDef) ast2;
            return def.name.beginColumn;
        }
        if (ast2 instanceof FunctionDef) {
            FunctionDef def = (FunctionDef) ast2;
            return def.name.beginColumn;
View Full Code Here

            Module module = (Module) node;
            return module.body;
        }

        if (node instanceof ClassDef) {
            ClassDef module = (ClassDef) node;
            return module.body;
        }

        if (node instanceof FunctionDef) {
            FunctionDef module = (FunctionDef) node;
View Full Code Here

        FoldingEntry foldingEntry = null;
        if (entry.node instanceof Import || entry.node instanceof ImportFrom) {
            foldingEntry = new FoldingEntry(FoldingEntry.TYPE_IMPORT, entry.node.beginLine - 1, entry.endLine, entry);

        } else if (entry.node instanceof ClassDef) {
            ClassDef def = (ClassDef) entry.node;
            foldingEntry = new FoldingEntry(FoldingEntry.TYPE_DEF, def.name.beginLine - 1, entry.endLine, entry);

        } else if (entry.node instanceof FunctionDef) {
            FunctionDef def = (FunctionDef) entry.node;
            foldingEntry = new FoldingEntry(FoldingEntry.TYPE_DEF, def.name.beginLine - 1, entry.endLine, entry);
View Full Code Here

    private void startClass(String name, int startClassRow, int startClassCol) {
        if (startClassCol == 1) {
            endScopesInStack();
        }
        NameTok nameTok = new NameTok(name, NameTok.ClassName);
        ClassDef classDef = new ClassDef(nameTok, null, null, null, null, null, null);

        classDef.beginLine = startClassRow;
        classDef.beginColumn = startClassCol;

        stack.push(classDef);
View Full Code Here

    private void endScope() {
        SimpleNode pop = stack.pop();
        if (!(pop instanceof ClassDef)) {
            return;
        }
        ClassDef def = (ClassDef) pop;
        List<stmtType> body = stackBody.pop();
        def.body = body.toArray(new stmtType[body.size()]);
        addToPertinentScope(def);
    }
View Full Code Here

                    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 JJTCALL_OP:
                exprType starargs = null;
                exprType kwargs = null;

                java.util.List<exprType> args = new ArrayList<exprType>();
                java.util.List<keywordType> keywords = new ArrayList<keywordType>();

                for (int i = arity - 2; i >= 0; i--) {
                    SimpleNode node = stack.popNode();
                    if (node instanceof keywordType) {
                        keywords.add(0, (keywordType) node);

                    } else if (node.getId() == JJTEXTRAARGVALUELIST) {
                        ExtraArgValue nstarargs = (ExtraArgValue) node;
                        starargs = nstarargs.value;
                        this.addSpecialsAndClearOriginal(nstarargs, starargs);

                    } else if (node.getId() == JJTEXTRAKEYWORDVALUELIST) {
                        ExtraArgValue nkwargs = (ExtraArgValue) node;
                        kwargs = nkwargs.value;
                        this.addSpecialsAndClearOriginal(nkwargs, kwargs);

                    } else if (node instanceof ComprehensionCollection) {
                        //what can happen is something like print sum(x for x in y), where we have already passed x in the args, and then get 'for x in y'
                        args.add(
                                0,
                                new ListComp((exprType) stack.popNode(), ((ComprehensionCollection) node)
                                        .getGenerators(), ListComp.EmptyCtx));
                        i--; //popped node

                    } else {
                        args.add(0, (exprType) node);
                    }
                }

                exprType func = (exprType) stack.popNode();
                Call c = new Call(func, args.toArray(new exprType[args.size()]),
                        keywords.toArray(new keywordType[keywords.size()]), starargs, kwargs);
                addSpecialsAndClearOriginal(n, c);
                return c;
            case JJTFUNCDEF:
                suite = (Suite) stack.popNode();
                body = suite.body;

                argumentsType arguments = makeArguments(stack.nodeArity() - 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, null);
                addSpecialsAndClearOriginal(suite, funcDef);
                setParentForFuncOrClass(body, funcDef);
                return funcDef;
            case JJTDEFAULTARG:
                value = (arity == 1) ? null : ((exprType) stack.popNode());
                return new DefaultArg(((exprType) stack.popNode()), value, n.getId());
            case JJTEXTRAARGLIST:
                return new ExtraArg(makeName(NameTok.VarArg), JJTEXTRAARGLIST);
            case JJTEXTRAKEYWORDLIST:
                return new ExtraArg(makeName(NameTok.KwArg), JJTEXTRAKEYWORDLIST);
            case JJTCLASSDEF:
                suite = (Suite) stack.popNode();
                body = suite.body;
                exprType[] bases = makeExprs(stack.nodeArity() - 1);
                nameTok = makeName(NameTok.ClassName);
                ClassDef classDef = new ClassDef(nameTok, bases, body, null, null, null, null);
                addSpecialsAndClearOriginal(suite, classDef);
                setParentForFuncOrClass(body, classDef);
                return classDef;
            case JJTBEGIN_RETURN_STMT:
                return new Return(null);
View Full Code Here

            case JJTCLASSDEF:
                suite = (Suite) stack.popNode();
                body = suite.body;
                exprType[] bases = makeExprs(stack.nodeArity() - 1);
                nameTok = makeName(NameTok.ClassName);
                ClassDef classDef = new ClassDef(nameTok, bases, body, null, null, null, null);
                addSpecialsAndClearOriginal(suite, classDef);
                setParentForFuncOrClass(body, classDef);
                return classDef;
            case JJTBEGIN_RETURN_STMT:
                return new Return(null);
View Full Code Here

TOP

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

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.