Package org.python.pydev.core.parser

Examples of org.python.pydev.core.parser.IPyParser


     * @param edit this is the editor to which a parser should be attached.
     */
    public synchronized void attachParserTo(IPyEdit edit) {
        synchronized (lock) {
            //remove previous...
            IPyParser existingParser = getParser(edit);
            if (existingParser != null) {
                //it was already bounded to a parser, so, we have to remove that one before
                //attaching a new one
                notifyEditorDisposed(edit);
            }

            for (Map.Entry<IPyParser, List<IPyEdit>> entry : parsers.entrySet()) {
                for (IPyEdit curr : entry.getValue()) {
                    if (curr.hasSameInput(edit)) {
                        //do nothing, as it is already binded to a similar document (just force a reparse
                        //and add it to the list of edits for that parser)
                        IPyParser p = getParser(curr);

                        makeParserAssociations(edit, p);

                        p.forceReparse();
                        return;
                    }
                }
            }
            if (DEBUG) {
                System.out.println("Creating new parser.");
            }

            IPyParser pyParser = new PyParser(edit);

            boolean useAnalysisOnlyOnDocSave = useAnalysisOnlyOnDocSave();
            pyParser.resetTimeoutPreferences(useAnalysisOnlyOnDocSave);

            makeParserAssociations(edit, pyParser);
            IDocument doc = edit.getDocument();
            pyParser.setDocument(doc, edit.getEditorInput());

            if (DEBUG) {
                System.out.println("Available parsers:" + this.parsers.size());
            }
        }
View Full Code Here


    }

    public synchronized void notifyEditorDisposed(IPyEdit edit) {
        synchronized (lock) {
            //remove the listener from the parser
            IPyParser parser = getParser(edit);

            //External editors may not have a parser...
            if (parser != null) {

                parser.removeParseListener(edit);

                //from the internal list from the parsers to the editors
                List<IPyEdit> lst = parsers.get(parser);
                //we always have the list here (because we must have created it before disposing it)
                lst.remove(edit);

                //and from the edit itself
                edit.getCache().remove(KEY_IN_PYEDIT_CACHE);

                //now, if there's no one in that parsers list anymore, lets dispose the parser
                //and remove it from our references
                boolean dispose = lst.size() == 0;

                if (dispose) {
                    if (DEBUG) {
                        System.out.println("Disposing parser.");
                    }
                    parser.dispose();
                    this.parsers.remove(parser);
                    if (DEBUG) {
                        System.out.println("Available parsers:" + this.parsers.size());
                    }
                } else {
                    //otherwise, just set its new input
                    IPyEdit pyEdit = lst.get(0);
                    IDocument doc = pyEdit.getDocument();
                    parser.setDocument(doc, pyEdit.getEditorInput());
                }
            }

        }
    }
View Full Code Here

TOP

Related Classes of org.python.pydev.core.parser.IPyParser

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.