use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.
the class PMDCheckAction method reviewSelectedResources.
/**
* Prepare and run the reviewCode command for all selected resources
*
* @param selection
* the selected resources
*/
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) {
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, countElements(selection));
}
use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.
the class ReviewCodeHandler method execute.
// /**
// * Collects the files out of the given resources.
// *
// * @param resources the resources from which to get the files
// * @return an array of files
// */
// protected static IFile[] collectFiles(IResource[] resources) {
//
// Set<IFile> files= new HashSet<IFile>();
// for (int i= 0; i < resources.length; i++) {
// IResource resource= resources[i];
// if ((IResource.FILE & resource.getType()) > 0)
// files.add((IFile)resource);
// }
// return (IFile[]) files.toArray(new IFile[files.size()]);
// }
public Object execute(ExecutionEvent event) throws ExecutionException {
computeSelectedResources();
try {
if (fResources != null && fResources.length > 0) {
// separate one for each thread
ReviewCodeCmd cmd = new ReviewCodeCmd();
cmd.reset();
for (IResource rsc : fResources) {
cmd.addResource(rsc);
}
try {
cmd.performExecute();
} catch (CommandException e) {
PMDPlugin.getDefault().log(IStatus.ERROR, "Error processing user-initiated code review", e);
}
}
// Standard return value. DO NOT CHANGE.
return null;
} finally {
fResources = null;
fLocation = null;
}
}
Aggregations