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"
|
id="pmdPopupMenus"
|
||||||
name="PMD Popup Menus"
|
name="PMD Popup Menus"
|
||||||
point="org.eclipse.ui.popupMenus">
|
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
|
<objectContribution
|
||||||
objectClass="org.eclipse.core.resources.IProject"
|
objectClass="org.eclipse.core.resources.IProject"
|
||||||
adaptable="true"
|
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.runtime.cmd.ReviewCodeCmd;
|
||||||
import net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord;
|
import net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord;
|
||||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||||
|
import org.eclipse.ui.IWorkingSet;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
@ -136,39 +137,50 @@ public class PMDCheckAction extends AbstractUIAction {
|
|||||||
*
|
*
|
||||||
* @param selection the selected resources
|
* @param selection the selected resources
|
||||||
*/
|
*/
|
||||||
private void reviewSelectedResources(IStructuredSelection selection) throws CommandException {
|
private void reviewSelectedResources(IStructuredSelection selection)
|
||||||
ReviewCodeCmd cmd = new ReviewCodeCmd();
|
throws CommandException {
|
||||||
|
ReviewCodeCmd cmd = new ReviewCodeCmd();
|
||||||
|
|
||||||
// Add selected resources to the list of resources to be reviewed
|
// Add selected resources to the list of resources to be reviewed
|
||||||
for (Iterator<?> i = selection.iterator(); i.hasNext();) {
|
for (Iterator<?> i = selection.iterator(); i.hasNext();) {
|
||||||
Object element = i.next();
|
Object element = i.next();
|
||||||
if (element instanceof AbstractPMDRecord) {
|
if (element instanceof AbstractPMDRecord) {
|
||||||
final IResource resource = ((AbstractPMDRecord) element).getResource();
|
final IResource resource = ((AbstractPMDRecord) element)
|
||||||
if (resource != null) {
|
.getResource();
|
||||||
cmd.addResource(resource);
|
if (resource != null) {
|
||||||
} else {
|
cmd.addResource(resource);
|
||||||
log.warn("The selected object has no resource");
|
} else {
|
||||||
log.debug(" -> selected object : " + element);
|
log.warn("The selected object has no resource");
|
||||||
}
|
log.debug(" -> selected object : " + element);
|
||||||
} else if (element instanceof IAdaptable) {
|
}
|
||||||
IAdaptable adaptable = (IAdaptable) element;
|
} else if (element instanceof IWorkingSet) {
|
||||||
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
|
IWorkingSet set = (IWorkingSet) element;
|
||||||
if (resource != null) {
|
for (IAdaptable adaptable : set.getElements()) {
|
||||||
cmd.addResource(resource);
|
addAdaptable(cmd, adaptable);
|
||||||
} else {
|
}
|
||||||
log.warn("The selected object cannot adapt to a resource");
|
} else if (element instanceof IAdaptable) {
|
||||||
log.debug(" -> selected object : " + element);
|
IAdaptable adaptable = (IAdaptable) element;
|
||||||
}
|
addAdaptable(cmd, adaptable);
|
||||||
} else {
|
} else {
|
||||||
log.warn("The selected object is not adaptable");
|
log.warn("The selected object is not adaptable");
|
||||||
log.debug(" -> selected object : " + element);
|
log.debug(" -> selected object : " + element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the command
|
// Run the command
|
||||||
setupAndExecute(cmd, countElement(selection));
|
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
|
* Count the number of resources of a selection
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user