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));
}
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);
}
}
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());
}
}
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;
}
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;
}
Aggregations