Support for checking code from working set selections. Contribution from Dominic:
http://sourceforge.net/tracker/?func=detail&atid=479923&aid=3137280&group_id=56262 git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7302 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -226,6 +226,29 @@
|
||||
id="pmdPopupMenus"
|
||||
name="PMD Popup Menus"
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<objectContribution
|
||||
objectClass="org.eclipse.ui.IWorkingSet"
|
||||
adaptable="true"
|
||||
nameFilter="*"
|
||||
id="net.sourceforge.pmd.eclipse.ui.pmdWorkingSetContribution">
|
||||
<menu
|
||||
label="%menu.pmd"
|
||||
icon="icons/pmd-icon-16.gif"
|
||||
path="additions"
|
||||
id="pmd.menu">
|
||||
<separator
|
||||
name="group">
|
||||
</separator>
|
||||
</menu>
|
||||
<action
|
||||
label="%action.checkpmd"
|
||||
icon="icons/icon_run.gif"
|
||||
class="net.sourceforge.pmd.eclipse.ui.actions.PMDCheckAction"
|
||||
menubarPath="pmd.menu/group"
|
||||
enablesFor="+"
|
||||
id="net.sourceforge.pmd.eclipse.ui.pmdPopupCheckWorkingSetAction">
|
||||
</action>
|
||||
</objectContribution>
|
||||
<objectContribution
|
||||
objectClass="org.eclipse.core.resources.IProject"
|
||||
adaptable="true"
|
||||
|
@ -41,6 +41,7 @@ import net.sourceforge.pmd.eclipse.runtime.cmd.AbstractDefaultCommand;
|
||||
import net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd;
|
||||
import net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord;
|
||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@ -136,39 +137,50 @@ public class PMDCheckAction extends AbstractUIAction {
|
||||
*
|
||||
* @param selection the selected resources
|
||||
*/
|
||||
private void reviewSelectedResources(IStructuredSelection selection) throws CommandException {
|
||||
ReviewCodeCmd cmd = new ReviewCodeCmd();
|
||||
private void reviewSelectedResources(IStructuredSelection selection)
|
||||
throws CommandException {
|
||||
ReviewCodeCmd cmd = new ReviewCodeCmd();
|
||||
|
||||
// Add selected resources to the list of resources to be reviewed
|
||||
for (Iterator<?> i = selection.iterator(); i.hasNext();) {
|
||||
Object element = i.next();
|
||||
if (element instanceof AbstractPMDRecord) {
|
||||
final IResource resource = ((AbstractPMDRecord) element).getResource();
|
||||
if (resource != null) {
|
||||
cmd.addResource(resource);
|
||||
} else {
|
||||
log.warn("The selected object has no resource");
|
||||
log.debug(" -> selected object : " + element);
|
||||
}
|
||||
} else if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable = (IAdaptable) element;
|
||||
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
|
||||
if (resource != null) {
|
||||
cmd.addResource(resource);
|
||||
} else {
|
||||
log.warn("The selected object cannot adapt to a resource");
|
||||
log.debug(" -> selected object : " + element);
|
||||
}
|
||||
} else {
|
||||
log.warn("The selected object is not adaptable");
|
||||
log.debug(" -> selected object : " + element);
|
||||
}
|
||||
}
|
||||
// Add selected resources to the list of resources to be reviewed
|
||||
for (Iterator<?> i = selection.iterator(); i.hasNext();) {
|
||||
Object element = i.next();
|
||||
if (element instanceof AbstractPMDRecord) {
|
||||
final IResource resource = ((AbstractPMDRecord) element)
|
||||
.getResource();
|
||||
if (resource != null) {
|
||||
cmd.addResource(resource);
|
||||
} else {
|
||||
log.warn("The selected object has no resource");
|
||||
log.debug(" -> selected object : " + element);
|
||||
}
|
||||
} else if (element instanceof IWorkingSet) {
|
||||
IWorkingSet set = (IWorkingSet) element;
|
||||
for (IAdaptable adaptable : set.getElements()) {
|
||||
addAdaptable(cmd, adaptable);
|
||||
}
|
||||
} else if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable = (IAdaptable) element;
|
||||
addAdaptable(cmd, adaptable);
|
||||
} else {
|
||||
log.warn("The selected object is not adaptable");
|
||||
log.debug(" -> selected object : " + element);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the command
|
||||
setupAndExecute(cmd, countElement(selection));
|
||||
}
|
||||
// Run the command
|
||||
setupAndExecute(cmd, countElement(selection));
|
||||
}
|
||||
|
||||
private void addAdaptable(ReviewCodeCmd cmd, IAdaptable adaptable) {
|
||||
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
|
||||
if (resource != null) {
|
||||
cmd.addResource(resource);
|
||||
} else {
|
||||
log.warn("The selected object cannot adapt to a resource");
|
||||
log.debug(" -> selected object : " + adaptable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of resources of a selection
|
||||
*
|
||||
|
Reference in New Issue
Block a user