From ffd78b8f4c0a24f1e76d2ad1f355119a1a85332b Mon Sep 17 00:00:00 2001 From: Jiger Patel Date: Sat, 21 Jun 2003 14:50:52 +0000 Subject: [PATCH] Updated to pmd 1.1 and lots of code improvements git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2015 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-jedit/config/pmd.props | 2 +- pmd-jedit/etc/build.xml | 4 +- .../pmd/jedit/CPDDuplicateCodeViewer.java | 62 ++++---- .../sourceforge/pmd/jedit/PMDJEditPlugin.java | 136 +++++++++--------- 4 files changed, 104 insertions(+), 100 deletions(-) diff --git a/pmd-jedit/config/pmd.props b/pmd-jedit/config/pmd.props index d62f78f928..1eedb25dd4 100644 --- a/pmd-jedit/config/pmd.props +++ b/pmd-jedit/config/pmd.props @@ -8,7 +8,7 @@ plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=jedit.html plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.3 plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.00.99.00 plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.2 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-1.05.jar +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-1.1.jar plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=jaxen-core-1.0-fcs.jar plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=saxpath-1.0-fcs.jar diff --git a/pmd-jedit/etc/build.xml b/pmd-jedit/etc/build.xml index a97f79e029..b3ef0677c3 100644 --- a/pmd-jedit/etc/build.xml +++ b/pmd-jedit/etc/build.xml @@ -4,9 +4,9 @@ - + - + diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java index fc477ebeba..6c6684a757 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java @@ -17,7 +17,6 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; import java.awt.BorderLayout; import java.util.Vector; -import org.gjt.sp.util.Log; //End of Imports /** @@ -46,18 +45,19 @@ public class CPDDuplicateCodeViewer extends JPanel public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); - if (node == null) return; - - //System.out.println("Node is " + node +" class "+ node.getClass()); - if (node.isLeaf() && node instanceof Duplicate) + if (node != null) { - Duplicate duplicate = (Duplicate)node; - gotoDuplicate(duplicate); - //System.out.println("Got!! " + duplicate); - } - else - { - //System.out.println("Something else. Please check "); + //System.out.println("Node is " + node +" class "+ node.getClass()); + if (node.isLeaf() && node instanceof Duplicate) + { + Duplicate duplicate = (Duplicate)node; + gotoDuplicate(duplicate); + //System.out.println("Got!! " + duplicate); + } + else + { + //System.out.println("Something else. Please check "); + } } } }); @@ -75,29 +75,25 @@ public class CPDDuplicateCodeViewer extends JPanel public void gotoDuplicate(final Duplicate duplicate) { - if(duplicate == null) + if(duplicate != null) { - return; - } - - final Buffer buffer = jEdit.openFile(view,duplicate.getFilename()); - - VFSManager.runInAWTThread(new Runnable() - { - public void run() + final Buffer buffer = jEdit.openFile(view,duplicate.getFilename()); + + VFSManager.runInAWTThread(new Runnable() { - view.setBuffer(buffer); - - int start = buffer.getLineStartOffset(duplicate.getBeginLine()); - int end = buffer.getLineEndOffset(duplicate.getEndLine()-2); - //Log.log(Log.DEBUG, this.getClass(), "Start Line "+ duplicate.getBeginLine() + " End Line "+ duplicate.getEndLine() + " Start " + start + " End "+ end); - //Since an AIOOB Exception is thrown if the end is the end of file. we do a -1 from end to fix it. - view.getTextArea().setSelection(new Selection.Range(start,end -1)); - view.getTextArea().moveCaretPosition(start); - } - }); - - + public void run() + { + view.setBuffer(buffer); + + int start = buffer.getLineStartOffset(duplicate.getBeginLine()); + int end = buffer.getLineEndOffset(duplicate.getEndLine()-2); + //Log.log(Log.DEBUG, this.getClass(), "Start Line "+ duplicate.getBeginLine() + " End Line "+ duplicate.getEndLine() + " Start " + start + " End "+ end); + //Since an AIOOB Exception is thrown if the end is the end of file. we do a -1 from end to fix it. + view.getTextArea().setSelection(new Selection.Range(start,end -1)); + view.getTextArea().moveCaretPosition(start); + } + }); + } } public DefaultMutableTreeNode getRoot() diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java index b876cb0329..028dd00e38 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java @@ -51,6 +51,7 @@ public class PMDJEditPlugin extends EditPlugin { public static final String NAME = "PMD"; public static final String OPTION_RULES_PREFIX = "options.pmd.rules."; public static final String OPTION_UI_DIRECTORY_POPUP = "options.pmd.ui.directorypopup"; + public static final String DEFAULT_TILE_MINSIZE_PROPERTY = "pmd.cpd.defMinTileSize"; //private static RE re = new UncheckedRE("Starting at line ([0-9]*) of (\\S*)"); private static PMDJEditPlugin instance; @@ -77,22 +78,26 @@ public class PMDJEditPlugin extends EditPlugin { } // boilerplate JEdit code - public static void checkDirectory(View view) { - instance.instanceCheckDirectory(view); - } + public static void checkDirectory(View view) { + instance.instanceCheckDirectory(view); + } public void instanceCheckDirectory(View view) { - if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) { + if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) + { final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan", NAME, JOptionPane.QUESTION_MESSAGE); - if (dir == null) { - return; + if (dir != null) + { + if (!(new File(dir)).exists() || !(new File(dir)).isDirectory() ) + { + JOptionPane.showMessageDialog(jEdit.getFirstView(), dir + " is not a valid directory name", NAME, JOptionPane.ERROR_MESSAGE); + return; + } + process(findFiles(dir, false)); } - if (!(new File(dir)).exists() || !(new File(dir)).isDirectory() ) { - JOptionPane.showMessageDialog(jEdit.getFirstView(), dir + " is not a valid directory name", NAME, JOptionPane.ERROR_MESSAGE); - return; - } - process(findFiles(dir, false)); - } else { + } + else + { final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); if(browser == null) { JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); @@ -102,51 +107,54 @@ public class PMDJEditPlugin extends EditPlugin { } } - // check all open buffers - public static void checkAllOpenBuffers(View view) { - instance.instanceCheckAllOpenBuffers(view); - } + // check all open buffers + public static void checkAllOpenBuffers(View view) { + instance.instanceCheckAllOpenBuffers(view); + } - public void instanceCheckAllOpenBuffers(View view) { - // I'm putting the files in a Set to work around some - // odd behavior in jEdit - the buffer.getNext() - // seems to iterate over the files twice. - Set fileSet = new HashSet(); - for (int i=0; i