Search in sources :

Example 6 with AbstractPMDRecord

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

the class ViolationOverviewMenuManager method createProjectFilterMenu.

/**
 * Create the Menu for filtering Projects
 *
 * @param manager, the MenuManager
 */
private void createProjectFilterMenu(IMenuManager manager) {
    final List<AbstractPMDRecord> projectFilterList = this.overview.getProjectFilterList();
    final List<ProjectRecord> projectList = new ArrayList<ProjectRecord>();
    // We get a List of all Projects
    final AbstractPMDRecord[] projects = this.overview.getAllProjects();
    for (int i = 0; i < projects.length; i++) {
        final ProjectRecord project = (ProjectRecord) projects[i];
        // we add a FilterAction for it
        if (project.hasMarkers()) {
            // NOPMD by Herlin on 09/10/06 15:03
            final Action projectFilterAction = new ProjectFilterAction(project, this.overview);
            // we set it as "visible"
            if (!projectFilterList.contains(projects[i])) {
                // NOPMD by Herlin on 09/10/06 15:04
                projectFilterAction.setChecked(true);
            }
            manager.add(projectFilterAction);
            projectList.add(project);
        }
    }
    manager.add(new Separator());
}
Also used : ProjectFilterAction(net.sourceforge.pmd.eclipse.ui.views.actions.ProjectFilterAction) CalculateStatisticsAction(net.sourceforge.pmd.eclipse.ui.views.actions.CalculateStatisticsAction) PriorityFilterAction(net.sourceforge.pmd.eclipse.ui.views.actions.PriorityFilterAction) Action(org.eclipse.jface.action.Action) ProjectFilterAction(net.sourceforge.pmd.eclipse.ui.views.actions.ProjectFilterAction) ViolationPresentationTypeAction(net.sourceforge.pmd.eclipse.ui.views.actions.ViolationPresentationTypeAction) CollapseAllAction(net.sourceforge.pmd.eclipse.ui.views.actions.CollapseAllAction) ProjectRecord(net.sourceforge.pmd.eclipse.ui.model.ProjectRecord) ArrayList(java.util.ArrayList) Separator(org.eclipse.jface.action.Separator) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 7 with AbstractPMDRecord

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

the class ChangeEvaluator method changeRecordFor.

public ChangeRecord<AbstractPMDRecord> changeRecordFor(IResourceChangeEvent event) {
    List<IMarkerDelta> markerDeltas = MarkerUtil.markerDeltasIn(event);
    // first we get a List of changes to Files and Projects so we won't be
    // updating everything
    List<IResource> changedFiles = new ArrayList<IResource>();
    List<IProject> changedProjects = new ArrayList<IProject>();
    for (IMarkerDelta markerDelta : markerDeltas) {
        IResource resource = markerDelta.getResource();
        IProject project = resource.getProject();
        // the lists should not contain Projects or Resources twice
        if (!changedFiles.contains(resource)) {
            changedFiles.add(resource);
        // LOG.debug("Resource " + resource.getName() + " has changed");
        }
        if (!changedProjects.contains(project)) {
            changedProjects.add(project);
        // LOG.debug("Project " + project.getName() + " has changed");
        }
    }
    // we can add, change, or remove Resources
    // all the changes are given to the viewer later
    ChangeRecord<AbstractPMDRecord> changeRec = new ChangeRecord<AbstractPMDRecord>();
    // we go through the changed Projects
    for (IProject project : changedProjects) {
        // LOG.debug("Processing changes for project " + project.getName());
        ProjectRecord projectRec = (ProjectRecord) root.findResource(project);
        // Model and go on
        if (!(project.isOpen() && project.isAccessible())) {
            // LOG.debug("The project is not open or not accessible. Remove
            // it");
            List<AbstractPMDRecord>[] array = updateFiles(project, changedFiles);
            changeRec.removed(array[1]);
            root.removeResource(project);
        } else if (projectRec == null) {
            // if we couldn't find the Project then it has to be new
            // LOG.debug("Cannot find a project record for it. Add it.");
            projectRec = (ProjectRecord) root.addResource(project);
        }
        // then we can update the Files for the new or updated Project
        List<AbstractPMDRecord>[] array = updateFiles(project, changedFiles);
        changeRec.added(array[0]);
        changeRec.removed(array[1]);
        changeRec.changed(array[2]);
    }
    return changeRec;
}
Also used : ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord) ProjectRecord(net.sourceforge.pmd.eclipse.ui.model.ProjectRecord) List(java.util.List) ArrayList(java.util.ArrayList) IMarkerDelta(org.eclipse.core.resources.IMarkerDelta) IResource(org.eclipse.core.resources.IResource)

Example 8 with AbstractPMDRecord

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

the class ChangeEvaluator method searchProjectForModifications.

/**
 * Analyzes the modification inside a single project and compute the list of
 * additions, updates and removals.
 *
 * @param projectRec
 * @param changedFiles
 * @return
 */
private static List<AbstractPMDRecord>[] searchProjectForModifications(ProjectRecord projectRec, List<IResource> changedFiles) {
    // TODO use ChangeRecord
    List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord> changes = new ArrayList<AbstractPMDRecord>();
    IProject project = (IProject) projectRec.getResource();
    for (IResource resource : changedFiles) {
        // ... and first check, if the project is the right one
        if (project.equals(resource.getProject())) {
            AbstractPMDRecord rec = projectRec.findResource(resource);
            if (rec != null && rec.getResourceType() == IResource.FILE) {
                FileRecord fileRec = (FileRecord) rec;
                fileRec.updateChildren();
                if (fileRec.getResource().isAccessible() && fileRec.hasMarkers()) {
                    // LOG.debug("The file has changed");
                    changes.add(fileRec);
                } else {
                    // LOG.debug("The file has been removed");
                    projectRec.removeResource(fileRec.getResource());
                    removals.add(fileRec);
                    // remove parent if no more markers
                    if (!fileRec.getParent().hasMarkers()) {
                        projectRec.removeResource(fileRec.getParent().getResource());
                        removals.add(fileRec.getParent());
                    }
                }
            } else if (rec == null) {
                // LOG.debug("This is a new file.");
                AbstractPMDRecord fileRec = projectRec.addResource(resource);
                additions.add(fileRec);
            } else {
            // LOG.debug("The resource found is not a file! type found :
            // " + rec.getResourceType());
            }
        } else {
        // LOG.debug("The project resource is not the same! (" +
        // resource.getProject().getName() + ')');
        }
    }
    return new List[] { additions, removals, changes };
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 9 with AbstractPMDRecord

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

the class ChangeEvaluator method updateFiles.

/**
 * Updates the Files for a given Project
 *
 * @param project
 * @param changedFiles,
 *            a List of all changed Files
 * @return an List of Lists containing additions [0], removals [1] and
 *         changes [2] (Array-Position in Brackets)
 */
private List<AbstractPMDRecord>[] updateFiles(IProject project, List<IResource> changedFiles) {
    // TODO use ChangeRecord
    List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord> changes = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord>[] updatedFiles = new List[] { additions, removals, changes };
    // we search for the ProjectRecord to the Project
    // if it doesn't exist, we return nothing
    ProjectRecord projectRec = (ProjectRecord) root.findResource(project);
    // we got through all files
    if (projectRec != null && project.isAccessible()) {
        updatedFiles = searchProjectForModifications(projectRec, changedFiles);
    } else if (projectRec != null) {
        // if the project is deleted or closed
        List<AbstractPMDRecord> packages = projectRec.getChildrenAsList();
        // ... we add all Packages to the removals so they are not shown
        // anymore
        removals.addAll(packages);
        for (int k = 0; k < packages.size(); k++) {
            PackageRecord packageRec = (PackageRecord) packages.get(k);
            removals.addAll(packageRec.getChildrenAsList());
        }
        updatedFiles = new List[] { additions, removals, changes };
    }
    return updatedFiles;
}
Also used : ArrayList(java.util.ArrayList) ProjectRecord(net.sourceforge.pmd.eclipse.ui.model.ProjectRecord) List(java.util.List) ArrayList(java.util.ArrayList) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 10 with AbstractPMDRecord

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

the class MarkerUtil method allMarkedFiles.

public static Set<IFile> allMarkedFiles(RootRecord root) {
    gatherRuleNames();
    Set<IFile> files = new HashSet<IFile>();
    for (AbstractPMDRecord projectRecord : root.getChildren()) {
        for (AbstractPMDRecord packageRecord : projectRecord.getChildren()) {
            for (AbstractPMDRecord fileRecord : packageRecord.getChildren()) {
                ((FileRecord) fileRecord).updateChildren();
                for (AbstractPMDRecord mRecord : fileRecord.getChildren()) {
                    MarkerRecord markerRecord = (MarkerRecord) mRecord;
                    for (IMarker marker : markerRecord.findMarkers()) {
                        Rule rule = ruleFrom(marker);
                        if (rule == null) {
                            continue;
                        }
                        files.add((IFile) fileRecord.getResource());
                        break;
                    }
                }
            }
        }
    }
    return files;
}
Also used : IFile(org.eclipse.core.resources.IFile) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) IMarker(org.eclipse.core.resources.IMarker) Rule(net.sourceforge.pmd.Rule) HashSet(java.util.HashSet) 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