modified to use ErrorList

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@424 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-07-18 01:28:15 +00:00
parent c7509e73df
commit 173d7770de
6 changed files with 33 additions and 106 deletions

View File

@ -3,7 +3,7 @@
<ACTIONS>
<ACTION NAME="pmd.check">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.check(view);
net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view);
</CODE>
</ACTION>
<ACTION NAME="pmd.options">

View File

@ -12,6 +12,7 @@
<path id="project.class.path">
<pathelement location="${lib}/${pmdjar}"/>
<pathelement location="${lib}/jedit.jar"/>
<pathelement location="${lib}/ErrorList.jar"/>
<pathelement location="${build}"/>
</path>

View File

@ -1,4 +1,5 @@
@echo off
set CLASSPATH=..\build
set CLASSPATH=%CLASSPATH%;..\lib\pmd-0.5.jar
set CLASSPATH=%CLASSPATH%;..\lib\ErrorList.jar
set CLASSPATH=%CLASSPATH%;..\lib\jedit.jar

BIN
pmd-jedit/lib/ErrorList.jar Normal file

Binary file not shown.

View File

@ -7,7 +7,8 @@ package net.sourceforge.pmd.jedit;
import org.gjt.sp.jedit.*;
import org.gjt.sp.jedit.gui.OptionsDialog;
import errorlist.ErrorSource;
import errorlist.DefaultErrorSource;
import javax.swing.*;
import java.util.Vector;
import java.util.Iterator;
@ -25,11 +26,23 @@ public class PMDJEditPlugin extends EBPlugin {
public static final String OPTION_PREFIX = "options.pmd.";
public static final String OPTION_RULESETS_PREFIX = "options.pmd.rulesets.";
private static PMDJEditPlugin instance = new PMDJEditPlugin();
private static PMDJEditPlugin instance;
static {
instance = new PMDJEditPlugin();
instance.start();
}
private DefaultErrorSource errorSource;
// boilerplate JEdit code
public static void check(View view) {
instance.instanceCheck(view);
public void start() {
errorSource = new DefaultErrorSource(NAME);
ErrorSource.registerErrorSource(errorSource);
}
public static void check(Buffer buffer, View view) {
instance.instanceCheck(buffer, view);
}
public static void displayPreferencesDialog(View view) {
@ -41,7 +54,8 @@ public class PMDJEditPlugin extends EBPlugin {
}
// boilerplate JEdit code
public void instanceCheck(View view) {
public void instanceCheck(Buffer buffer, View view) {
errorSource.clear();
RuleContext ctx = new RuleContext();
RuleSetFactory ruleSetFactory = new RuleSetFactory();
SelectedRuleSetsMap selectedRuleSets = new SelectedRuleSetsMap();
@ -51,13 +65,16 @@ public class PMDJEditPlugin extends EBPlugin {
rules.addRuleSet(ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream((String)i.next())));
}
ctx.setReport(new Report());
ctx.setSourceCodeFilename("this");
try {
pmd.processFile(new StringReader(view.getTextArea().getText()), rules, ctx);
new PMDRuleViolationDialog(ctx.getReport());
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
ctx.setSourceCodeFilename(buffer.getPath());
try {
pmd.processFile(new StringReader(view.getTextArea().getText()), rules, ctx);
} catch (FileNotFoundException fnfe) {}
for (Iterator i = ctx.getReport().iterator(); i.hasNext();) {
RuleViolation rv = (RuleViolation)i.next();
String path = buffer.getPath();
DefaultErrorSource.DefaultError err = new DefaultErrorSource.DefaultError(errorSource, ErrorSource.WARNING, path, rv.getLine()-1,0,0,rv.getDescription());
errorSource.addError(err);
}
}
public void instanceDisplayPreferencesDialog(View view) {

View File

@ -1,92 +0,0 @@
/*
* User: tom
* Date: Jul 12, 2002
* Time: 11:08:26 AM
*/
package net.sourceforge.pmd.jedit;
import org.gjt.sp.jedit.jEdit;
import javax.swing.*;
import javax.swing.event.ListDataListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.RuleViolation;
public class PMDRuleViolationDialog {
private JList list;
private JDialog dialog;
private static class RuleViolationListModel implements ListModel {
private Report report;
public RuleViolationListModel(Report report) {
this.report = report;
}
public int getSize() {
return report.size();
}
public Object getElementAt(int index) {
int reportIndex = 0;
for (Iterator i = report.iterator(); i.hasNext();) {
RuleViolation rv = (RuleViolation)i.next();
if (reportIndex == index) {
return "Line " + rv.getLine() + ":" + rv.getDescription();
}
reportIndex++;
}
throw new RuntimeException("Hm, the Report size is " + report.size() + " and you asked for rule violation " + index);
}
public void addListDataListener(ListDataListener l) {}
public void removeListDataListener(ListDataListener l) {}
}
private RuleViolationListModel rvListModel;
public PMDRuleViolationDialog(Report report) {
if (report.isEmpty()) {
JOptionPane.showMessageDialog(jEdit.getFirstView(), "No errors found");
return;
}
dialog = new JDialog(jEdit.getFirstView(), PMDJEditPlugin.NAME, true);
rvListModel = new RuleViolationListModel(report);
//main part of the dialog
list = new JList(rvListModel);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JScrollPane listScroller = new JScrollPane(list);
JPanel listPane = new JPanel();
listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS));
listPane.add(listScroller);
listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
JPanel buttonPane = new JPanel();
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PMDRuleViolationDialog.this.dialog.dispose();
}
});
dialog.getRootPane().setDefaultButton(okButton);
buttonPane.add(okButton);
dialog.getContentPane().add(listPane, BorderLayout.CENTER);
dialog.getContentPane().add(buttonPane, BorderLayout.SOUTH);
dialog.setLocationRelativeTo(jEdit.getFirstView());
dialog.pack();
dialog.setVisible(true);
}
}