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

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


            SimpleNode ast = s.getAst();

            if (ast instanceof ImportFrom) {
                ImportFrom i = (ImportFrom) ast;
                //ok, now, this depends on the name
                NameTok it = getNameForRepresentation(i, shortMessage, true);
                if (it != null) {
                    endCol = it.beginColumn + shortMessage.length();
                    return endCol;
                }

                //if still not returned, it is a wild import... find the '*'
                try {
                    IRegion lineInformation = doc.getLineInformation(i.module.beginLine - 1);
                    //ok, we have the line... now, let's find the absolute offset
                    int absolute = lineInformation.getOffset() + i.module.beginColumn - 1;
                    while (doc.getChar(absolute) != '*') {
                        absolute++;
                    }
                    int absoluteCol = absolute + 1; //1 for the *
                    IRegion region = doc.getLineInformationOfOffset(absoluteCol);
                    endCol = absoluteCol - region.getOffset() + 1; //1 because we should return as if starting in 1 and not 0
                    return endCol;
                } catch (BadLocationException e) {
                    throw new RuntimeException(e);
                }

            } else if (ast instanceof Import) {
                NameTok it = getNameForRepresentation((Import) ast, shortMessage, true);
                endCol = it.beginColumn + shortMessage.length();
                return endCol;
            } else {
                throw new RuntimeException("It is not an import");
            }
View Full Code Here


                if (g.tok instanceof SourceToken) {
                    SourceToken t = (SourceToken) g.tok;
                    SimpleNode ast = t.getAst();
                    if (ast instanceof NameTok) {
                        NameTok n = (NameTok) ast;
                        if (n.ctx == NameTok.KwArg || n.ctx == NameTok.VarArg || n.ctx == NameTok.KeywordName) {
                            type = IAnalysisPreferences.TYPE_UNUSED_PARAMETER;
                        }
                    } else if (ast instanceof Name) {
                        Name n = (Name) ast;
View Full Code Here

    private FunctionDef initExtractedMethod(List<stmtType> body, List<exprType> argsList) {
        argumentsType args = new argumentsType(argsList.toArray(new exprType[0]), null, null, null, null, null, null,
                null, null, null);

        FunctionDef extractedMethod = new FunctionDef(new NameTok(methodName, NameTok.FunctionName), args,
                body.toArray(new stmtType[0]), null, null);
        return extractedMethod;
    }
View Full Code Here

        return argsList;
    }

    private exprType createCallAttribute() {
        if (this.offsetAdapter instanceof IClassDefAdapter) {
            return new Attribute(new Name("self", Name.Load, false), new NameTok(this.methodName, NameTok.Attrib),
                    Attribute.Load);
        } else {
            return new Name(this.methodName, Name.Load, false);
        }
    }
View Full Code Here

            String id;
            if (astNode instanceof Name) {
                Name variable = (Name) astNode;
                id = variable.id;
            } else if (astNode instanceof NameTok) {
                NameTok variable = (NameTok) astNode;
                id = variable.id;
            } else {
                continue;
            }
            if (globalVariableNames.contains(id) && !isStored(id, before)) {
View Full Code Here

            String id;
            if (astNode instanceof Name) {
                Name variable = (Name) astNode;
                id = variable.id;
            } else if (astNode instanceof NameTok) {
                NameTok variable = (NameTok) astNode;
                id = variable.id;
            } else {
                continue;
            }
            if (isStored(id, selected)) {
View Full Code Here

                Name scopeVar = (Name) astNode;
                if (scopeVar.id.equals(var)) {
                    isStored = (scopeVar.ctx != Name.Load && scopeVar.ctx != Name.AugLoad);
                }
            } else if (astNode instanceof NameTok) {
                NameTok scopeVar = (NameTok) astNode;
                if (scopeVar.id.equals(var)) {
                    isStored = true; //NameTok are always store contexts.
                }

            } else if (astNode instanceof Import) {
View Full Code Here

            case JJTIMPORT:
                ((Import) n).names = makeAliases(arity);
                return n;

            case JJTDOT_OP:
                NameTok attr = makeName(NameTok.Attrib);
                value = (exprType) stack.popNode();
                Attribute attribute = (Attribute) n;
                attribute.value = value;
                attribute.attr = attr;
                return n;

            case JJTBEGIN_DEL_STMT:
                return new Delete(null);

            case JJTDEL_STMT:
                exprs = makeExprs(arity - 1);
                ctx.setDelete(exprs);
                Delete d = (Delete) stack.popNode();
                d.targets = exprs;
                return d;

            case JJTDOTTED_NAME:
                Name name = (Name) n;
                FastStringBuffer sb = tempBuffer.clear();
                for (int i = 0; i < arity; i++) {
                    if (i > 0) {
                        sb.insert(0, '.');
                    }
                    Name name0 = (Name) stack.popNode();
                    sb.insert(0, name0.id);
                    addSpecials(name0, name);
                    //we have to set that, because if we later add things to the previous Name, we will now want it to be added to
                    //the new name (comments will only appear later and may be added to the previous name -- so, we replace the previous
                    //name specials list).
                    name0.specialsBefore = name.getSpecialsBefore();
                    name0.specialsAfter = name.getSpecialsAfter();
                }
                name.id = sb.toString();
                return name;

            case JJTDOTTED_AS_NAME:
                NameTok asname = null;
                if (arity > 1) {
                    asname = makeName(NameTok.ImportName);
                }
                return new aliasType(makeName(NameTok.ImportName), asname);
View Full Code Here

        ArrayList<aliasType> aliastL = new ArrayList<aliasType>();
        while (arity > 0 && stack.peekNode() instanceof aliasType) {
            aliastL.add(0, (aliasType) stack.popNode());
            arity--;
        }
        NameTok nT;
        if (arity > 0) {
            nT = makeName(NameTok.ImportModule);
        } else {
            nT = new NameTok("", NameTok.ImportModule);
            Object temporaryTok = this.stack.getGrammar().temporaryToken;
            ISpecialStr temporaryToken;
            if (temporaryTok instanceof ISpecialStr) {
                temporaryToken = (ISpecialStr) temporaryTok;
            } else {
View Full Code Here

            if (init != null) {
                if (!init.getArguments().hasOnlySelf()) {
                    argsNames.addAll(init.getArguments().getSelfFilteredArgNames());
                }
                if (varArg == null && init.getArguments().hasVarArg()) {
                    varArg = new NameTok(ARGS, NameTok.VarArg);
                }

                if (kwArg == null && init.getArguments().hasKwArg()) {
                    kwArg = new NameTok(KWARGS, NameTok.KwArg);
                }
            }
        }

        //addOwnArguments
        for (INodeAdapter adapter1 : attributes) {
            argsNames.add(nodeHelper.getPublicAttr(adapter1.getName()));
        }
        List<exprType> argsExprList = new ArrayList<exprType>();
        Name selfArg = new Name(NodeHelper.KEYWORD_SELF, Name.Param, false);
        argsExprList.add(selfArg);
        for (String parameter : argsNames) {
            argsExprList.add(new Name(parameter.trim(), Name.Param, false));
        }

        exprType[] argsExpr = argsExprList.toArray(new exprType[0]);
        argumentsType args = new argumentsType(argsExpr, varArg, kwArg, null, null, null, null, null, null, null);

        //constructorCalls
        List<stmtType> body = new ArrayList<stmtType>();
        for (IClassDefAdapter base : bases) {
            Expr init = extractConstructorInit(base);
            if (init != null) {
                body.add(init);
            }
        }

        //initAttributes
        for (INodeAdapter adapter : attributes) {
            exprType target = new Attribute(new Name(NodeHelper.KEYWORD_SELF, Name.Load, false), new NameTok(
                    adapter.getName(), NameTok.Attrib), Attribute.Store);
            Assign initParam1 = new Assign(new exprType[] { target }, new Name(nodeHelper.getPublicAttr(adapter
                    .getName()), Name.Load, false));
            Assign initParam = initParam1;
            body.add(initParam);
        }

        //create function def
        return new FunctionDef(new NameTok(NodeHelper.KEYWORD_INIT, NameTok.FunctionName), args,
                body.toArray(new stmtType[0]), null, null);
    }
View Full Code Here

TOP

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

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.