Search in sources :

Example 6 with ReviewCodeCmd

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));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 7 with ReviewCodeCmd

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;
    }
}
Also used : ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) CommandException(name.herlin.command.CommandException) IResource(org.eclipse.core.resources.IResource)

Aggregations

ReviewCodeCmd (net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)7 CommandException (name.herlin.command.CommandException)3 IResource (org.eclipse.core.resources.IResource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)1 IProject (org.eclipse.core.resources.IProject)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1