Search in sources :

Example 1 with PyParser

use of org.python.pydev.parser.PyParser in project Pydev by fabioz.

the class PyGoToDefinition method run.

/**
 * Overrides the run and calls -- and the whole default refactoring cycle from the beggining,
 * because unlike most refactoring operations, this one can work with dirty editors.
 * @return
 */
@Override
public void run(IAction action) {
    workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart[] dirtyEditors = workbenchWindow.getActivePage().getDirtyEditors();
    Set<PyEdit> askReparse = new HashSet<PyEdit>();
    for (IEditorPart iEditorPart : dirtyEditors) {
        if (iEditorPart instanceof PyEdit) {
            PyEdit pyEdit = (PyEdit) iEditorPart;
            long astModificationTimeStamp = pyEdit.getAstModificationTimeStamp();
            IDocument doc = pyEdit.getDocument();
            if (astModificationTimeStamp != -1 && astModificationTimeStamp == (((IDocumentExtension4) doc).getModificationStamp())) {
            // All OK, the ast is synched!
            } else {
                askReparse.add(pyEdit);
            }
        }
    }
    if (askReparse.size() == 0) {
        findDefinitionsAndOpen(true);
    } else {
        // We don't have a match: ask for a reparse
        Object lock = new Object();
        for (PyEdit pyEdit : askReparse) {
            IParserObserver observer = new FindParserObserver(pyEdit, askReparse, lock);
            PyParser parser = pyEdit.getParser();
            // it will analyze when the next parse is finished
            parser.addParseListener(observer);
            parser.forceReparse();
        }
    }
}
Also used : PyParser(org.python.pydev.parser.PyParser) IEditorPart(org.eclipse.ui.IEditorPart) IParserObserver(org.python.pydev.shared_core.parsing.IParserObserver) PyEdit(org.python.pydev.editor.PyEdit) IDocument(org.eclipse.jface.text.IDocument) HashSet(java.util.HashSet)

Example 2 with PyParser

use of org.python.pydev.parser.PyParser in project Pydev by fabioz.

the class OrganizeImportsFixesUnused method ensureParsed.

private boolean ensureParsed(PyEdit edit) {
    // Ok, we have a little problem here: we have to ensure not that only a regular ast parse took place, but
    // that the analysis of the related document is updated (so that the markers are in-place).
    // To do that, we ask for a reparse asking to analyze the results in that same thread (without scheduling it).
    // 
    // Maybe better would be having some extension that allowed to call the analysis of the document directly
    // (so we don't have to rely on markers in place?)
    final PyParser parser = edit.getParser();
    final boolean[] notified = new boolean[] { false };
    final Object sentinel = new Object();
    parser.addPostParseListener(new IPostParserListener() {

        @Override
        public void participantsNotified(Object... argsToReparse) {
            synchronized (OrganizeImportsFixesUnused.this) {
                parser.removePostParseListener(this);
                if (argsToReparse.length == 2 && argsToReparse[1] == sentinel) {
                    notified[0] = true;
                    OrganizeImportsFixesUnused.this.notify();
                }
            }
        }
    });
    long initial = System.currentTimeMillis();
    while ((System.currentTimeMillis() - initial) < 5000) {
        if (parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE_IN_THIS_THREAD, true), sentinel)) {
            // ok, we were able to schedule it with our parameters, let's wait for its completion...
            synchronized (this) {
                try {
                    wait(5000);
                } catch (InterruptedException e) {
                }
            }
            break;
        } else {
            synchronized (this) {
                try {
                    wait(200);
                } catch (InterruptedException e) {
                }
            }
        }
    }
    // }
    return true;
}
Also used : IPostParserListener(org.python.pydev.parser.PyParser.IPostParserListener) PyParser(org.python.pydev.parser.PyParser)

Example 3 with PyParser

use of org.python.pydev.parser.PyParser in project Pydev by fabioz.

the class AbstractTddRefactorCompletion method forceReparseInBaseEditorAnd.

protected void forceReparseInBaseEditorAnd(PyEdit... others) {
    if (edit != null) {
        PyParser parser = edit.getParser();
        parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
    }
    for (PyEdit e : others) {
        PyParser parser = e.getParser();
        parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
    }
}
Also used : PyParser(org.python.pydev.parser.PyParser) PyEdit(org.python.pydev.editor.PyEdit)

Aggregations

PyParser (org.python.pydev.parser.PyParser)3 PyEdit (org.python.pydev.editor.PyEdit)2 HashSet (java.util.HashSet)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IPostParserListener (org.python.pydev.parser.PyParser.IPostParserListener)1 IParserObserver (org.python.pydev.shared_core.parsing.IParserObserver)1