Checkstyle module builds and runs w/ nb 5.0 again! BLD200601161900
authorhair@netbeans.org
Mon, 16 Jan 2006 10:42:17 +0000
changeset 675738c6592f088a
parent 6756 7e0e28f7a66f
child 6758 568690c95288
Checkstyle module builds and runs w/ nb 5.0 again!
Build structure refactored to use the netbeans-module-commons-logging module correctly. See the README file.
Now provides "automatic fixes" for whitespace missing/needed, final keyword needed, and unused import checkstyle violations.
tasklist.checkstyle/README
tasklist.checkstyle/build.xml
tasklist.checkstyle/nbproject/project.properties
tasklist.checkstyle/nbproject/project.xml
tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/AbstractSuggestionPerformer.java
tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/DeleteLineSuggestionPerformer.java
tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/DeleteSpaceSuggestionPerformer.java
tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/TrailingSpacesSuggestionPerformer.java
tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/ViolationProvider.java
     1.1 --- a/tasklist.checkstyle/README	Sat Jan 14 11:48:25 2006 +0000
     1.2 +++ b/tasklist.checkstyle/README	Mon Jan 16 10:42:17 2006 +0000
     1.3 @@ -3,9 +3,14 @@
     1.4  
     1.5  Due to licensing issues, those bits are not hosted here,
     1.6  so you'll need to download it yourself, and locate
     1.7 -checkstyle-all-X.X.jar inside the installation, then
     1.8 -place it into the "tasklist/external" directory.
     1.9 +checkstyle-X.X.jar inside the installation, then
    1.10 +copy it into the "tasklist/external/checkstyle.jar" directory.
    1.11 +
    1.12 +You must also copy into the "tasklist/external" directory antlr.jar,
    1.13 +commons-beanutils-core.jar, commons-cli.jar, and commons-collections.jar.
    1.14 +These are also found in the checkstyle download.
    1.15 +
    1.16  You should also place the checkstyle configuration
    1.17  file you want to use, for example
    1.18    checkstyle-X.X/contrib/examples/conf/BlochEffectiveJava.xml
    1.19 -into external and name it "checkstyle.xml".
    1.20 +into external and name it "checkstyle_checks.xml".
     2.1 --- a/tasklist.checkstyle/build.xml	Sat Jan 14 11:48:25 2006 +0000
     2.2 +++ b/tasklist.checkstyle/build.xml	Mon Jan 16 10:42:17 2006 +0000
     2.3 @@ -18,22 +18,45 @@
     2.4      <target name="netbeans-extra" depends="release"/>
     2.5      
     2.6      <target name="release" depends="build-init">
     2.7 -        <available file="../external/checkstyle-all.jar" property="checkstyle-all.present" />
     2.8 -        <fail unless="checkstyle-all.present" message="Missing library. Read README for proper setup." />
     2.9 +        <loadfile property="readme.txt" srcfile="README" />
    2.10 +        
    2.11 +        <available file="../external/checkstyle.jar" property="checkstyle.present" />
    2.12 +        <fail unless="checkstyle.present"> Missing library.
    2.13 +            ${readme.txt} 
    2.14 +        </fail>
    2.15 +        <available file="../external/antlr.jar" property="antlr.present" />
    2.16 +        <fail unless="antlr.present">Missing library.
    2.17 +            ${readme.txt} 
    2.18 +        </fail>
    2.19 +        <available file="../external/checkstyle.jar" property="commons-beanutils-core.present" />
    2.20 +        <fail unless="commons-beanutils-core.present"> Missing library.
    2.21 +            ${readme.txt} 
    2.22 +        </fail>
    2.23 +        <available file="../external/checkstyle.jar" property="commons-cli.present" />
    2.24 +        <fail unless="commons-cli.present"> Missing library.
    2.25 +            ${readme.txt} 
    2.26 +        </fail>
    2.27 +        <available file="../external/checkstyle.jar" property="commons-collections.present" />
    2.28 +        <fail unless="commons-collections.present">Missing library.
    2.29 +            ${readme.txt} 
    2.30 +        </fail>
    2.31          <available file="../external/checkstyle_checks.xml" property="checkstyle-rule.present" />
    2.32 -        <fail unless="checkstyle-rule.present" message="Missing ruleset. Read README for proper setup."/>
    2.33 +        <fail unless="checkstyle-rule.present">Missing library.
    2.34 +            ${readme.txt}
    2.35 +        </fail>
    2.36 +        
    2.37          <mkdir dir="${cluster}/modules/ext"/>
    2.38          <copy todir="${cluster}/modules/ext">
    2.39              <fileset dir="../external">
    2.40 -                <include name="checkstyle-all.jar"/>
    2.41 +                <include name="checkstyle.jar"/>
    2.42 +                <include name="antlr.jar"/>
    2.43 +                <include name="commons-beanutils-core.jar"/>
    2.44 +                <include name="commons-cli.jar"/>
    2.45 +                <include name="commons-collections.jar"/>
    2.46              </fileset>
    2.47          </copy>
    2.48         <mkdir dir="${cluster}/configs"/>
    2.49 -       <copy todir="${cluster}/configs">
    2.50 -         <fileset dir="../external">
    2.51 -           <include name="checkstyle.xml"/>
    2.52 -         </fileset>
    2.53 -       </copy>
    2.54 +       <copy tofile="${cluster}/configs/checkstyle.xml" file="../external/checkstyle_checks.xml"/>
    2.55      </target>
    2.56      
    2.57      <target name="changelog">
     3.1 --- a/tasklist.checkstyle/nbproject/project.properties	Sat Jan 14 11:48:25 2006 +0000
     3.2 +++ b/tasklist.checkstyle/nbproject/project.properties	Mon Jan 16 10:42:17 2006 +0000
     3.3 @@ -11,7 +11,11 @@
     3.4  
     3.5  spec.version.base=0.15.0
     3.6  extra.module.files=\
     3.7 -    modules/ext/checkstyle-all.jar,\
     3.8 +    modules/ext/checkstyle.jar,\
     3.9 +    modules/ext/antlr.jar,\
    3.10 +    modules/ext/commons-beanutils-core.jar,\
    3.11 +    modules/ext/commons-cli.jar,\
    3.12 +    modules/ext/commons-collections.jar,\
    3.13      configs/checkstyle.xml
    3.14  
    3.15  #nbm.homepage=http://tasklist.netbeans.org/updates/tasklist-checkstyle.html
     4.1 --- a/tasklist.checkstyle/nbproject/project.xml	Sat Jan 14 11:48:25 2006 +0000
     4.2 +++ b/tasklist.checkstyle/nbproject/project.xml	Mon Jan 16 10:42:17 2006 +0000
     4.3 @@ -18,29 +18,15 @@
     4.4              <code-name-base>org.netbeans.modules.tasklist.checkstyle</code-name-base>
     4.5              <module-dependencies>
     4.6                  <dependency>
     4.7 -                    <code-name-base>org.openide</code-name-base>
     4.8 +                    <code-name-base>org.netbeans.libs.commons_logging</code-name-base>
     4.9                      <build-prerequisite/>
    4.10                      <compile-dependency/>
    4.11                      <run-dependency>
    4.12                          <release-version>1</release-version>
    4.13 -                        <specification-version>4.47</specification-version>
    4.14 +                        <specification-version>1.3.1</specification-version>
    4.15                      </run-dependency>
    4.16                  </dependency>
    4.17                  <dependency>
    4.18 -                    <code-name-base>org.openide.src</code-name-base>
    4.19 -                    <build-prerequisite/>
    4.20 -                    <compile-dependency/>
    4.21 -                    <run-dependency>
    4.22 -                        <specification-version>1.0</specification-version>
    4.23 -                    </run-dependency>
    4.24 -                </dependency>
    4.25 -                <dependency>
    4.26 -                    <code-name-base>org.openide.loaders</code-name-base>
    4.27 -                    <build-prerequisite/>
    4.28 -                    <compile-dependency/>
    4.29 -                    <run-dependency/>
    4.30 -                </dependency>	
    4.31 -                <dependency>
    4.32                      <code-name-base>org.netbeans.modules.tasklist.core</code-name-base>
    4.33                      <build-prerequisite/>
    4.34                      <compile-dependency/>
    4.35 @@ -58,11 +44,89 @@
    4.36                          <implementation-version/>
    4.37                      </run-dependency>
    4.38                  </dependency>
    4.39 +                <dependency>
    4.40 +                    <code-name-base>org.openide.explorer</code-name-base>
    4.41 +                    <build-prerequisite/>
    4.42 +                    <compile-dependency/>
    4.43 +                    <run-dependency>
    4.44 +                        <specification-version>6.5.1</specification-version>
    4.45 +                    </run-dependency>
    4.46 +                </dependency>
    4.47 +                <dependency>
    4.48 +                    <code-name-base>org.openide.filesystems</code-name-base>
    4.49 +                    <build-prerequisite/>
    4.50 +                    <compile-dependency/>
    4.51 +                    <run-dependency>
    4.52 +                        <specification-version>6.4.1</specification-version>
    4.53 +                    </run-dependency>
    4.54 +                </dependency>
    4.55 +                <dependency>
    4.56 +                    <code-name-base>org.openide.loaders</code-name-base>
    4.57 +                    <build-prerequisite/>
    4.58 +                    <compile-dependency/>
    4.59 +                    <run-dependency/>
    4.60 +                </dependency>
    4.61 +                <dependency>
    4.62 +                    <code-name-base>org.openide.modules</code-name-base>
    4.63 +                    <build-prerequisite/>
    4.64 +                    <compile-dependency/>
    4.65 +                    <run-dependency>
    4.66 +                        <specification-version>6.5.1</specification-version>
    4.67 +                    </run-dependency>
    4.68 +                </dependency>
    4.69 +                <dependency>
    4.70 +                    <code-name-base>org.openide.nodes</code-name-base>
    4.71 +                    <build-prerequisite/>
    4.72 +                    <compile-dependency/>
    4.73 +                    <run-dependency>
    4.74 +                        <specification-version>6.7.1</specification-version>
    4.75 +                    </run-dependency>
    4.76 +                </dependency>
    4.77 +                <dependency>
    4.78 +                    <code-name-base>org.openide.src</code-name-base>
    4.79 +                    <build-prerequisite/>
    4.80 +                    <compile-dependency/>
    4.81 +                    <run-dependency>
    4.82 +                        <specification-version>1.0</specification-version>
    4.83 +                    </run-dependency>
    4.84 +                </dependency>
    4.85 +                <dependency>
    4.86 +                    <code-name-base>org.openide.text</code-name-base>
    4.87 +                    <build-prerequisite/>
    4.88 +                    <compile-dependency/>
    4.89 +                    <run-dependency>
    4.90 +                        <specification-version>6.9.1</specification-version>
    4.91 +                    </run-dependency>
    4.92 +                </dependency>
    4.93 +                <dependency>
    4.94 +                    <code-name-base>org.openide.util</code-name-base>
    4.95 +                    <build-prerequisite/>
    4.96 +                    <compile-dependency/>
    4.97 +                    <run-dependency>
    4.98 +                        <specification-version>6.8.1</specification-version>
    4.99 +                    </run-dependency>
   4.100 +                </dependency>
   4.101              </module-dependencies>
   4.102              <public-packages/>
   4.103              <class-path-extension>
   4.104 -                <runtime-relative-path>ext/checkstyle-all.jar</runtime-relative-path>
   4.105 -                <binary-origin>../external/checkstyle-all.jar</binary-origin>
   4.106 +                <runtime-relative-path>ext/checkstyle.jar</runtime-relative-path>
   4.107 +                <binary-origin>../external/checkstyle.jar</binary-origin>
   4.108 +            </class-path-extension>
   4.109 +            <class-path-extension>
   4.110 +                <runtime-relative-path>ext/antlr.jar</runtime-relative-path>
   4.111 +                <binary-origin>../external/antlr.jar</binary-origin>
   4.112 +            </class-path-extension>
   4.113 +            <class-path-extension>
   4.114 +                <runtime-relative-path>ext/commons-beanutils-core.jar</runtime-relative-path>
   4.115 +                <binary-origin>../external/commons-beanutils-core.jar</binary-origin>
   4.116 +            </class-path-extension>
   4.117 +            <class-path-extension>
   4.118 +                <runtime-relative-path>ext/commons-cli.jar</runtime-relative-path>
   4.119 +                <binary-origin>../external/commons-cli.jar</binary-origin>
   4.120 +            </class-path-extension>
   4.121 +            <class-path-extension>
   4.122 +                <runtime-relative-path>ext/commons-collection.jar</runtime-relative-path>
   4.123 +                <binary-origin>../external/commons-collections.jar</binary-origin>
   4.124              </class-path-extension>
   4.125          </data>
   4.126      </configuration>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/AbstractSuggestionPerformer.java	Mon Jan 16 10:42:17 2006 +0000
     5.3 @@ -0,0 +1,126 @@
     5.4 +/*
     5.5 + *                 Sun Public License Notice
     5.6 + * 
     5.7 + * The contents of this file are subject to the Sun Public Licensense is available at
     5.8 + * http://www.sun.com/
     5.9 + * 
    5.10 + * The Original Code is NetBeans. The Initial Developer of the Original
    5.11 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
    5.12 + * Microsystems, Inc. All Rights Reserved.
    5.13 + */
    5.14 +
    5.15 +package org.netbeans.modules.tasklist.checkstyle;
    5.16 +
    5.17 +
    5.18 +import javax.swing.text.BadLocationException;
    5.19 +import javax.swing.text.Document;
    5.20 +import javax.swing.text.Element;
    5.21 +import javax.swing.text.StyledDocument;
    5.22 +
    5.23 +import org.netbeans.modules.tasklist.client.Suggestion;
    5.24 +import org.netbeans.modules.tasklist.client.SuggestionPerformer;
    5.25 +import org.netbeans.modules.tasklist.providers.SuggestionContext;
    5.26 +
    5.27 +import org.openide.ErrorManager;
    5.28 +
    5.29 +/** Handles remembering (through changes as well) the line and column of the violation.
    5.30 + *
    5.31 + * @author hair
    5.32 + * @version $Id$
    5.33 + */
    5.34 +public abstract class AbstractSuggestionPerformer implements SuggestionPerformer {
    5.35 +
    5.36 +    protected final Document doc;
    5.37 +
    5.38 +    protected final int lineno;
    5.39 +    
    5.40 +    protected String columnOnwards;
    5.41 +    
    5.42 +    /**
    5.43 +     * Creates a new instance of AbstractSuggestionPerformer
    5.44 +     */
    5.45 +    AbstractSuggestionPerformer(
    5.46 +            final Document doc,
    5.47 +            final int lineno,
    5.48 +            final int column) {
    5.49 +        
    5.50 +        this.doc = doc;
    5.51 +        this.lineno = lineno;
    5.52 +        
    5.53 +        // instead of remembering the column remember the string from the column to the end of the line.
    5.54 +        final Element elm = getElement(doc, lineno -1  );
    5.55 +        if (elm == null) {
    5.56 +            ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
    5.57 +            return;
    5.58 +        }
    5.59 +        final int offset = elm.getStartOffset();
    5.60 +        final int endOffset = elm.getEndOffset()-1;
    5.61 +        if( column >= 0 ){
    5.62 +            try {
    5.63 +
    5.64 +                columnOnwards = doc.getText(offset + column -1, endOffset-(offset+column -1));
    5.65 +
    5.66 +            } catch (BadLocationException ex) {
    5.67 +                ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
    5.68 +            }
    5.69 +        }
    5.70 +    }
    5.71 +
    5.72 +    public void perform(final Suggestion suggestion) {
    5.73 +        
    5.74 +        final Element elm = getElement(doc, lineno -1  );
    5.75 +        if (elm == null) {
    5.76 +            ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
    5.77 +            return;
    5.78 +        }
    5.79 +        final int offset = elm.getStartOffset();
    5.80 +        final int endOffset = elm.getEndOffset()-1;
    5.81 +        try {
    5.82 +            final String line = doc.getText(offset,endOffset-offset);
    5.83 +            final int idx = line.indexOf(columnOnwards);
    5.84 +            if( idx >= 0 ){
    5.85 +                performImpl(offset+idx);
    5.86 +            }else{
    5.87 +                ErrorManager.getDefault().log(ErrorManager.USER, "Lost position of violation, fix not performed.");
    5.88 +            }
    5.89 +            
    5.90 +        } catch (BadLocationException ex) {
    5.91 +            ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
    5.92 +        }
    5.93 +    }
    5.94 +    
    5.95 +    protected abstract void performImpl(int docPosition) throws BadLocationException;
    5.96 +
    5.97 +    /** Such a simple operation there's no need to ask for confirmation.
    5.98 +     * Also a little tricky to display whitespace being deleted!
    5.99 +     **/
   5.100 +    public Object getConfirmation(final Suggestion suggestion) {
   5.101 +        return null;
   5.102 +    }
   5.103 +
   5.104 +    public boolean hasConfirmation() {
   5.105 +        return false;
   5.106 +    }
   5.107 +    
   5.108 +    /** copied from ChangeCopyrightDatesPerformer **/
   5.109 +    protected final static Element getElement(final Document d, final int linenumber) {
   5.110 +        if (d == null) {
   5.111 +            ErrorManager.getDefault().log(ErrorManager.USER, "d was null");
   5.112 +            return null;
   5.113 +        }
   5.114 +        
   5.115 +        if (!(d instanceof StyledDocument)) {
   5.116 +            ErrorManager.getDefault().log(ErrorManager.USER, "Not a styleddocument");
   5.117 +            return null;
   5.118 +        }
   5.119 +        
   5.120 +        final StyledDocument doc = (StyledDocument) d;
   5.121 +        Element e = doc.getParagraphElement(0).getParentElement();
   5.122 +        if (e == null) {
   5.123 +            // try default root (should work for text/plain)
   5.124 +            e = doc.getDefaultRootElement();
   5.125 +        }
   5.126 +        final Element elm = e.getElement(linenumber);
   5.127 +        return elm;
   5.128 +    }    
   5.129 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/DeleteLineSuggestionPerformer.java	Mon Jan 16 10:42:17 2006 +0000
     6.3 @@ -0,0 +1,69 @@
     6.4 +/*
     6.5 + * DeleteLineSuggestionPerformer.java
     6.6 + *
     6.7 + * Created on December 30, 2005, 9:06 AM
     6.8 + *
     6.9 + * To change this template, choose Tools | Template Manager
    6.10 + * and open the template in the editor.
    6.11 + */
    6.12 +
    6.13 +package org.netbeans.modules.tasklist.checkstyle;
    6.14 +
    6.15 +
    6.16 +import javax.swing.text.BadLocationException;
    6.17 +import javax.swing.text.Document;
    6.18 +import javax.swing.text.Element;
    6.19 +import javax.swing.text.StyledDocument;
    6.20 +
    6.21 +import org.netbeans.modules.tasklist.client.Suggestion;
    6.22 +import org.netbeans.modules.tasklist.client.SuggestionPerformer;
    6.23 +import org.netbeans.modules.tasklist.providers.SuggestionContext;
    6.24 +
    6.25 +import org.openide.ErrorManager;
    6.26 +
    6.27 +/** Simple. Removes the whole line.
    6.28 + *
    6.29 + * @author hair
    6.30 + */
    6.31 +public final class DeleteLineSuggestionPerformer extends AbstractSuggestionPerformer{
    6.32 +    
    6.33 +    /** Creates a new instance of TrailingSpacesSuggestionPerformer */
    6.34 +    DeleteLineSuggestionPerformer(
    6.35 +            final Document doc,
    6.36 +            final int lineno) {
    6.37 +        
    6.38 +        super(doc,lineno,-1);
    6.39 +    }
    6.40 +
    6.41 +    public void perform(final Suggestion suggestion) {
    6.42 +        
    6.43 +        final Element elm = getElement(doc, lineno-1);
    6.44 +        if (elm == null) {
    6.45 +            ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
    6.46 +            return;
    6.47 +        }
    6.48 +        final int offset = elm.getStartOffset();
    6.49 +        final int endOffset = elm.getEndOffset();
    6.50 +        try {
    6.51 +            doc.remove(offset,endOffset-offset);
    6.52 +        } catch (BadLocationException ex) {
    6.53 +            ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
    6.54 +        }
    6.55 +    }
    6.56 +
    6.57 +    /** Such a simple operation there's no need to ask for confirmation.
    6.58 +     * Also a little tricky to display whitespace being deleted!
    6.59 +     **/
    6.60 +    public Object getConfirmation(final Suggestion suggestion) {
    6.61 +        return null;
    6.62 +    }
    6.63 +
    6.64 +    public boolean hasConfirmation() {
    6.65 +        return false;
    6.66 +    }
    6.67 +
    6.68 +    protected void performImpl(int docPosition) throws BadLocationException {
    6.69 +        throw new UnsupportedOperationException("TrailingSpacesSuggestionProvider overrides perform(..) directly.");
    6.70 +    }
    6.71 +
    6.72 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/DeleteSpaceSuggestionPerformer.java	Mon Jan 16 10:42:17 2006 +0000
     7.3 @@ -0,0 +1,34 @@
     7.4 +/* 
     7.5 + *
     7.6 + * InsertSpaceSuggestionPerformer.java
     7.7 + *
     7.8 + * Created on 8 January 2006, 22:28
     7.9 + *
    7.10 + */
    7.11 +
    7.12 +package org.netbeans.modules.tasklist.checkstyle;
    7.13 +
    7.14 +import javax.swing.text.BadLocationException;
    7.15 +import javax.swing.text.Document;
    7.16 +
    7.17 +/**
    7.18 + * @version $Id$
    7.19 + * @author <a href="mailto:mick@wever.org">Michael Semb Wever</a>
    7.20 + */
    7.21 +public final class DeleteSpaceSuggestionPerformer extends AbstractSuggestionPerformer{
    7.22 +    
    7.23 +    /** Creates a new instance of InsertSpaceSuggestionPerformer */
    7.24 +    public DeleteSpaceSuggestionPerformer(
    7.25 +            final Document doc,
    7.26 +            final int lineno,
    7.27 +            final int column) {
    7.28 +        super(doc,lineno,column);
    7.29 +    }
    7.30 +
    7.31 +    protected void performImpl(final int docPosition) throws BadLocationException {
    7.32 +        while( doc.getText(docPosition,1).charAt(0) == ' ' ){
    7.33 +            doc.remove(docPosition,1);
    7.34 +        }
    7.35 +    }
    7.36 +    
    7.37 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/TrailingSpacesSuggestionPerformer.java	Mon Jan 16 10:42:17 2006 +0000
     8.3 @@ -0,0 +1,61 @@
     8.4 +/*
     8.5 + * TrailingSpacesSuggestionPerformer.java
     8.6 + *
     8.7 + * Created on December 30, 2005, 9:06 AM
     8.8 + *
     8.9 + * To change this template, choose Tools | Template Manager
    8.10 + * and open the template in the editor.
    8.11 + */
    8.12 +
    8.13 +package org.netbeans.modules.tasklist.checkstyle;
    8.14 +
    8.15 +
    8.16 +import javax.swing.text.BadLocationException;
    8.17 +import javax.swing.text.Document;
    8.18 +import javax.swing.text.Element;
    8.19 +import javax.swing.text.StyledDocument;
    8.20 +
    8.21 +import org.netbeans.modules.tasklist.client.Suggestion;
    8.22 +import org.netbeans.modules.tasklist.client.SuggestionPerformer;
    8.23 +import org.netbeans.modules.tasklist.providers.SuggestionContext;
    8.24 +
    8.25 +import org.openide.ErrorManager;
    8.26 +
    8.27 +/** Removes Trailing spaces from line.
    8.28 + *
    8.29 + * @author hair
    8.30 + */
    8.31 +public final class TrailingSpacesSuggestionPerformer extends AbstractSuggestionPerformer{
    8.32 +    
    8.33 +    /** Creates a new instance of TrailingSpacesSuggestionPerformer */
    8.34 +    TrailingSpacesSuggestionPerformer(
    8.35 +            final Document doc,
    8.36 +            final int lineno) {
    8.37 +        
    8.38 +        super(doc,lineno,0);
    8.39 +    }
    8.40 +
    8.41 +    public void perform(final Suggestion suggestion) {
    8.42 +        
    8.43 +        final Element elm = getElement(doc, lineno-1);
    8.44 +        if (elm == null) {
    8.45 +            ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
    8.46 +            return;
    8.47 +        }
    8.48 +        final int offset = elm.getStartOffset();
    8.49 +        final int endOffset = elm.getEndOffset()-2; // lines finished with '\n' & ''
    8.50 +        int wsStart = endOffset;
    8.51 +        try {
    8.52 +            while( doc.getText(wsStart,1).charAt(0) == ' ' ){
    8.53 +                --wsStart;
    8.54 +            }
    8.55 +            doc.remove(wsStart+1,endOffset-wsStart);
    8.56 +        } catch (BadLocationException ex) {
    8.57 +            ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
    8.58 +        }
    8.59 +    }
    8.60 +   
    8.61 +    protected void performImpl(int docPosition) throws BadLocationException {
    8.62 +        throw new UnsupportedOperationException("TrailingSpacesSuggestionProvider overrides perform(..) directly.");
    8.63 +    }
    8.64 +}
     9.1 --- a/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/ViolationProvider.java	Sat Jan 14 11:48:25 2006 +0000
     9.2 +++ b/tasklist.checkstyle/src/org/netbeans/modules/tasklist/checkstyle/ViolationProvider.java	Mon Jan 16 10:42:17 2006 +0000
     9.3 @@ -1,9 +1,7 @@
     9.4  /*
     9.5   *                 Sun Public License Notice
     9.6   * 
     9.7 - * The contents of this file are subject to the Sun Public License
     9.8 - * Version 1.0 (the "License"). You may not use this file except in
     9.9 - * compliance with the License. A copy of the License is available at
    9.10 + * The contents of this file are subject to the Sun Public Licensense is available at
    9.11   * http://www.sun.com/
    9.12   * 
    9.13   * The Original Code is NetBeans. The Initial Developer of the Original
    9.14 @@ -75,10 +73,10 @@
    9.15       * methods. */
    9.16      private List tasks = null;
    9.17      
    9.18 -    public List scan(SuggestionContext env) {
    9.19 +    public List scan(final SuggestionContext env) {
    9.20          tasks = null;
    9.21 -
    9.22 -        SuggestionManager manager = SuggestionManager.getDefault();
    9.23 +        this.env = env;
    9.24 +        final SuggestionManager manager = SuggestionManager.getDefault();
    9.25          if (!manager.isEnabled(TYPE)) {
    9.26              return null;
    9.27          }
    9.28 @@ -106,14 +104,13 @@
    9.29          
    9.30          // Checkstyle doesn't seem to have an API where I can pass in
    9.31          // a string reader - it wants to read the files directly!
    9.32 -        FileObject fo = env.getFileObject();
    9.33 -        DataObject dobj = null;
    9.34 +        final FileObject fo = env.getFileObject();
    9.35          try {
    9.36 -            dobj = DataObject.find(fo);
    9.37 +            dataobject = DataObject.find(fo);
    9.38          } catch (DataObjectNotFoundException e) {
    9.39              ErrorManager.getDefault().notify(e);
    9.40          }
    9.41 -        File file = (dobj != null && dobj.isModified() == false) ? FileUtil.toFile(fo) : null;
    9.42 +        final File file = (dataobject != null && dataobject.isModified() == false) ? FileUtil.toFile(fo) : null;
    9.43  
    9.44          if (file != null) {
    9.45              try {
    9.46 @@ -127,10 +124,10 @@
    9.47          } else {
    9.48              Writer out = null;
    9.49              try {
    9.50 -                File tmp = File.createTempFile("tl_cs", "tmp"); // NOI18N
    9.51 +                final File tmp = File.createTempFile("tl_cs", "tmp"); // NOI18N
    9.52                  tmp.deleteOnExit();
    9.53                  out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tmp)));
    9.54 -                CharSequence chars = env.getCharSequence();
    9.55 +                final CharSequence chars = env.getCharSequence();
    9.56                  for (int i=0; i<chars.length(); i++) {
    9.57                      out.write(chars.charAt(i));
    9.58                  }
    9.59 @@ -155,22 +152,23 @@
    9.60          return tasks;
    9.61      }
    9.62  
    9.63 -    private boolean callCheckstyle(File file) {
    9.64 +    private boolean callCheckstyle(final File file) {
    9.65          // TODO: this should only be done once, not for each scan!!!
    9.66          try {
    9.67 -            Checker checker = new Checker();
    9.68 +            final Checker checker = new Checker();
    9.69              ModuleFactory moduleFactory = null;
    9.70              checker.setModuleFactory(moduleFactory);
    9.71              Configuration config = null;
    9.72 -            Properties props = System.getProperties();
    9.73 -                // For now, grab the configuration from the module
    9.74 -                File f = org.openide.modules.InstalledFileLocator.getDefault().locate("configs/checkstyle.xml", "org.netbeans.modules.tasklist.checkstyle", false);
    9.75 -                //System.out.println("FILE LOCATED = " + f);
    9.76 -                if (f == null) {
    9.77 -                    ErrorManager.getDefault().log("Couldn't find configs/checkstyle.xml");
    9.78 -                    return false;
    9.79 -                }
    9.80 -                config = ConfigurationLoader.loadConfiguration(f.getPath(), new PropertiesExpander(props));
    9.81 +            final Properties props = System.getProperties();
    9.82 +            // For now, grab the configuration from the module
    9.83 +            final File f = org.openide.modules.InstalledFileLocator.getDefault().locate("configs/checkstyle.xml", "org.netbeans.modules.tasklist.checkstyle", false);
    9.84 +            //System.out.println("FILE LOCATED = " + f);
    9.85 +            if (f == null) {
    9.86 +                ErrorManager.getDefault().log("Couldn't find configs/checkstyle.xml");
    9.87 +                return false;
    9.88 +            }
    9.89 +
    9.90 +            config = ConfigurationLoader.loadConfiguration(f.getPath(), new PropertiesExpander(props));
    9.91              checker.configure(config);
    9.92              checker.addListener(this);
    9.93              checker.process(new File[] { file }); // Yuck!
    9.94 @@ -233,21 +231,23 @@
    9.95          //System.out.println("addError(" + aEvt + ")");
    9.96          
    9.97          try {
    9.98 -            // Violation line numbers seem to be 0-based
    9.99 -            final Line line = TLUtils.getLineByNumber(dataobject, aEvt.getLine());
   9.100 +            final int lineNo = Math.max(1,aEvt.getLine());
   9.101 +            final Line line = TLUtils.getLineByNumber(dataobject, lineNo);
   9.102                      
   9.103 -            SuggestionPerformer action = null;
   9.104 -            action = null;
   9.105 -            String description = aEvt.getLocalizedMessage().getMessage();
   9.106 +            final SuggestionPerformer action = getAction(aEvt);
   9.107 +            final String description = aEvt.getLocalizedMessage().getMessage();
   9.108                      
   9.109 -            SuggestionManager manager = SuggestionManager.getDefault();
   9.110 -            SuggestionAgent s = manager.createSuggestion(
   9.111 +            final SuggestionManager manager = SuggestionManager.getDefault();
   9.112 +
   9.113 +            final SuggestionAgent s = manager.createSuggestion(
   9.114 +                        env.getFileObject(),
   9.115                          TYPE,
   9.116                          description,
   9.117                          action,
   9.118                          this);
   9.119  
   9.120 -            SeverityLevel sv = aEvt.getSeverityLevel();
   9.121 +            final SeverityLevel sv = aEvt.getSeverityLevel();
   9.122 +            
   9.123              if (sv == SeverityLevel.IGNORE) {
   9.124                  s.setPriority(SuggestionPriority.LOW);
   9.125              } else if (sv == SeverityLevel.INFO) {
   9.126 @@ -263,14 +263,40 @@
   9.127              } 
   9.128              
   9.129              s.setLine(line);
   9.130 +            
   9.131              if (tasks == null) {
   9.132                  tasks = new ArrayList(40); // initial guess
   9.133              }
   9.134 -            tasks.add(s);
   9.135 +            tasks.add(s.getSuggestion());
   9.136 +
   9.137          } catch (Exception e) {
   9.138              ErrorManager.getDefault().notify(e);
   9.139          }
   9.140      }
   9.141 +
   9.142 +    private SuggestionPerformer getAction(
   9.143 +            final AuditEvent aEvt) {
   9.144 +        
   9.145 +        final String key = aEvt.getLocalizedMessage().getKey();
   9.146 +        if( key != null ){
   9.147 +            System.out.println(key);
   9.148 +            
   9.149 +            if( key.contains("trailing")  // FIXME i18n me. problem is that this comes from the checkstyle.xml
   9.150 +                    && key.contains("spaces") ){ // and can be specified in any language with a common key.
   9.151 +                return new TrailingSpacesSuggestionPerformer(env.getDocument(),aEvt.getLine());
   9.152 +            }else if( "import.unused".equals(key) ){
   9.153 +                return new DeleteLineSuggestionPerformer(env.getDocument(),aEvt.getLine());
   9.154 +            }else if( "ws.notPreceded".equals(key) ){
   9.155 +                return new InsertSpaceSuggestionPerformer(env.getDocument(),aEvt.getLine(),aEvt.getColumn());
   9.156 +            }else if( "ws.notFollowed".equals(key) ){
   9.157 +                return new InsertSpaceSuggestionPerformer(env.getDocument(),aEvt.getLine(),aEvt.getColumn());
   9.158 +            }else if( "final.parameter".equals(key) ){
   9.159 +                return new InsertFinalKeywordSuggestionPerformer(env.getDocument(),aEvt.getLine(),aEvt.getColumn());
   9.160 +            }
   9.161 +           
   9.162 +        }
   9.163 +        return null;
   9.164 +    }
   9.165      
   9.166      
   9.167      /** The list of tasks we're currently showing in the tasklist */