Search in sources :

Example 11 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord 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 12 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class PMDRemoveMarkersAction method processElement.

private void processElement(Object element) throws CoreException {
    if (element instanceof AbstractPMDRecord) {
        final AbstractPMDRecord record = (AbstractPMDRecord) element;
        final IResource resource = record.getResource();
        if (isViolationOverview()) {
            ((ViolationOverview) targetPart()).deleteMarkers(record);
        }
        LOG.debug("Remove markers on resource " + resource.getName());
    } else if (element instanceof IAdaptable) {
        final IAdaptable adaptable = (IAdaptable) element;
        final IResource resource = (IResource) adaptable.getAdapter(IResource.class);
        if (resource == null) {
            LOG.warn("The selected object cannot adapt to a resource");
            LOG.debug("   -> selected object : " + element);
        } else {
            MarkerUtil.deleteAllMarkersIn(resource);
            LOG.debug("Remove markers on resrouce " + resource.getName());
        }
    } else {
        LOG.warn("The selected object is not adaptable");
        LOG.debug("   -> selected object : " + element);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ViolationOverview(net.sourceforge.pmd.eclipse.ui.views.ViolationOverview) IResource(org.eclipse.core.resources.IResource) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 13 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverview method rememberFilterSettings.

/**
 * Apply the memento for filters. Before calling this private method, one
 * must be sure memento is not null.
 */
private void rememberFilterSettings() {
    // Provide the Filters with their last State
    List<Integer> priorityList = memento.getIntegerList(PRIORITY_LIST);
    if (!priorityList.isEmpty()) {
        priorityFilter.setPriorityFilterList(priorityList);
    }
    List<String> projectNames = memento.getStringList(PROJECT_LIST);
    if (!projectNames.isEmpty()) {
        List<AbstractPMDRecord> projectList = new ArrayList<AbstractPMDRecord>();
        for (int k = 0; k < projectNames.size(); k++) {
            AbstractPMDRecord project = root.findResourceByName(projectNames.get(k), AbstractPMDRecord.TYPE_PROJECT);
            if (project != null) {
                projectList.add(project);
            }
        }
        projectFilter.setProjectFilterList(projectList);
    }
    Integer type = memento.getInteger(PACKAGE_SWITCH);
    if (type != null) {
        setShowType(type.intValue());
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 14 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverviewContentProvider method getChildrenOfRoot.

/**
 * Gets the children of the root depending on the show type.
 *
 * @return children
 */
private Object[] getChildrenOfRoot() {
    // ... we care about its Project's
    List<AbstractPMDRecord> projects = root.getChildrenAsList();
    ProjectRecord[] projectArray = new ProjectRecord[projects.size()];
    projects.toArray(projectArray);
    // we make a List of all Packages
    List<AbstractPMDRecord> packages = new ArrayList<AbstractPMDRecord>();
    for (ProjectRecord element : projectArray) {
        if (element.isProjectOpen()) {
            packages.addAll(element.getChildrenAsList());
        }
    }
    switch(violationView.getShowType()) {
        case ViolationOverview.SHOW_MARKERS_FILES:
        case ViolationOverview.SHOW_PACKAGES_FILES_MARKERS:
            // show packages
            return packages.toArray();
        case ViolationOverview.SHOW_FILES_MARKERS:
            // show files
            List<AbstractPMDRecord> files = new ArrayList<AbstractPMDRecord>();
            for (AbstractPMDRecord packageRec : packages) {
                files.addAll(packageRec.getChildrenAsList());
            }
            return files.toArray();
        default:
    }
    return Util.EMPTY_ARRAY;
}
Also used : ProjectRecord(net.sourceforge.pmd.eclipse.ui.model.ProjectRecord) ArrayList(java.util.ArrayList) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 15 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverviewContentProvider method getParent.

/**
 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
 */
public Object getParent(Object element) {
    Object parent = null;
    AbstractPMDRecord record = (AbstractPMDRecord) element;
    switch(violationView.getShowType()) {
        case ViolationOverview.SHOW_FILES_MARKERS:
            if (element instanceof FileRecord) {
                parent = root;
            } else {
                parent = record.getParent();
            }
            break;
        case ViolationOverview.SHOW_MARKERS_FILES:
            if (element instanceof FileToMarkerRecord) {
                parent = record.getParent();
            } else if (element instanceof PackageRecord) {
                parent = root;
            } else if (element instanceof MarkerRecord) {
                parent = record.getParent().getParent();
            }
            break;
        case ViolationOverview.SHOW_PACKAGES_FILES_MARKERS:
            if (element instanceof PackageRecord) {
                parent = root;
            } else {
                parent = record.getParent();
            }
            break;
        default:
    }
    return parent;
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Aggregations

AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)19 FileRecord (net.sourceforge.pmd.eclipse.ui.model.FileRecord)8 ArrayList (java.util.ArrayList)7 PackageRecord (net.sourceforge.pmd.eclipse.ui.model.PackageRecord)7 MarkerRecord (net.sourceforge.pmd.eclipse.ui.model.MarkerRecord)5 ProjectRecord (net.sourceforge.pmd.eclipse.ui.model.ProjectRecord)4 IResource (org.eclipse.core.resources.IResource)4 List (java.util.List)3 FileToMarkerRecord (net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)3 IMarker (org.eclipse.core.resources.IMarker)2 IProject (org.eclipse.core.resources.IProject)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Rule (net.sourceforge.pmd.Rule)1 ReviewCodeCmd (net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)1 ViolationOverview (net.sourceforge.pmd.eclipse.ui.views.ViolationOverview)1 CalculateStatisticsAction (net.sourceforge.pmd.eclipse.ui.views.actions.CalculateStatisticsAction)1 CollapseAllAction (net.sourceforge.pmd.eclipse.ui.views.actions.CollapseAllAction)1