From 5094d1b2cd9d89d23440f788c3dedd0d6e1b2301 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Mon, 24 Feb 2003 22:55:06 +0000 Subject: [PATCH] Not quite working yet, seems to stop after the first click. Odd. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1474 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/jdeveloper/JumpingSelectionModel.java | 9 ++++- .../sourceforge/pmd/jdeveloper/Plugin.java | 36 ++++++++++++++++++- .../pmd/jdeveloper/RuleViolationWrapper.java | 19 ++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationWrapper.java diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java index 34a3426a50..692dc057d2 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java @@ -11,6 +11,10 @@ import javax.swing.DefaultListSelectionModel; import java.util.Iterator; import java.util.List; +/** + * This class was inspired by a class on Sun's web site in the JList tutorial section. It's + * been twiddled somewhat since then, though. + */ public class JumpingSelectionModel extends DefaultListSelectionModel { private DefaultListModel model; @@ -34,7 +38,10 @@ public class JumpingSelectionModel extends DefaultListSelectionModel { Editor editor = (Editor)i.next(); Document doc = editor.getContext().getDocument(); if (doc.getLongLabel().equals(rv.getFilename()) && editor instanceof CodeEditor) { - Ide.getEditorManager().openDefaultEditorInFrame(editor.getContext()); + System.out.println("GOING THERE"); + Ide.getEditorManager().openDefaultEditorInFrame(editor.getContext().getDocument().getURL()); + editor.activate(); + editor.open(); ((CodeEditor)editor).gotoLine(rv.getLine(), 0, false); break; } diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java index feab921d86..73aed300d0 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java @@ -4,6 +4,7 @@ import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.PMDException; import oracle.ide.AddinManager; import oracle.ide.ContextMenu; import oracle.ide.Ide; @@ -18,6 +19,8 @@ import oracle.ide.model.Element; import oracle.ide.model.PackageFolder; import oracle.ide.model.Workspace; import oracle.ide.model.Workspaces; +import oracle.ide.model.Project; +import oracle.ide.model.Document; import oracle.ide.panels.Navigable; import oracle.jdeveloper.model.BusinessComponents; import oracle.jdeveloper.model.EnterpriseJavaBeans; @@ -28,6 +31,7 @@ import oracle.jdeveloper.model.JavaSources; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import java.util.Iterator; +import java.util.List; public class Plugin implements Addin, Controller, ContextMenuListener { @@ -96,7 +100,34 @@ public class Plugin implements Addin, Controller, ContextMenuListener { if (ideAction.getCommandId() == CHECK_CMD_ID) { try { if (resolveType(context.getDocument()) == PROJECT) { - + Project proj = (Project)context.getDocument(); + List foo = proj.getListOfChildren(); + PMD pmd = new PMD(); + SelectedRules rs = new SelectedRules(); + RuleContext ctx = new RuleContext(); + ctx.setReport(new Report()); + for (Iterator i = foo.iterator(); i.hasNext();) { + Document d = (Document)i.next(); + if (d.getLongLabel().endsWith(".java")) { + ctx.setSourceCodeFilename(d.getLongLabel()); + System.out.println("processing " + d.getLongLabel()); + pmd.processFile(context.getDocument().getInputStream(), rs.getSelectedRules(), ctx); + } + } + if (rvPage == null) { + rvPage = new RuleViolationPage(); + } + if (!rvPage.isVisible()) { + rvPage.show(); + } + rvPage.clearAll(); + if (ctx.getReport().isEmpty()) { + JOptionPane.showMessageDialog(null, "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE); + } else { + for (Iterator i = ctx.getReport().iterator(); i.hasNext();) { + rvPage.add((RuleViolation)i.next()); + } + } } else { PMD pmd = new PMD(); RuleContext ctx = new RuleContext(); @@ -120,6 +151,9 @@ public class Plugin implements Addin, Controller, ContextMenuListener { } } return true; + } catch (PMDException e) { + e.printStackTrace(); + e.getOriginalException().printStackTrace(); } catch (Exception e) { e.printStackTrace(); } diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationWrapper.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationWrapper.java new file mode 100644 index 0000000000..fc409c1c58 --- /dev/null +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationWrapper.java @@ -0,0 +1,19 @@ +package net.sourceforge.pmd.jdeveloper; + +import net.sourceforge.pmd.RuleViolation; + +public class RuleViolationWrapper { + private RuleViolation rv; + + public RuleViolationWrapper(RuleViolation rv) { + this.rv = rv; + } + + public RuleViolation getRV() { + return this.rv; + } + + public String toString() { + return rv.getFilename() + ":" + rv.getLine() +":"+ rv.getDescription(); + } +}