Search in sources :

Example 1 with IParserObserver

use of org.python.pydev.shared_core.parsing.IParserObserver 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 IParserObserver

use of org.python.pydev.shared_core.parsing.IParserObserver in project Pydev by fabioz.

the class PyParser method fireParserError.

/**
 * stock listener implementation event is fired when parse fails
 * @param original
 */
@Override
@SuppressWarnings("unchecked")
protected void fireParserError(ErrorParserInfoForObservers info) {
    super.fireParserError(info);
    List<IParserObserver> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_PARSER_OBSERVER);
    for (IParserObserver observer : participants) {
        if (observer instanceof IParserObserver3) {
            ((IParserObserver3) observer).parserError(info);
        } else if (observer instanceof IParserObserver2) {
            ((IParserObserver2) observer).parserError(info.error, info.file, info.doc, info.argsToReparse);
        } else {
            observer.parserError(info.error, info.file, info.doc);
        }
    }
}
Also used : IParserObserver3(org.python.pydev.shared_core.parsing.IParserObserver3) IParserObserver2(org.python.pydev.shared_core.parsing.IParserObserver2) IParserObserver(org.python.pydev.shared_core.parsing.IParserObserver)

Example 3 with IParserObserver

use of org.python.pydev.shared_core.parsing.IParserObserver in project Pydev by fabioz.

the class PyParser method fireParserChanged.

/**
 * stock listener implementation event is fired whenever we get a new root
 * @param original
 */
@Override
@SuppressWarnings("unchecked")
protected void fireParserChanged(ChangedParserInfoForObservers info) {
    super.fireParserChanged(info);
    List<IParserObserver> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_PARSER_OBSERVER);
    for (IParserObserver observer : participants) {
        try {
            if (observer instanceof IParserObserver3) {
                ((IParserObserver3) observer).parserChanged(info);
            } else if (observer instanceof IParserObserver2) {
                ((IParserObserver2) observer).parserChanged(info.root, info.file, info.doc, info.argsToReparse);
            } else {
                observer.parserChanged(info.root, info.file, info.doc, info.docModificationStamp);
            }
        } catch (Exception e) {
            Log.log(e);
        }
    }
}
Also used : IParserObserver3(org.python.pydev.shared_core.parsing.IParserObserver3) IParserObserver2(org.python.pydev.shared_core.parsing.IParserObserver2) IParserObserver(org.python.pydev.shared_core.parsing.IParserObserver) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) ParseException(org.python.pydev.parser.jython.ParseException) BadLocationException(org.eclipse.jface.text.BadLocationException) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Aggregations

IParserObserver (org.python.pydev.shared_core.parsing.IParserObserver)3 IParserObserver2 (org.python.pydev.shared_core.parsing.IParserObserver2)2 IParserObserver3 (org.python.pydev.shared_core.parsing.IParserObserver3)2 HashSet (java.util.HashSet)1 ResourceException (org.eclipse.core.internal.resources.ResourceException)1 CoreException (org.eclipse.core.runtime.CoreException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorPart (org.eclipse.ui.IEditorPart)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 PyEdit (org.python.pydev.editor.PyEdit)1 PyParser (org.python.pydev.parser.PyParser)1 ParseException (org.python.pydev.parser.jython.ParseException)1