diff --git a/pmd-jedit/config/actions.xml b/pmd-jedit/config/actions.xml index 31232902dd..2ab0f8d44c 100644 --- a/pmd-jedit/config/actions.xml +++ b/pmd-jedit/config/actions.xml @@ -3,7 +3,7 @@ - net.sourceforge.pmd.jedit.PMDJEditPlugin.check(view); + net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view); diff --git a/pmd-jedit/etc/build.xml b/pmd-jedit/etc/build.xml index 0f0b13ddb3..7c97cb26cd 100644 --- a/pmd-jedit/etc/build.xml +++ b/pmd-jedit/etc/build.xml @@ -12,6 +12,7 @@ + diff --git a/pmd-jedit/etc/scp.bat b/pmd-jedit/etc/scp.bat index 38dec91353..02af868963 100755 --- a/pmd-jedit/etc/scp.bat +++ b/pmd-jedit/etc/scp.bat @@ -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 \ No newline at end of file diff --git a/pmd-jedit/lib/ErrorList.jar b/pmd-jedit/lib/ErrorList.jar new file mode 100644 index 0000000000..a85f1b4167 Binary files /dev/null and b/pmd-jedit/lib/ErrorList.jar differ diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java index 07b6d01d26..2e231c32ad 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java @@ -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) { diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDRuleViolationDialog.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDRuleViolationDialog.java deleted file mode 100644 index 9baf285bc8..0000000000 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDRuleViolationDialog.java +++ /dev/null @@ -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); - } -}