[Pydev-cvs] org.python.pydev/src/org/python/pydev/builder/pylint PyLintPrefPage.java,1.9,1.10 PyLint
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-02-23 14:29:46
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/pylint In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7296/src/org/python/pydev/builder/pylint Modified Files: PyLintPrefPage.java PyLintVisitor.java Log Message: Index: PyLintVisitor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/pylint/PyLintVisitor.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PyLintVisitor.java 16 Feb 2005 16:48:50 -0000 1.14 --- PyLintVisitor.java 23 Feb 2005 14:29:37 -0000 1.15 *************** *** 7,10 **** --- 7,13 ---- import java.io.File; + import java.util.ArrayList; + import java.util.Iterator; + import java.util.List; import java.util.StringTokenizer; *************** *** 15,18 **** --- 18,25 ---- import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; + import org.eclipse.core.runtime.IProgressMonitor; + import org.eclipse.core.runtime.IStatus; + import org.eclipse.core.runtime.Status; + import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; *************** *** 33,36 **** --- 40,211 ---- */ public static final String PYLINT_PROBLEM_MARKER = "org.python.pydev.pylintproblemmarker"; + + /** + * This class runs as a thread to get the markers, and only stops the IDE when the markers are being added. + * + * @author Fabio Zadrozny + */ + public static class PyLintThread extends Thread{ + + IResource resource; + IDocument document; + IPath location; + + List markers = new ArrayList(); + + public PyLintThread(IResource resource, IDocument document, IPath location){ + this.resource = resource; + this.document = document; + this.location = location; + } + + /** + * @see java.lang.Thread#run() + */ + public void run() { + try { + passPyLint(); + + new Job("Adding markers"){ + + protected IStatus run(IProgressMonitor monitor) { + try { + resource.deleteMarkers(PYLINT_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + } catch (CoreException e3) { + PydevPlugin.log(e3); + } + + for (Iterator iter = markers.iterator(); iter.hasNext();) { + Object[] el = (Object[]) iter.next(); + + String tok = (String) el[0]; + String type = (String) el[1]; + int priority = ((Integer)el[2]).intValue(); + String id = (String) el[3]; + int line = ((Integer)el[4]).intValue(); + createMarker(resource, "ID:"+id+" "+tok , line, type, priority); + } + + return PydevPlugin.makeStatus(Status.OK, "", null); + } + }.schedule(); + + + } catch (final CoreException e) { + new Job("Error reporting"){ + protected IStatus run(IProgressMonitor monitor) { + PydevPlugin.log(e); + return PydevPlugin.makeStatus(Status.OK, "", null); + } + }.schedule(); + } + } + + /** + * @param tok + * @param type + * @param priority + * @param id + * @param line + */ + private void addToMarkers(String tok, String type, int priority, String id, int line) { + markers.add(new Object[]{tok, type, new Integer(priority), id, new Integer(line)} ); + } + + /** + * @param resource + * @param document + * @param location + * @throws CoreException + */ + private void passPyLint() throws CoreException { + File script; + script = PydevPlugin.getScriptWithinPySrc("ThirdParty/logilab/pylint/lint.py"); + File arg = new File(location.toOSString()); + + String lintargs = " --include-ids=y "; + lintargs += PyLintPrefPage.getPylintArgs().replaceAll("\r","").replaceAll("\n"," "); + lintargs += " "; + + String output = SimplePythonRunner.runAndGetOutput(script.getAbsolutePath(), lintargs+arg.getAbsolutePath(), script.getParentFile()); + + StringTokenizer tokenizer = new StringTokenizer(output, "\r\n"); + + boolean useW = PyLintPrefPage.useWarnings(); + boolean useE = PyLintPrefPage.useErrors(); + boolean useF = PyLintPrefPage.useFatal(); + boolean useC = PyLintPrefPage.useCodingStandard(); + boolean useR = PyLintPrefPage.useRefactorTips(); + + + while(tokenizer.hasMoreTokens()){ + String tok = tokenizer.nextToken(); + + try { + String type = null; + int priority = 0; + + //W0611: 3: Unused import finalize + //F0001: 0: Unable to load module test.test2 (list index out of range) + //C0321: 25:fdfd: More than one statement on a single line + if(tok.startsWith("C")&& useC && tok.indexOf(":") != -1){ + type = PYLINT_PROBLEM_MARKER; + priority = Marker.SEVERITY_WARNING; + } + else if(tok.startsWith("R") && useR && tok.indexOf(":") != -1){ + type = PYLINT_PROBLEM_MARKER; + priority = Marker.SEVERITY_WARNING; + } + else if(tok.startsWith("W") && useW && tok.indexOf(":") != -1){ + type = PYLINT_PROBLEM_MARKER; + priority = Marker.SEVERITY_WARNING; + } + else if(tok.startsWith("E") && useE && tok.indexOf(":") != -1){ + type = PYLINT_PROBLEM_MARKER; + priority = Marker.SEVERITY_ERROR; + } + else if(tok.startsWith("F") && useF && tok.indexOf(":") != -1){ + type = PYLINT_PROBLEM_MARKER; + priority = Marker.SEVERITY_ERROR; + } + + String initial = tok; + try { + if(type != null){ + String id = tok.substring(0, tok.indexOf(":")).trim(); + + tok = tok.substring(tok.indexOf(":")+1); + int line = Integer.parseInt(tok.substring(0, tok.indexOf(":")).trim() ); + + IRegion region = null; + try { + region = document.getLineInformation(line - 1); + } catch (Exception e) { + region = document.getLineInformation(line); + } + String lineContents = document.get(region.getOffset(), region.getLength()); + + int pos = -1; + if( ( pos = lineContents.indexOf("IGNORE:") ) != -1){ + String lintW = lineContents.substring(pos+"IGNORE:".length()); + if (lintW.startsWith(id)){ + continue; + } + } + + tok = tok.substring(tok.indexOf(":")+1); + addToMarkers(tok, type, priority, id, line); + } + } catch (RuntimeException e2) { + e2.printStackTrace(); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + + + } public boolean visitResource(IResource resource, IDocument document) { *************** *** 51,150 **** IPath location = PydevPlugin.getLocation(file.getFullPath()); ! File script; ! try { ! script = PydevPlugin.getScriptWithinPySrc("ThirdParty/logilab/pylint/lint.py"); ! File arg = new File(location.toOSString()); ! ! String lintargs = " --include-ids=y "; ! lintargs += PyLintPrefPage.getPylintArgs().replaceAll("\r","").replaceAll("\n"," "); ! lintargs += " "; ! ! String output = SimplePythonRunner.runAndGetOutput(script.getAbsolutePath(), lintargs+arg.getAbsolutePath(), script.getParentFile()); ! ! StringTokenizer tokenizer = new StringTokenizer(output, "\r\n"); ! ! boolean useW = PyLintPrefPage.useWarnings(); ! boolean useE = PyLintPrefPage.useErrors(); ! boolean useF = PyLintPrefPage.useFatal(); ! boolean useC = PyLintPrefPage.useCodingStandard(); ! boolean useR = PyLintPrefPage.useRefactorTips(); ! ! try { ! resource.deleteMarkers(PYLINT_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); ! } catch (CoreException e3) { ! PydevPlugin.log(e3); ! } ! ! while(tokenizer.hasMoreTokens()){ ! String tok = tokenizer.nextToken(); ! ! try { ! String type = null; ! int priority = 0; ! ! //W0611: 3: Unused import finalize ! //F0001: 0: Unable to load module test.test2 (list index out of range) ! //C0321: 25:fdfd: More than one statement on a single line ! if(tok.startsWith("C")&& useC && tok.indexOf(":") != -1){ ! type = PYLINT_PROBLEM_MARKER; ! priority = Marker.SEVERITY_WARNING; ! } ! else if(tok.startsWith("R") && useR && tok.indexOf(":") != -1){ ! type = PYLINT_PROBLEM_MARKER; ! priority = Marker.SEVERITY_WARNING; ! } ! else if(tok.startsWith("W") && useW && tok.indexOf(":") != -1){ ! type = PYLINT_PROBLEM_MARKER; ! priority = Marker.SEVERITY_WARNING; ! } ! else if(tok.startsWith("E") && useE && tok.indexOf(":") != -1){ ! type = PYLINT_PROBLEM_MARKER; ! priority = Marker.SEVERITY_ERROR; ! } ! else if(tok.startsWith("F") && useF && tok.indexOf(":") != -1){ ! type = PYLINT_PROBLEM_MARKER; ! priority = Marker.SEVERITY_ERROR; ! } ! ! String initial = tok; ! try { ! if(type != null){ ! String id = tok.substring(0, tok.indexOf(":")).trim(); ! ! tok = tok.substring(tok.indexOf(":")+1); ! int line = Integer.parseInt(tok.substring(0, tok.indexOf(":")).trim() ); ! ! IRegion region = null; ! try { ! region = document.getLineInformation(line - 1); ! } catch (Exception e) { ! region = document.getLineInformation(line); ! } ! String lineContents = document.get(region.getOffset(), region.getLength()); ! ! int pos = -1; ! if( ( pos = lineContents.indexOf("IGNORE:") ) != -1){ ! String lintW = lineContents.substring(pos+"IGNORE:".length()); ! if (lintW.startsWith(id)){ ! continue; ! } ! } ! ! tok = tok.substring(tok.indexOf(":")+1); ! createMarker(resource, "ID:"+id+" "+tok , line, type, priority); ! } ! } catch (RuntimeException e2) { ! e2.printStackTrace(); ! } ! } catch (Exception e1) { ! e1.printStackTrace(); ! } ! } ! } catch (CoreException e) { ! PydevPlugin.log(e); ! } } return true; } /** * @see org.python.pydev.builder.PyDevBuilderVisitor#visitRemovedResource(org.eclipse.core.resources.IResource, org.eclipse.jface.text.IDocument) --- 226,235 ---- IPath location = PydevPlugin.getLocation(file.getFullPath()); ! PyLintThread thread = new PyLintThread(resource, document, location); ! thread.start(); } return true; } + /** * @see org.python.pydev.builder.PyDevBuilderVisitor#visitRemovedResource(org.eclipse.core.resources.IResource, org.eclipse.jface.text.IDocument) Index: PyLintPrefPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/builder/pylint/PyLintPrefPage.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PyLintPrefPage.java 3 Feb 2005 16:31:03 -0000 1.9 --- PyLintPrefPage.java 23 Feb 2005 14:29:37 -0000 1.10 *************** *** 93,96 **** --- 93,98 ---- addField(new IntegerFieldEditor(MAX_PYLINT_DELTA, "Max delta to run PyLint?", p)); FileFieldEditor fileField = new FileFieldEditor(PYLINT_FILE_LOCATION, "Location of pylint:", true, p); + //not used - some patches had to be applied. + fileField.setEnabled(false, p); addField(fileField); |