Created our own annotation type. Made the annotation go away when the user edits the line.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1183 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Ole-Martin Mork
2002-11-02 20:26:06 +00:00
parent 3a86cbe699
commit 1eb7d66dec
6 changed files with 87 additions and 47 deletions

View File

@ -10,3 +10,5 @@ OpenIDE-Module-Name=PMD
OpenIDE-Module-Display-Category=Tools
OpenIDE-Module-Short-Description=Runs the pmd tool
LBL_pmd_annotation=Error found

View File

@ -95,4 +95,8 @@ public class Fault implements Comparable
{
return Integer.parseInt( fault.substring( fault.indexOf( '[' ) + 1, fault.indexOf( ']' ) ) );
}
}
public static String getErrorMessage( String fault ) {
return fault.substring( fault.indexOf( ":" ) + 2 );
}
}

View File

@ -26,30 +26,53 @@
*/
package pmd;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.openide.text.Annotation;
import org.openide.text.Line;
/**
* 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
* error is. It's using pmd-annotation type to mark the line
* @author ole martin mørk
*/
public class PMDAnnotation extends Annotation {
public class PMDAnnotation extends Annotation implements PropertyChangeListener {
/** The error message shown on mouseover on the pmd icon */
private String errormessage = null;
/**
* The annotation type.
* @return org-netbeans-core-compiler-error
*/
public String getAnnotationType() {
return "org-netbeans-core-compiler-error";
return "pmd-annotation";
}
/**
* Sets the current errormessage
* @param message the errormessage
*/
public void setErrorMessage( String message ) {
errormessage = message;
}
/**
* A short description of this annotation
* @return the short description
*/
public String getShortDescription() {
return "short description?";
return errormessage;
}
/**
* Invoked when the user change the content on the line where the
* annotation is attached
* @param propertyChangeEvent the event fired
*/
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
Line line = (Line)propertyChangeEvent.getSource();
line.removePropertyChangeListener( this );
detach();
}
}

View File

@ -26,17 +26,16 @@
*/
package pmd;
import org.openide.cookies.EditorCookie;
import org.openide.cookies.OpenCookie;
import org.openide.cookies.LineCookie;
import org.openide.loaders.DataObject;
import org.openide.text.Line;
import org.openide.text.Line.Set;
import org.openide.windows.OutputEvent;
import org.openide.windows.OutputListener;
import org.openide.windows.WindowManager;
/**
* Listens for user actions on the output pane
* @author Ole-Martin Mørk
* @created 24. oktober 2002
*/
@ -68,7 +67,6 @@ public class PMDOutputListener implements OutputListener
/**
* Removes the marking of the line.
* @todo remove the marking when the line is edited
*/
public void detach()
{
@ -81,19 +79,18 @@ public class PMDOutputListener implements OutputListener
*/
public void outputLineAction( OutputEvent outputEvent )
{
annotation.detach();
DataObject object = FaultRegistry.getDataObject( outputEvent.getLine() );
OpenCookie openC = (OpenCookie)object.getCookie( OpenCookie.class );
openC.open();
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 );
}
LineCookie cookie = (LineCookie)object.getCookie( LineCookie.class );
Set set = cookie.getLineSet();
int lineNum = Fault.getLineNum( outputEvent.getLine() );
Line line = set.getOriginal( lineNum - 1 );
annotation.setErrorMessage( Fault.getErrorMessage( outputEvent.getLine() ) );
annotation.attach( line );
line.addPropertyChangeListener( annotation );
line.show( Line.SHOW_GOTO );
}
/**
* Not implemented
*/

View File

@ -1,34 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<folder name="Services">
<file name="pmd-config-option.settings" url="config/option.xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.config.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/pmd/resources/PMDOptionsSettingsIcon.gif"/>
<attr name="name" stringvalue="PMD Settings"/>
</file>
</folder>
<folder name="UI">
<folder name="Services">
<folder name="IDEConfiguration">
<folder name="ServerAndExternalToolSettings">
<!-- Note: line break in file contents necessary: -->
<file name="pmd-config-option.shadow">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.config.Bundle"/>
<![CDATA[Services/pmd-config-option.settings
<folder name="Services">
<file name="pmd-config-option.settings" url="config/option.xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.config.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/pmd/resources/PMDOptionsSettingsIcon.gif"/>
<attr name="name" stringvalue="PMD Settings"/>
</file>
</folder>
<folder name="UI">
<folder name="Services">
<folder name="IDEConfiguration">
<folder name="ServerAndExternalToolSettings">
<!-- Note: line break in file contents necessary: -->
<file name="pmd-config-option.shadow">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.config.Bundle"/><![CDATA[Services/pmd-config-option.settings
SystemFileSystem
]]>
</file>
</folder>
</file>
</folder>
</folder>
</folder>
</folder>
<folder name="Actions">
<file name="pmd-RunPMDAction.instance">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.Bundle"/>
</file>
</folder>
<folder name="Editors">
<folder name="AnnotationTypes">
<file name="pmd-annotation.xml" url="resources/annotation.xml"/>
</folder>
</folder>
</folder>
<folder name="Actions">
<file name="pmd-RunPMDAction.instance">
<attr name="SystemFileSystem.localizingBundle" stringvalue="pmd.Bundle"/>
</file>
</folder>
</filesystem>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE type PUBLIC
"-//NetBeans//DTD annotation type 1.0//EN"
"http://www.netbeans.org/dtds/annotation-type-1_0.dtd">
<type name="pmd-annotation"
description_key="LBL_pmd_annotation"
localizing_bundle="pmd.Bundle"
visible="true"
glyph="nbresloc:/pmd/resources/PMDOptionsSettingsIcon.gif"
highlight="#FF8080"
type="linepart"
/>