diff --git a/pmd-netbeans/src/pmd/PMDAnnotation.java b/pmd-netbeans/src/pmd/PMDAnnotation.java new file mode 100644 index 0000000000..7345dc8f46 --- /dev/null +++ b/pmd-netbeans/src/pmd/PMDAnnotation.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2002, Ole-Martin Mørk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ +package pmd; + +import org.openide.text.Annotation; + +/** + * Just a class thats mission is to mark the line where the + * error is. It's using netbeans java compiler's annotationtype to + * mark the line. + * @todo create our own annotationtype + * @author ole martin mørk + */ +public class PMDAnnotation extends Annotation { + + /** + * The annotation type. + * @return org-netbeans-core-compiler-error + */ + public String getAnnotationType() { + return "org-netbeans-core-compiler-error"; + } + + /** + * A short description of this annotation + * @return the short description + */ + public String getShortDescription() { + return "short description?"; + } +} \ No newline at end of file diff --git a/pmd-netbeans/src/pmd/PMDOutputListener.java b/pmd-netbeans/src/pmd/PMDOutputListener.java index 900522b21a..95d0f33803 100644 --- a/pmd-netbeans/src/pmd/PMDOutputListener.java +++ b/pmd-netbeans/src/pmd/PMDOutputListener.java @@ -35,33 +35,72 @@ import org.openide.windows.OutputEvent; import org.openide.windows.OutputListener; import org.openide.windows.WindowManager; + /** * @author Ole-Martin Mørk * @created 24. oktober 2002 */ public class PMDOutputListener implements OutputListener { - + /** The annotation used to mark the line where the error is */ + private final PMDAnnotation annotation = new PMDAnnotation(); + + /** The instance of this class */ + private final static PMDOutputListener instance = new PMDOutputListener(); + + /** + * Private constructor + * @see #getInstance() + */ + private PMDOutputListener() + { + //Empty constructor + } + + /** + * Returns the instance of this class + * @return the instance + */ + public static PMDOutputListener getInstance() + { + return instance; + } + + /** + * Removes the marking of the line. + * @todo remove the marking when the line is edited + */ + public void detach() + { + annotation.detach(); + } + + /** + * Fired when the user doubleclicks on a line in the outputpane + * @param outputEvent the event that was fired + */ public void outputLineAction( OutputEvent outputEvent ) { - DataObject object = FaultRegistry.getDataObject( outputEvent.getLine() ); - OpenCookie openC = ( OpenCookie )object.getCookie( OpenCookie.class ); + OpenCookie openC = (OpenCookie)object.getCookie( OpenCookie.class ); openC.open(); - EditorCookie cookie = ( EditorCookie )WindowManager.getDefault().getRegistry().getActivatedNodes()[0].getCookie( EditorCookie.class ); - Set set = cookie.getLineSet(); - int lineNum = Fault.getLineNum( outputEvent.getLine() ); - Line line = set.getOriginal( lineNum - 1 ); - line.markError(); - line.show( Line.SHOW_GOTO ); + EditorCookie cookie = (EditorCookie)WindowManager.getDefault().getRegistry().getActivatedNodes()[0].getCookie( EditorCookie.class ); + if( cookie != null ) { + Set set = cookie.getLineSet(); + int lineNum = Fault.getLineNum( outputEvent.getLine() ); + Line line = set.getOriginal( lineNum - 1 ); + annotation.detach(); + annotation.attach( line ); + line.show( Line.SHOW_GOTO ); + } } - - public void outputLineCleared( OutputEvent outputEvent ) - { - } - - public void outputLineSelected( OutputEvent outputEvent ) - { - } - -} + /** + * Not implemented + */ + public void outputLineCleared( OutputEvent outputEvent ){} + + /** + * Not implemented + */ + public void outputLineSelected( OutputEvent outputEvent ){} +} \ No newline at end of file diff --git a/pmd-netbeans/src/pmd/RunPMDAction.java b/pmd-netbeans/src/pmd/RunPMDAction.java index 6ebd594fbe..63ebf844a7 100644 --- a/pmd-netbeans/src/pmd/RunPMDAction.java +++ b/pmd-netbeans/src/pmd/RunPMDAction.java @@ -163,7 +163,8 @@ public class RunPMDAction extends CookieAction */ protected void performAction( Node[] node ) { - PMDOutputListener listener = new PMDOutputListener(); + PMDOutputListener listener = PMDOutputListener.getInstance(); + listener.detach(); FaultRegistry.clearRegistry(); try { printed = false;