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

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


            }
        }

        //If it got here, there may still be an assign to it...
        if (functionDefinitionReferenced.parent instanceof ClassDef) {
            ClassDef classDef = (ClassDef) functionDefinitionReferenced.parent;
            stmtType[] body = classDef.body;
            if (body != null) {
                int len = body.length;

                String funcName = ((NameTok) functionDefinitionReferenced.name).id;
View Full Code Here


        if (ast instanceof FunctionDef) {
            functionDefinitionReferenced = (FunctionDef) ast;
            analyzeCallAndFunctionMatch(callNode, functionDefinitionReferenced, sourceToken, callingBoundMethod);

        } else if (ast instanceof ClassDef) {
            ClassDef classDef = (ClassDef) ast;
            SimpleNode initNode = defToConsideredInit.get(classDef);
            callingBoundMethod = true;
            if (initNode == null) {
                String className = ((NameTok) classDef.name).id;
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

                    Object[][] metaclassAttrs = new Object[][] {
                            { "objects", NodeUtils.makeAttribute("django.db.models.manager.Manager()") },
                            { "DoesNotExist", new Name("Exception", Name.Load, false) },
                            { "MultipleObjectsReturned", new Name("Exception", Name.Load, false) }, };

                    ClassDef classDef = (ClassDef) node;
                    stmtType[] newBody = new stmtType[classDef.body.length + metaclassAttrs.length];
                    System.arraycopy(classDef.body, 0, newBody, metaclassAttrs.length, classDef.body.length);

                    int i = 0;
                    for (Object[] objAndType : metaclassAttrs) {
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 JJTCLASSDEF:
                suite = (Suite) stack.popNode();
                body = suite.body;
                int nodeArity = stack.nodeArity() - 1;
                ArrayList<keywordType> classDefKeywords = new ArrayList<keywordType>();
                starargs = null;
                kwargs = null;

                int loopTo = nodeArity;
                for (int i = 0; i < loopTo; i++) {
                    SimpleNode node = stack.peekNode();
                    if (node instanceof keywordType) {
                        stack.popNode();
                        keywordType keyword = (keywordType) node;
                        classDefKeywords.add(keyword);
                        if (starargs == null) {
                            keyword.afterstarargs = true; //note that we get things backward in the stack
                        }
                        nodeArity--;
                    } else if (node instanceof ExtraArgValue) {
                        if (node.getId() == JJTEXTRAARGVALUELIST) {
                            ExtraArgValue nstarargs = (ExtraArgValue) stack.popNode();
                            starargs = nstarargs.value;
                            this.addSpecialsAndClearOriginal(nstarargs, starargs);
                            nodeArity--;
                        } else if (node.getId() == JJTEXTRAKEYWORDVALUELIST) {
                            ExtraArgValue nkwargs = (ExtraArgValue) stack.popNode();
                            kwargs = nkwargs.value;
                            this.addSpecialsAndClearOriginal(nkwargs, kwargs);
                            nodeArity--;
                        }
                    } else {
                        break;
                    }
                }
                if (classDefKeywords.size() > 1) {
                    Collections.reverse(classDefKeywords);
                }

                exprType[] bases = makeExprs(nodeArity);
                nameTok = makeName(NameTok.ClassName);
                //decorator is always null at this point... it's decorated later on
                ClassDef classDef = new ClassDef(nameTok, bases, body, null,
                        classDefKeywords.toArray(new keywordType[classDefKeywords.size()]), starargs, kwargs);

                addSpecialsAndClearOriginal(suite, classDef);
                setParentForFuncOrClass(body, classDef);
                return classDef;
View Full Code Here

                                        return toks;
                                    }
                                    value = d.value;

                                } else if (d.ast instanceof Name) {
                                    ClassDef classDef = (ClassDef) d.scope.getClassDef();
                                    if (classDef != null) {
                                        FindDefinitionModelVisitor visitor = new FindDefinitionModelVisitor(
                                                actToks.get(actToksLen - 1), d.line, d.col, d.module);
                                        try {
                                            classDef.accept(visitor);
                                        } catch (StopVisitingException e) {
                                            //expected exception
                                        }
                                        if (visitor.definitions.size() == 0) {
                                            return EMPTY_ITOKEN_ARRAY;
View Full Code Here

        try {
            //COMPLETION: get the completions for the whole hierarchy if this is a class!!
            ICompletionState state;
            if (ast instanceof ClassDef) {
                ClassDef c = (ClassDef) ast;
                for (int j = 0; j < c.bases.length; j++) {
                    if (c.bases[j] instanceof Name) {
                        Name n = (Name) c.bases[j];
                        String base = n.id;
                        //An error in the programming might result in an error.
View Full Code Here

        //ok, not assign nor import, let's check if it is some self (we do not check for only 'self' because that would map to a
        //local (which has already been covered).
        if (actTok.startsWith("self.")) {
            //ok, it is some self, now, that is only valid if we are in some class definition
            ClassDef classDef = (ClassDef) scopeVisitor.scope.getClassDef();
            if (classDef != null) {
                //ok, we are in a class, so, let's get the self completions
                String classRep = NodeUtils.getRepresentationString(classDef);
                IToken[] globalTokens = getGlobalTokens(new CompletionState(line - 1, col - 1, classRep, nature, "",
                        state), //use the old state as the cache
View Full Code Here

    public Tuple<Integer, Integer> getLineColForDefinition(SimpleNode a) {
        int line = a.beginLine;
        int col = a.beginColumn;

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

        } else if (a instanceof FunctionDef) {
            FunctionDef c = (FunctionDef) a;
View Full Code Here

    public static void getSelfOrClsCompletions(ILocalScope scope, CompletionRequest request, List theList,
            ICompletionState state, boolean getOnlySupers) throws BadLocationException, MisconfigurationException {
        for (Iterator<SimpleNode> it = scope.iterator(); it.hasNext();) {
            SimpleNode node = it.next();
            if (node instanceof ClassDef) {
                ClassDef d = (ClassDef) node;

                if (getOnlySupers) {
                    for (int i = 0; i < d.bases.length; i++) {
                        if (d.bases[i] instanceof Name) {
                            Name n = (Name) d.bases[i];
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.