Re: [nbui] Re: trailing blanks removal?

Tor Norbye <[email protected]> Wed, 10 Dec 2003 20:57:08 -0800
Newsgroups gmane.comp.java.netbeans.modules.tasklist.devel
Message-ID <[email protected]>
On Dec 10, 2003, at 4:55 PM, John Richardson wrote:

>
> FWIW: if no one has changed checkstyle yet, I'd be willing to look into
> what modifications are required to use InputStreams.
>
> Is there anything specific, just have an API which runs checkstyle on a
> InputStream?

Take a look at
checkstyle/src/org/netbeans/modules/tasklist/checkstyle/ 
ViolationProvider.java :

         // YUCK! This is a hack! It will operate on the saved file,
         // not the buffer contents! However, checkstyle doesn't seem to
         // have an API where I can pass in a string reader - it wants to
         // read the files directly! XXX
         File file = FileUtil.toFile(dobj.getPrimaryFile());
         if (file != null) {
             ....
             checker.process(new File[] { file }); // Yuck!

It's this last line where we're calling in to checkstyle to process the  
data. I've already registered a listener which is notified of  
checkstyle warnings (and will list these in the suggestions window), so  
the only thing that needs to be done is replace the above File  
manipulation with a call to pass in an InputStream or Reader  
constructed from the live document instead. (The document in question  
is passed in as a parameter to the method containing the above code:  
scan().)

Jesse's quick'n'dirty hack using temp files might be a good start;  
convincing the Checkstyle authors to modify their code (or to do it for  
them) would be even better. The PMD integration module can already take  
advantage of this in tasklist/pmd.

Of course, the checkstyle module currently only lists violations found  
by checkstyle. It would be more useful to offer options to actually fix  
the problems found - the tasklist/pmd module has auto-fixers for a few  
things (such as removing unused fields, methods and imports).  PMD  
itself recently started adding auto fixers to the rules, so we should  
bridge to those as well; that would be another useful project for  
somebody who's willing to contribute.

-- Tor