Search in sources :

Example 6 with ErrorDescription

use of org.python.pydev.shared_core.model.ErrorDescription in project Pydev by fabioz.

the class OrganizeImportsFixesUnused method beforePerformArrangeImports.

public boolean beforePerformArrangeImports(PySelection ps, PyEdit edit, IFile f) {
    int oldSelection = ps.getRegion().getOffset();
    IDocumentExtension4 doc = (IDocumentExtension4) ps.getDoc();
    if (edit != null) {
        if (!ensureParsed(edit)) {
            return true;
        }
        // Check that the editor time is actually the same as the document time.
        long docTime = doc.getModificationStamp();
        if (docTime != edit.getAstModificationTimeStamp()) {
            return true;
        }
        ErrorDescription errorDescription = edit.getErrorDescription();
        if (errorDescription != null) {
            // Don't remove unused imports if we have syntax errors.
            return true;
        }
    }
    try {
        findAndDeleteUnusedImports(ps, edit, doc, f);
    } catch (Exception e) {
        Log.log(e);
    }
    ps.setSelection(oldSelection, oldSelection);
    return true;
}
Also used : ErrorDescription(org.python.pydev.shared_core.model.ErrorDescription) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ErrorDescription (org.python.pydev.shared_core.model.ErrorDescription)6 CoreException (org.eclipse.core.runtime.CoreException)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 ResourceException (org.eclipse.core.internal.resources.ResourceException)2 MisconfigurationException (org.python.pydev.core.MisconfigurationException)2 ParseException (org.python.pydev.parser.jython.ParseException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1 IRegion (org.eclipse.jface.text.IRegion)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1