Package org.python.pydev.parser.jython

Examples of org.python.pydev.parser.jython.SimpleNode


     * the action that jdt uses for this is org.eclipse.jdt.ui.actions.OrganizeImportsAction
     *
     */
    public void performArrangeImports(PySelection ps, MarkerAnnotationAndPosition markerInfo, PyEdit edit)
            throws BadLocationException, CoreException {
        SimpleNode ast = edit.getAST();
        if (ast == null) {
            //we need the ast to look for the imports... (the generated markers will be matched against them)
            return;
        }
        IMarker marker = markerInfo.markerAnnotation.getMarker();
View Full Code Here


            }
            PySelection selection = new PySelection(info.getDocument(), userSelection);
            int startLineIndexIndocCoords = selection.getStartLineIndex();
            int startLineIndexInASTCoords = startLineIndexIndocCoords + 1; //from doc to ast
            Module module = info.getModuleAdapter().getASTNode();
            SimpleNode currentScope = module;

            try {
                FindScopeVisitor scopeVisitor = new FindScopeVisitor(startLineIndexInASTCoords,
                        selection.getCursorColumn() + 1);
                module.accept(scopeVisitor);
                ILocalScope scope = scopeVisitor.scope;
                FastStack scopeStack = scope.getScopeStack();
                currentScope = (SimpleNode) scopeStack.peek(); //at least the module should be there if we don't have anything.
            } catch (Exception e1) {
                Log.log(e1);
            }

            GetNodeForExtractLocalVisitor visitor = new GetNodeForExtractLocalVisitor(startLineIndexInASTCoords);
            try {
                currentScope.accept(visitor);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            SimpleNode lastNodeBeforePassedLine = visitor.getLastInContextBeforePassedLine();
            if (lastNodeBeforePassedLine != null) {
                final int[] line = new int[] { Integer.MAX_VALUE };
                try {
                    Visitor v = new Visitor() {

                        protected Object unhandled_node(SimpleNode node) throws Exception {
                            if (node.beginLine > 0) {
                                line[0] = Math.min(line[0], node.beginLine - 1);
                            } else {
                                Log.log("Found node with beginLine <= 0:" + node + " line: " + node.beginLine);
                            }
                            return this;
                        }
                    };
                    lastNodeBeforePassedLine.accept(v);
                } catch (Exception e) {
                    Log.log(e);
                }
                if (line[0] != Integer.MAX_VALUE) {
                    lineForLocal = line[0];
View Full Code Here

                "        #--- comm method\n" +
                "    #--- comm class\n" +
                "#--- comm module\n" +
                "";

        SimpleNode node = parseLegalDocStr(str);

        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);

        //module level: Foo and 1 comment
View Full Code Here

                "else:\n" +
                "    #--- bar ---\n"
                +
                "    pass";

        SimpleNode node = parseLegalDocStr(str);

        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);

        //module level: 2 comments
View Full Code Here

                "class Test:\n" +
                "    def __init__(self):\n" +
                "        self.foo, self.bar = 1, 2\n" +
                "";

        SimpleNode node = parseLegalDocStr(str);

        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);

        //module level: Test
View Full Code Here

                "    var = 10\n"
                +
                "\n" +
                "";

        SimpleNode node = parseLegalDocStr(str);

        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);

        //module level: Foo and main
View Full Code Here

                "    def m2(self):\n" + //one more member
                "        pass\n" +
                "\n" +
                "";

        SimpleNode node = parseLegalDocStr(str);
        SimpleNode node2 = parseLegalDocStr(str2);

        OutlineCreatorVisitor visitor = OutlineCreatorVisitor.create(node);
        ParsedItem item = new ParsedItem(visitor.getAll().toArray(new ASTEntryWithChildren[0]), null);

        OutlineCreatorVisitor visitor2 = OutlineCreatorVisitor.create(node2);
View Full Code Here

    public IMessage[] analyzeDocument(IPythonNature nature, SourceModule module, IAnalysisPreferences prefs,
            IDocument document, IProgressMonitor monitor, IIndentPrefs indentPrefs) {

        OccurrencesVisitor visitor = new OccurrencesVisitor(nature, module.getName(), module, prefs, document, monitor);
        try {
            SimpleNode ast = module.getAst();
            if (ast != null) {
                if (nature.startRequests()) {
                    try {
                        ast.accept(visitor);
                    } finally {
                        nature.endRequests();
                    }
                }
            }
View Full Code Here

        List<GenAndTok> all = f.getAll();
        int len = all.size();
        for (int i = 0; i < len; i++) {
            GenAndTok g = all.get(i);
            if (g.generator instanceof SourceToken) {
                SimpleNode ast = ((SourceToken) g.generator).getAst();

                // it can be an unused import
                boolean isFromImport = ast instanceof ImportFrom;
                if (isFromImport || ast instanceof Import) {

                    if (isFromImport && AbstractVisitor.isWildImport((ImportFrom) ast)) {
                        addMessage(IAnalysisPreferences.TYPE_UNUSED_WILD_IMPORT, g.generator, g.tok);

                    } else if (!(g.generator instanceof ImportPartSourceToken)) {
                        addMessage(IAnalysisPreferences.TYPE_UNUSED_IMPORT, g.generator, g.tok);
                    }

                    continue; // finish it...
                }
            }

            // or unused variable
            // we have to check if this is a name we should ignore
            if (startsWithNamesToIgnore(g)) {
                int type = IAnalysisPreferences.TYPE_UNUSED_VARIABLE;

                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;
                        }
View Full Code Here

        if (!(part instanceof PyEdit)) {
            return false;
        }

        PyEdit pyEdit = (PyEdit) part;
        SimpleNode ast = pyEdit.getAST();
        if (ast == null) {
            IDocument doc = pyEdit.getDocument();
            SourceModule sourceModule;
            IPythonNature nature = null;
            try {
View Full Code Here

TOP

Related Classes of org.python.pydev.parser.jython.SimpleNode

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.