Search in sources :

Example 1 with MarkerRecord

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

the class ViolationOverview method deleteMarkers.

/**
 * Deletes markers of an AbstractPMDRecord. This is performed after the
 * action Clear PMD Markers of the contextmenu was called.
 *
 * @param element
 * @throws CoreException
 */
public void deleteMarkers(AbstractPMDRecord element) throws CoreException {
    if (element instanceof MarkerRecord) {
        MarkerRecord record = (MarkerRecord) element;
        IMarker[] markers = MarkerUtil.EMPTY_MARKERS;
        switch(getShowType()) {
            case SHOW_PACKAGES_FILES_MARKERS:
            case SHOW_FILES_MARKERS:
                // simply get the markers of the marker record
                markers = record.findMarkers();
                break;
            case SHOW_MARKERS_FILES:
                AbstractPMDRecord packRec = record.getParent().getParent();
                markers = packRec.findMarkersByAttribute(PMDUiConstants.KEY_MARKERATT_RULENAME, record.getName());
                break;
            default:
        }
        deleteMarkers(markers);
    } else if (element instanceof FileToMarkerRecord) {
        FileToMarkerRecord record = (FileToMarkerRecord) element;
        IMarker[] markers = record.findMarkers();
        deleteMarkers(markers);
    } else {
        // simply delete markers from resource
        MarkerUtil.deleteAllMarkersIn(element.getResource());
    }
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) IMarker(org.eclipse.core.resources.IMarker) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 2 with MarkerRecord

use of net.sourceforge.pmd.eclipse.ui.model.MarkerRecord 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)

Example 3 with MarkerRecord

use of net.sourceforge.pmd.eclipse.ui.model.MarkerRecord 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)

Example 4 with MarkerRecord

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

the class ViolationOverviewDoubleClickListener method doubleClick.

/**
 * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
 */
public void doubleClick(DoubleClickEvent event) {
    final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    final Object object = selection.getFirstElement();
    if (object instanceof PackageRecord) {
        doubleClickToPackageRecord((PackageRecord) object);
    } else if (object instanceof FileRecord) {
        doubleClickToFileRecord((FileRecord) object);
    } else if (object instanceof MarkerRecord) {
        doubleClickToMarkerRecord((MarkerRecord) object);
    } else if (object instanceof FileToMarkerRecord) {
        doubleClickToFileToMarkerRecord((FileToMarkerRecord) object);
    }
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)

Example 5 with MarkerRecord

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

the class ViolationOverviewLabelProvider method getProjectName.

/**
 * Return the project name.
 *
 * @param element
 * @return
 */
private String getProjectName(Object element) {
    String projectName = "";
    AbstractPMDRecord projectRec = null;
    if (element instanceof PackageRecord) {
        projectRec = ((PackageRecord) element).getParent();
    } else if (element instanceof FileRecord) {
        projectRec = ((FileRecord) element).getParent().getParent();
    } else if (element instanceof MarkerRecord) {
        projectRec = ((MarkerRecord) element).getParent().getParent().getParent();
    } else if (element instanceof FileToMarkerRecord) {
        projectRec = ((FileToMarkerRecord) element).getParent().getParent().getParent().getParent();
    }
    if (projectRec != null) {
        projectName = projectRec.getName();
    }
    return projectName;
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Aggregations

MarkerRecord (net.sourceforge.pmd.eclipse.ui.model.MarkerRecord)8 FileRecord (net.sourceforge.pmd.eclipse.ui.model.FileRecord)7 FileToMarkerRecord (net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)6 PackageRecord (net.sourceforge.pmd.eclipse.ui.model.PackageRecord)6 AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)5 IMarker (org.eclipse.core.resources.IMarker)3 HashSet (java.util.HashSet)1 Rule (net.sourceforge.pmd.Rule)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Image (org.eclipse.swt.graphics.Image)1