⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pylintvisitor.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            
            
            IProject project = resource.getProject();
            
            String scriptToExe = REF.getFileAbsolutePath(script);
			String[] paramsToExe = list.toArray(new String[0]);
			String cmdLineToExe = SimplePythonRunner.makeExecutableCommandStr(scriptToExe, paramsToExe);
			write("Pylint: Executing command line:'"+cmdLineToExe+"'", out);
			
			Tuple<String, String> outTup = new SimplePythonRunner().runAndGetOutput(cmdLineToExe, script.getParentFile(), project);
			write("Pylint: The stdout of the command line is: "+outTup.o1, out);
			write("Pylint: The stderr of the command line is: "+outTup.o2, out);
			
			String output = outTup.o1;

            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();
            
            //Set up local values for severity
            int wSeverity = PyLintPrefPage.wSeverity();
            int eSeverity = PyLintPrefPage.eSeverity();
            int fSeverity = PyLintPrefPage.fSeverity();
            int cSeverity = PyLintPrefPage.cSeverity();
            int rSeverity = PyLintPrefPage.rSeverity();
            
            //System.out.println(output);
            if(output.indexOf("Traceback (most recent call last):") != -1){
                PydevPlugin.log(new RuntimeException("PyLint ERROR: \n"+output));
                return;
            }
            if(outTup.o2.indexOf("Traceback (most recent call last):") != -1){
            	PydevPlugin.log(new RuntimeException("PyLint ERROR: \n"+outTup.o2));
            	return;
            }
            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
                    int indexOfDoublePoints = tok.indexOf(":");
                    if(indexOfDoublePoints != -1){
                        
	                    if(tok.startsWith("C")&& useC){
	                        type = PYLINT_PROBLEM_MARKER;
	                        //priority = IMarker.SEVERITY_WARNING;
	                        priority = cSeverity;
	                    }
	                    else if(tok.startsWith("R")  && useR ){
	                        type = PYLINT_PROBLEM_MARKER;
	                        //priority = IMarker.SEVERITY_WARNING;
	                        priority = rSeverity;
	                    }
	                    else if(tok.startsWith("W")  && useW ){
	                        type = PYLINT_PROBLEM_MARKER;
	                        //priority = IMarker.SEVERITY_WARNING;
	                        priority = wSeverity;
	                    }
	                    else if(tok.startsWith("E") && useE ){
	                        type = PYLINT_PROBLEM_MARKER;
	                        //priority = IMarker.SEVERITY_ERROR;
	                        priority = eSeverity;
	                    }
	                    else if(tok.startsWith("F") && useF ){
	                        type = PYLINT_PROBLEM_MARKER;
	                        //priority = IMarker.SEVERITY_ERROR;
	                        priority = fSeverity;
	                    }else{
	                        continue;
	                    }
	                    
                    }else{
                        continue;
                    }
                    
                    try {
                        if(type != null){
                            String id = tok.substring(0, tok.indexOf(":")).trim();
                            
                            int i = tok.indexOf(":");
                            if(i == -1)
                                continue;
                            
                            tok = tok.substring(i+1);

                            i = tok.indexOf(":");
                            if(i == -1)
                                continue;
                            
                            int line = Integer.parseInt(tok.substring(0, i).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;
                                }
                            }
                            
                            i = tok.indexOf(":");
                            if(i == -1)
                                continue;

                            tok = tok.substring(i+1);
                            addToMarkers(tok, type, priority, id, line-1);
                        }
                    } catch (RuntimeException e2) {
                        PydevPlugin.log(e2);
                    }
                } catch (Exception e1) {
                    PydevPlugin.log(e1);
                }
            }
        }


    }
    
    public void visitChangedResource(IResource resource, IDocument document, IProgressMonitor monitor) {
        if(document == null){
        	return;
        }
        if(PyLintPrefPage.usePyLint() == false){
            try {
                resource.deleteMarkers(PYLINT_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
            } catch (CoreException e3) {
                PydevPlugin.log(e3);
            }
            return;
        }
        
        IProject project = resource.getProject();
        PythonNature pythonNature = PythonNature.getPythonNature(project);
        try {
            //pylint can only be used for jython projects
            if (!pythonNature.isPython()) {
                return;
            }
        } catch (Exception e) {
            return;
        }
        if (project != null && resource instanceof IFile) {

            IFile file = (IFile) resource;
            IPath location = file.getRawLocation();
            if(location != null){
                PyLintThread thread = new PyLintThread(resource, document, location);
                thread.start();
            }
        }
    }
    
    public static void write(String cmdLineToExe, IOConsoleOutputStream out) {
    	try {
    		if(fConsole != null && out != null){
    			synchronized(fConsole){
    				out.write(cmdLineToExe);
    			}
    		}
		} catch (IOException e) {
			PydevPlugin.log(e);
		}
	}

	/**
     * @see org.python.pydev.builder.PyDevBuilderVisitor#visitRemovedResource(org.eclipse.core.resources.IResource, org.eclipse.jface.text.IDocument)
     */
    public void visitRemovedResource(IResource resource, IDocument document, IProgressMonitor monitor) {
    }

    /**
     * @see org.python.pydev.builder.PyDevBuilderVisitor#maxResourcesToVisit()
     */
    public int maxResourcesToVisit() {
        int i = PyLintPrefPage.getMaxPyLintDelta();
        if (i < 0){
            i = 0;
        }
        return i;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -