Added ability to run PMD on a selected file
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@686 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
<name>pmd-eclipse</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>pmd</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<plugin
|
||||
id="net.sourceforge.pmd.eclipse"
|
||||
name="pmd-eclipse Plug-in"
|
||||
version="0.1.0"
|
||||
version="0.2.0"
|
||||
provider-name="PMD"
|
||||
class="net.sourceforge.pmd.eclipse.PMDPlugin">
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class PMDAction implements IWorkbenchWindowActionDelegate {
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
String[] rulesetFiles = PMDPlugin.getDefault().getRuleSetsPreference();
|
||||
|
||||
|
||||
PMDVisitor visitor = null;
|
||||
try {
|
||||
visitor = new PMDVisitor(rulesetFiles);
|
||||
|
@ -1,8 +1,12 @@
|
||||
package net.sourceforge.pmd.eclipse.actions;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
@ -23,7 +27,7 @@ public class PMDCheckFileAction implements IObjectActionDelegate {
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
this.targetPart = targetPart;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,21 +36,29 @@ public class PMDCheckFileAction implements IObjectActionDelegate {
|
||||
public void run(IAction action) {
|
||||
String[] rulesetFiles = PMDPlugin.getDefault().getRuleSetsPreference();
|
||||
|
||||
Shell shell = new Shell();
|
||||
|
||||
PMDVisitor visitor = null;
|
||||
try {
|
||||
visitor = new PMDVisitor(rulesetFiles);
|
||||
Object sel = targetPart.getSite().getSelectionProvider().getSelection();
|
||||
if (sel instanceof StructuredSelection) {
|
||||
StructuredSelection ss = (StructuredSelection)sel;
|
||||
for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
|
||||
Object obj = iter.next();
|
||||
if (obj instanceof IFile) {
|
||||
((IFile)obj).accept(visitor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
PMDPlugin.getWorkspace().getRoot().accept( visitor );
|
||||
//PMDPlugin.getWorkspace().getRoot().accept( visitor );
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Shell shell = new Shell();
|
||||
MessageDialog.openInformation(
|
||||
shell,
|
||||
"pmd-eclipse Plug-in",
|
||||
"PMD Check File was executed.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user