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
This commit is contained in:
Jiger Patel
2003-06-21 14:50:52 +00:00
parent b4677f7d0c
commit ffd78b8f4c
4 changed files with 104 additions and 100 deletions

View File

@ -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

View File

@ -4,9 +4,9 @@
<property name="src" value="src/"/>
<property name="lib" value="lib/"/>
<property name="build" value="build/"/>
<property name="pmdjar" value="pmd-1.05.jar"/>
<property name="pmdjar" value="pmd-1.1.jar"/>
<property name="pluginversion" value="2.1"/>
<property name="jedit.home" value="c:\Program Files\jEdit 4.1pre9"/>
<property name="jedit.home" value="c:\Program Files\jEdit 4.1"/>
<property name="jedit.jars.dir" value="${jedit.home}\jars"/>
<property name="jedit.install.dir" value="${jedit.jars.dir}"/>

View File

@ -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()

View File

@ -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<jEdit.getBufferCount(); i++ ) {
Buffer buffer = jEdit.getFirstBuffer();
while (buffer != null) {
//System.out.println("file = " + buffer.getFile());
if (buffer.getName().endsWith(".java")) {
fileSet.add(buffer.getFile());
}
buffer = buffer.getNext();
}
}
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<jEdit.getBufferCount(); i++ ) {
Buffer buffer = jEdit.getFirstBuffer();
while (buffer != null) {
//System.out.println("file = " + buffer.getFile());
if (buffer.getName().endsWith(".java")) {
fileSet.add(buffer.getFile());
}
buffer = buffer.getNext();
}
}
List files = new ArrayList();
files.addAll(fileSet);
process(files);
}
// check all open buffers
List files = new ArrayList();
files.addAll(fileSet);
process(files);
}
// check all open buffers
// check directory recursively
// check directory recursively
public static void checkDirectoryRecursively(View view) {
instance.instanceCheckDirectoryRecursively(view);
}
public void instanceCheckDirectoryRecursively(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 recursively", 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, true));
}
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, true));
} 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);
@ -155,27 +163,27 @@ public class PMDJEditPlugin extends EditPlugin {
process(findFiles(browser.getDirectory(), true));
}
}
// check directory recursively
// check directory recursively
// clear error list
public static void clearErrorList() {
instance.instanceClearErrorList();
}
// clear error list
public static void clearErrorList() {
instance.instanceClearErrorList();
}
public void instanceClearErrorList() {
errorSource.clear();
errorSource.clear();
}
// clear error list
// clear error list
private void process(final List files) {
new Thread(new Runnable () {
public void run() {
processFiles(files);
}
}).start();
public void run() {
processFiles(files);
}
}).start();
}
// check current buffer
// check current buffer
public static void check(Buffer buffer, View view) {
instance.instanceCheck(buffer, view);
}
@ -258,10 +266,10 @@ public class PMDJEditPlugin extends EditPlugin {
public static void CPDCurrentFile(View view) throws IOException
{
/* if(!view.getBuffer().getMode().getName().equals("java"))
{
{
JOptionPane.showMessageDialog(view,"Copy/Paste detection can only be performed on Java code.","Copy/Paste Detector",JOptionPane.INFORMATION_MESSAGE);
return;
} */
} */
instance.errorSource.clear();
CPD cpd = null;
//Log.log(Log.DEBUG, PMDJEditPlugin.class , "See mode " + view.getBuffer().getMode().getName());
@ -270,17 +278,17 @@ public class PMDJEditPlugin extends EditPlugin {
if (modeName.equals("java"))
{
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing java");
cpd = new CPD(jEdit.getIntegerProperty("pmd.cpd.defMinTileSize",100),new JavaLanguage());
cpd = new CPD(jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100),new JavaLanguage());
}
else if (modeName.equals("php"))
{
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing PHP");
cpd = new CPD(jEdit.getIntegerProperty("pmd.cpd.defMinTileSize",100),new PHPLanguage());
cpd = new CPD(jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100),new PHPLanguage());
}
else if (modeName.equals("c") || modeName.equals("c++"))
{
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing C/C++");
cpd = new CPD(jEdit.getIntegerProperty("pmd.cpd.defMinTileSize",100),new CPPLanguage());
cpd = new CPD(jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100),new CPPLanguage());
}
else
{
@ -331,7 +339,7 @@ public class PMDJEditPlugin extends EditPlugin {
catch(NumberFormatException e)
{
//use the default.
tilesize = jEdit.getIntegerProperty("pmd.cpd.defMinTileSize",100);
tilesize = jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100);
}
CPD cpd = new CPD(tilesize, new JavaLanguage());