diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/CHANGELOG.txt b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/CHANGELOG.txt index e349969cfb..8742c90ebc 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/CHANGELOG.txt +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/CHANGELOG.txt @@ -4,15 +4,18 @@ v4.0.0 - xxx 2011? . New integrated AST View and XPath test area . New rule creation wizard . New report preferences panel +. New file filter panel for exclusion/inclusion entries . User-definable rule violation markers Highest priority markers also decorate folders & projects (selectable) . Colour syntax highlighting in code viewers/editors +. Expanded rule import dialog to show incoming rules and any duplicates +. Export rule function now only exports selected rules . Overhauled rule preferences screen . allows users to group/edit rules by multiple criteria . new ability to enable/disable rules without removing them from rulesets . larger editors for the various fields . support for non-Java languages -. group editing of filter exclusion rules +. group editing of rule exclusion filters . highlighting of non-default property values . colour-tagged expressions in shown in rule table . new property editors are fully type-aware diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/messages.properties b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/messages.properties index c1e0d96ce0..f63227772b 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/messages.properties +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/messages.properties @@ -97,7 +97,7 @@ preference.ruleset.button.addrule = Add rule... preference.ruleset.button.removerule = Remove rule preference.ruleset.button.editrule = Edit rule... preference.ruleset.button.importruleset = Import rule set... -preference.ruleset.button.exportruleset = Export rule set... +preference.ruleset.button.exportruleset = Export selected rules... preference.ruleset.button.clearall = Clear all preference.ruleset.button.ruledesigner = Rule Designer preference.ruleset.button.addproperty = Add property... diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java index 02a7cd1aef..43e07652c9 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java @@ -46,6 +46,10 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; @@ -68,7 +72,7 @@ import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class PMDPlugin extends AbstractUIPlugin { +public class PMDPlugin extends AbstractUIPlugin implements IResourceChangeListener { private static File pluginFolder; @@ -170,16 +174,35 @@ public class PMDPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - configureLogs(loadPreferences()); + + IPreferences prefs = loadPreferences(); + configureLogs(prefs); registerStandardRuleSets(); registerAdditionalRuleSets(); + fileChangeListenerEnabled(prefs.isCheckAfterSaveEnabled()); } - + + + + public void fileChangeListenerEnabled(boolean flag) { + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + if (flag) { + workspace.addResourceChangeListener(this); + } else { + workspace.removeResourceChangeListener(this); + } + } + /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { + + fileChangeListenerEnabled(false); + plugin = null; disposeResources(); super.stop(context); @@ -541,5 +564,14 @@ public class PMDPlugin extends AbstractUIPlugin { decorator.changed(changes); } + public void resourceChanged(IResourceChangeEvent event) { + +// switch (event.getType()) { +// case PRE_DELETE: +// case POST_CHANGE: +// } + + } + } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/AbstractDefaultCommand.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/AbstractDefaultCommand.java index d0ba892221..f8bfdd5ee0 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/AbstractDefaultCommand.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/AbstractDefaultCommand.java @@ -38,6 +38,7 @@ package net.sourceforge.pmd.eclipse.runtime.cmd; import name.herlin.command.AbstractProcessableCommand; import name.herlin.command.CommandException; import net.sourceforge.pmd.eclipse.plugin.PMDPlugin; +import net.sourceforge.pmd.lang.Language; import org.apache.log4j.Logger; import org.eclipse.core.resources.IFile; @@ -70,11 +71,22 @@ public abstract class AbstractDefaultCommand extends AbstractProcessableCommand description = theDescription; } + /** + * + * @param file + * @return + * @deprecated we support multiple languages now + */ public static boolean isJavaFile(IFile file) { if (file == null) return false; return "JAVA".equalsIgnoreCase(file.getFileExtension()); } + public static boolean isLanguageFile(IFile file, Language language) { + if (file == null) return false; + return language.hasExtension(file.getFileExtension()); + } + /** * @return Returns the readOnly status. */ diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java index 0ad05f9b17..36a43f595c 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java @@ -74,7 +74,7 @@ public class BaseVisitor { private static final Logger log = Logger.getLogger(BaseVisitor.class); private IProgressMonitor monitor; private boolean useTaskMarker = false; - private Map> accumulator; + private Map> accumulator; // private PMDEngine pmdEngine; private RuleSet ruleSet; private int fileCount; @@ -123,7 +123,7 @@ public class BaseVisitor { * * @return Map */ - public Map> getAccumulator() { + public Map> getAccumulator() { return accumulator; } @@ -133,7 +133,7 @@ public class BaseVisitor { * @param accumulator * The accumulator to set */ - public void setAccumulator(final Map> accumulator) { + public void setAccumulator(final Map> accumulator) { this.accumulator = accumulator; } @@ -245,69 +245,65 @@ public class BaseVisitor { * @param resource * the resource to process */ - protected final void reviewResource(final IResource resource) { - IFile file = (IFile) resource.getAdapter(IFile.class); - if (file != null && file.getFileExtension() != null) { - - Reader input = null; - try { - boolean included = isIncluded(file); - log.debug("Derived files included: " + projectProperties.isIncludeDerivedFiles()); - log.debug("file " + file.getName() + " is derived: " + file.isDerived()); - log.debug("file checked: " + included); + protected final void reviewResource(IResource resource) { - final File sourceCodeFile = file.getRawLocation().toFile(); - if (included && getRuleSet().applies(sourceCodeFile) && isFileInWorkingSet(file)) { - subTask("PMD checking: " + file.getName()); + IFile file = (IFile) resource.getAdapter(IFile.class); + if (file == null || file.getFileExtension() == null) return; - LanguageVersion version = PMDPlugin.javaVersionFor(file.getProject()); - if (version != null) configuration().setDefaultLanguageVersion(version); - - Timer timer = new Timer(); + Reader input = null; + try { + boolean included = isIncluded(file); + log.debug("Derived files included: " + projectProperties.isIncludeDerivedFiles()); + log.debug("file " + file.getName() + " is derived: " + file.isDerived()); + log.debug("file checked: " + included); - RuleContext context = PMD.newRuleContext(file.getName(), sourceCodeFile); + final File sourceCodeFile = file.getRawLocation().toFile(); + if (included && getRuleSet().applies(sourceCodeFile) && isFileInWorkingSet(file)) { + subTask("PMD checking: " + file.getName()); - input = new InputStreamReader(file.getContents(), file.getCharset()); -// getPmdEngine().processFile(input, getRuleSet(), context); -// getPmdEngine().processFile(sourceCodeFile, getRuleSet(), context); + setLanguageVersion(file); - RuleSets rSets = new RuleSets(getRuleSet()); - new SourceCodeProcessor(configuration()).processSourceCode(input, rSets, context); + Timer timer = new Timer(); - timer.stop(); - pmdDuration += timer.getDuration(); + RuleContext context = PMD.newRuleContext(file.getName(), sourceCodeFile); - updateMarkers(file, context, isUseTaskMarker(), getAccumulator()); + input = new InputStreamReader(file.getContents(), file.getCharset()); + // getPmdEngine().processFile(input, getRuleSet(), context); + // getPmdEngine().processFile(sourceCodeFile, getRuleSet(), context); - worked(1); - fileCount++; - } else { - log.debug("The file " + file.getName() + " is not in the working set"); - } + RuleSets rSets = new RuleSets(getRuleSet()); + new SourceCodeProcessor(configuration()).processSourceCode(input, rSets, context); - } catch (CoreException e) { - log.error("Core exception visiting " + file.getName(), e); // TODO: - // complete - // message - } catch (PMDException e) { - log.error("PMD exception visiting " + file.getName(), e); // TODO: - // complete - // message - } catch (IOException e) { - log.error("IO exception visiting " + file.getName(), e); // TODO: - // complete - // message - } catch (PropertiesException e) { - log.error("Properties exception visiting " + file.getName(), e); // TODO: - // complete - // message - } finally { - IOUtil.closeQuietly(input); - } + timer.stop(); + pmdDuration += timer.getDuration(); + + updateMarkers(file, context, isUseTaskMarker(), getAccumulator()); + + worked(1); + fileCount++; + } else { + log.debug("The file " + file.getName() + " is not in the working set"); + } + + } catch (CoreException e) { + log.error("Core exception visiting " + file.getName(), e); // TODO: // complete message + } catch (PMDException e) { + log.error("PMD exception visiting " + file.getName(), e); // TODO: // complete message + } catch (IOException e) { + log.error("IO exception visiting " + file.getName(), e); // TODO: // complete message + } catch (PropertiesException e) { + log.error("Properties exception visiting " + file.getName(), e); // TODO: // complete message + } finally { + IOUtil.closeQuietly(input); + } - } } + private void setLanguageVersion(IFile file) { + LanguageVersion version = PMDPlugin.javaVersionFor(file.getProject()); + if (version != null) configuration().setDefaultLanguageVersion(version); + } + /** * Test if a file is in the PMD working set * @@ -360,15 +356,16 @@ public class BaseVisitor { } } - private void updateMarkers(final IFile file, final RuleContext context, final boolean fTask, final Map> accumulator) + private void updateMarkers(IFile file, RuleContext context, boolean fTask, Map> accumulator) throws CoreException, PropertiesException { - final Set markerSet = new HashSet(); - final List reviewsList = findReviewedViolations(file); - final Review review = new Review(); - final Iterator iter = context.getReport().iterator(); + + Set markerSet = new HashSet(); + List reviewsList = findReviewedViolations(file); + Review review = new Review(); + Iterator iter = context.getReport().iterator(); // final IPreferences preferences = PMDPlugin.getDefault().loadPreferences(); // final int maxViolationsPerFilePerRule = preferences.getMaxViolationsPerFilePerRule(); - final Map violationsByRule = new HashMap(); + Map violationsByRule = new HashMap(); Rule rule = null; while (iter.hasNext()) { @@ -379,35 +376,37 @@ public class BaseVisitor { if (reviewsList.contains(review)) { log.debug("Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine() + " because of a review."); - } else { - Integer count = violationsByRule.get(rule); - if (count == null) { - count = NumericConstants.ZERO; - violationsByRule.put(rule, count); + continue; + } + + Integer count = violationsByRule.get(rule); + if (count == null) { + count = NumericConstants.ZERO; + violationsByRule.put(rule, count); } - int maxViolations = maxAllowableViolationsFor(rule); + int maxViolations = maxAllowableViolationsFor(rule); - if (count.intValue() < maxViolations) { - // Ryan Gustafson 02/16/2008 - Always use PMD_MARKER, as people get confused as to why PMD problems don't always show up on Problems view like they do when you do build. - // markerSet.add(getMarkerInfo(violation, fTask ? PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); - markerSet.add(getMarkerInfo(violation, markerTypeFor(violation))); - /* - if (isDfaEnabled && violation.getRule().usesDFA()) { - markerSet.add(getMarkerInfo(violation, PMDRuntimeConstants.PMD_DFA_MARKER)); - } else { + if (count.intValue() < maxViolations) { + // Ryan Gustafson 02/16/2008 - Always use PMD_MARKER, as people get confused as to why PMD problems don't always show up on Problems view like they do when you do build. + // markerSet.add(getMarkerInfo(violation, fTask ? PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); + markerSet.add( + getMarkerInfo(violation, markerTypeFor(violation)) + ); + /* + if (isDfaEnabled && violation.getRule().usesDFA()) { + markerSet.add(getMarkerInfo(violation, PMDRuntimeConstants.PMD_DFA_MARKER)); + } else { markerSet.add(getMarkerInfo(violation, fTask ? PMDRuntimeConstants.PMD_TASKMARKER : PMDRuntimeConstants.PMD_MARKER)); - } + } */ - violationsByRule.put(rule, Integer.valueOf(count.intValue() + 1)); + violationsByRule.put(rule, Integer.valueOf(count.intValue() + 1)); - log.debug("Adding a violation for rule " + rule.getName() + " at line " + violation.getBeginLine()); + log.debug("Adding a violation for rule " + rule.getName() + " at line " + violation.getBeginLine()); } else { log.debug("Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine() + " because maximum violations has been reached for file " + file.getName()); } - - } } if (accumulator != null) { @@ -477,75 +476,47 @@ public class BaseVisitor { return reviews; } - /** - * Create a marker info object from a violation - * - * @param violation - * a PMD violation - * @param type - * a marker type - * @return markerInfo a markerInfo object - */ - private MarkerInfo getMarkerInfo(final RuleViolation violation, final String type) throws PropertiesException { - final MarkerInfo markerInfo = new MarkerInfo(type); + private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type) throws PropertiesException { + + Rule rule = violation.getRule(); + + MarkerInfo2 info = new MarkerInfo2(type, 7); - final List attributeNames = new ArrayList(); - final List values = new ArrayList(); + info.add(IMarker.MESSAGE, violation.getDescription()); + info.add(IMarker.LINE_NUMBER, violation.getBeginLine()); + info.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2, violation.getEndLine()); + info.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME, rule.getName()); + info.add(PMDRuntimeConstants.KEY_MARKERATT_PRIORITY ,rule.getPriority().getPriority()); - attributeNames.add(IMarker.MESSAGE); - values.add(violation.getDescription()); - - attributeNames.add(IMarker.LINE_NUMBER); - values.add(Integer.valueOf(violation.getBeginLine())); - - attributeNames.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2); - values.add(Integer.valueOf(violation.getEndLine())); - - attributeNames.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME); - values.add(violation.getRule().getName()); - - attributeNames.add(PMDRuntimeConstants.KEY_MARKERATT_PRIORITY); - values.add(Integer.valueOf(violation.getRule().getPriority().getPriority())); - - switch (violation.getRule().getPriority().getPriority()) { + switch (rule.getPriority().getPriority()) { case 1: - attributeNames.add(IMarker.PRIORITY); - values.add(Integer.valueOf(IMarker.PRIORITY_HIGH)); - attributeNames.add(IMarker.SEVERITY); - values.add(Integer.valueOf(projectProperties.violationsAsErrors()?IMarker.SEVERITY_ERROR:IMarker.SEVERITY_WARNING)); + info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); + info.add(IMarker.SEVERITY, projectProperties.violationsAsErrors() ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING); break; - case 2: - attributeNames.add(IMarker.SEVERITY); + case 2: if (projectProperties.violationsAsErrors()) { - values.add(Integer.valueOf(IMarker.SEVERITY_ERROR)); + info.add(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); } else { - values.add(Integer.valueOf(IMarker.SEVERITY_WARNING)); - attributeNames.add(IMarker.PRIORITY); - values.add(Integer.valueOf(IMarker.PRIORITY_HIGH)); + info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); + info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); } break; case 5: - attributeNames.add(IMarker.SEVERITY); - values.add(Integer.valueOf(IMarker.SEVERITY_INFO)); + info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO); break; case 3: - attributeNames.add(IMarker.PRIORITY); - values.add(Integer.valueOf(IMarker.PRIORITY_HIGH)); + info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); case 4: default: - attributeNames.add(IMarker.SEVERITY); - values.add(Integer.valueOf(IMarker.SEVERITY_WARNING)); + info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); break; } - - markerInfo.setAttributeNames(attributeNames.toArray(new String[attributeNames.size()])); - markerInfo.setAttributeValues(values.toArray()); - - return markerInfo; + + return info; } - + /** * Private inner type to handle reviews */ diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeleteMarkersCommand.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeleteMarkersCommand.java index bb6c965427..82d58955cd 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeleteMarkersCommand.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeleteMarkersCommand.java @@ -57,11 +57,11 @@ public class DeleteMarkersCommand extends AbstractDefaultCommand { public DeleteMarkersCommand() { super("DeleteMarkersCommand", "Deletes a possible large number of markers"); - this.setOutputProperties(true); - this.setReadOnly(false); - this.setTerminated(false); - this.setMarkers(null); - this.setUserInitiated(false); + setOutputProperties(true); + setReadOnly(false); + setTerminated(false); + setMarkers(null); + setUserInitiated(false); } public final void setMarkers(IMarker[] theMarkers) { // NOPMD by Sven on 13.11.06 11:43 @@ -95,4 +95,4 @@ public class DeleteMarkersCommand extends AbstractDefaultCommand { setMarkers(null); } -} +} \ No newline at end of file diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeltaVisitor.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeltaVisitor.java index 09f9d283ae..3c9d0f2f85 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeltaVisitor.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/DeltaVisitor.java @@ -14,6 +14,7 @@ import org.eclipse.core.runtime.IProgressMonitor; * */ public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor { + private static final Logger log = Logger.getLogger(DeltaVisitor.class); /** @@ -26,40 +27,43 @@ public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor { /** * Constructor with monitor */ - public DeltaVisitor(final IProgressMonitor monitor) { + public DeltaVisitor(IProgressMonitor monitor) { super(); - this.setMonitor(monitor); + setMonitor(monitor); } /** * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(IResourceDelta) */ - public boolean visit(final IResourceDelta delta) throws CoreException { - boolean fProcessChildren = true; + public boolean visit(IResourceDelta delta) throws CoreException { - if (this.isCanceled()) { - fProcessChildren = false; - } else { - if (delta.getKind() == IResourceDelta.ADDED) { - log.debug("Visiting added resource " + delta.getResource().getName()); - visitAdded(delta.getResource()); - } else if (delta.getKind() == IResourceDelta.CHANGED) { - log.debug("Visiting changed resource " + delta.getResource().getName()); - visitChanged(delta.getResource()); - } else { // other kinds are not visited - log.debug("Resource " + delta.getResource().getName() + " not visited."); - } - } + if (isCanceled()) return false; - return fProcessChildren; + switch (delta.getKind()) { + case IResourceDelta.ADDED : { + log.debug("Visiting added resource " + delta.getResource().getName()); + visitAdded(delta.getResource()); + break; + } + case IResourceDelta.CHANGED : { + log.debug("Visiting changed resource " + delta.getResource().getName()); + visitChanged(delta.getResource()); + break; + } + default : { // other kinds are not visited + log.debug("Resource " + delta.getResource().getName() + " not visited."); + } + } + + return true; } /** * Visit added resource * @param resource a new resource */ - private void visitAdded(final IResource resource) { - this.reviewResource(resource); + private void visitAdded(IResource resource) { + reviewResource(resource); } /** @@ -67,7 +71,7 @@ public class DeltaVisitor extends BaseVisitor implements IResourceDeltaVisitor { * @param resource a changed resource */ private void visitChanged(final IResource resource) { - this.reviewResource(resource); + reviewResource(resource); } } \ No newline at end of file diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo.java deleted file mode 100644 index f33e622b4e..0000000000 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Copyright 1997-2003 PMD for Eclipse Development team - * under sponsorship of the Defense Advanced Research Projects - * Agency (DARPA). - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Cougaar Open Source License as published by - * DARPA on the Cougaar Open Source Website (www.cougaar.org). - * - * THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS - * PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR - * IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT - * ANY WARRANTIES AS TO NON-INFRINGEMENT. IN NO EVENT SHALL COPYRIGHT - * HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS, - * TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THE COUGAAR SOFTWARE. - * - * - */ -package net.sourceforge.pmd.eclipse.runtime.cmd; - -/** - * This class is intended to hold informations for future marker creation. - * - * @author Philippe Herlin - * - */ -public class MarkerInfo { - - private final String type; - private String[] attributeNames; - private Object[] attributeValues; - - public MarkerInfo(String theType) { - type = theType; - } - /** - * @return - */ - public String[] getAttributeNames() { - return attributeNames; - } - - /** - * @return - */ - public Object[] getAttributeValues() { - return attributeValues; - } - - /** - * @return - */ - public String getType() { - return type; - } - - /** - * @param strings - */ - public void setAttributeNames(String[] strings) { - attributeNames = strings; - } - - /** - * @param objects - */ - public void setAttributeValues(Object[] objects) { - attributeValues = objects; - } - -} diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo2.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo2.java new file mode 100644 index 0000000000..72cb738719 --- /dev/null +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/MarkerInfo2.java @@ -0,0 +1,40 @@ +package net.sourceforge.pmd.eclipse.runtime.cmd; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; + +/** + * + * @author Brian Remedios + */ +public class MarkerInfo2 { + + private final String type; + private List names; + private List values; + + public MarkerInfo2(String theType, int expectedSize) { + type = theType; + names = new ArrayList(expectedSize); + values = new ArrayList(expectedSize); + } + + public void add(String name, Object value) { + names.add(name); + values.add(value); + } + + public void add(String name, int value) { + add(name, Integer.valueOf(value)); + } + + public void addAsMarkerTo(IFile file) throws CoreException { + + IMarker marker = file.createMarker(type); + marker.setAttributes(names.toArray(new String[names.size()]), values.toArray()); + } +} diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java index 9e3007d056..28a3b7ac94 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java @@ -52,6 +52,7 @@ import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences; import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties; import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException; import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil; +import net.sourceforge.pmd.lang.Language; import org.apache.log4j.Logger; import org.eclipse.core.resources.IContainer; @@ -91,7 +92,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { private final List resources = new ArrayList(); private IResourceDelta resourceDelta; - private Map> markersByFile = new HashMap>(); + private Map> markersByFile = new HashMap>(); private boolean taskMarker; private boolean openPmdPerspective; private int ruleCount; @@ -231,7 +232,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { /** * @return Returns the file markers */ - public Map> getMarkers() { + public Map> getMarkers() { return markersByFile; } @@ -284,7 +285,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { @Override public void reset() { resources.clear(); - markersByFile = new HashMap>(); + markersByFile = new HashMap>(); setTerminated(false); openPmdPerspective = false; onErrorIssue = null; @@ -518,11 +519,10 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { if (isCanceled()) break; currentFile = file.getName(); - Set markerInfoSet = markersByFile.get(file); + Set markerInfoSet = markersByFile.get(file); // MarkerUtil.deleteAllMarkersIn(file); - for (MarkerInfo markerInfo : markerInfoSet) { - IMarker marker = file.createMarker(markerInfo.getType()); - marker.setAttributes(markerInfo.getAttributeNames(), markerInfo.getAttributeValues()); + for (MarkerInfo2 markerInfo : markerInfoSet) { + markerInfo.addAsMarkerTo(file); violationCount++; } @@ -537,7 +537,6 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { logInfo("" + violationCount + " markers applied on " + count + " files in " + timer.getDuration() + "ms."); log.info("End of processing marker directives. " + violationCount + " violations for " + count + " files."); } - } /** @@ -581,7 +580,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { * * @author SebastianRaffel ( 07.05.2005 ) */ - private void switchToPmdPerspective() { + private static void switchToPmdPerspective() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IPerspectiveRegistry reg = workbench.getPerspectiveRegistry(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); @@ -598,7 +597,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand { boolean fVisitChildren = true; count++; - if (resource instanceof IFile && isJavaFile((IFile) resource)) { + if (resource instanceof IFile && isLanguageFile((IFile) resource, Language.JAVA)) { fVisitChildren = false; } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java index cc9f146310..a26a51b1b9 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java @@ -515,17 +515,19 @@ class PreferencesManagerImpl implements IPreferencesManager { */ private void storeRuleSetInStateLocation(RuleSet ruleSet) { OutputStream out = null; + PMDPlugin plugin = PMDPlugin.getDefault(); + try { - IPath ruleSetLocation = PMDPlugin.getDefault().getStateLocation().append(PREFERENCE_RULESET_FILE); + IPath ruleSetLocation = plugin.getStateLocation().append(PREFERENCE_RULESET_FILE); out = new FileOutputStream(ruleSetLocation.toOSString()); - IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter(); + IRuleSetWriter writer = plugin.getRuleSetWriter(); writer.write(out, ruleSet); out.flush(); } catch (IOException e) { - PMDPlugin.getDefault().logError("IO Exception when storing ruleset in state location", e); + plugin.logError("IO Exception when storing ruleset in state location", e); } catch (WriterException e) { - PMDPlugin.getDefault().logError("General PMD Eclipse Exception when storing ruleset in state location", e); + plugin.logError("General PMD Eclipse Exception when storing ruleset in state location", e); } finally { IOUtil.closeQuietly(out); } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java index 2ee8105bcb..599183b921 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/filters/FilterPreferencesPage.java @@ -68,7 +68,8 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements private Button pmdButt; private Text patternField; private BasicTableManager reportTableMgr; - + private Collection editorWidgets = new ArrayList(); + private static Image IncludeIcon; private static Image ExcludeIcon; @@ -172,11 +173,10 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements } private void enableEditor(boolean flag) { - cpdButt.setEnabled(flag); - pmdButt.setEnabled(flag); - excludeButt.setEnabled(flag); - includeButt.setEnabled(flag); - patternField.setEnabled(flag); + + for (Control control : editorWidgets) { + control.setEnabled(flag); + } } private List tableFilters(boolean isInclude) { @@ -229,9 +229,7 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection)event.getSelection(); - selectedPatterns(filtersIn(selection.toList())); - updateControls(); + patternsSelected(); } }); @@ -246,6 +244,12 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements return parent; } + private void patternsSelected() { + IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection(); + selectedPatterns(filtersIn(selection.toList())); + updateControls(); + } + private void selectedPatterns(Collection holders) { setState(holders, includeButt, FilterHolder.IncludeAccessor); @@ -304,7 +308,8 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements Label typeLabel = new Label(editorPanel, SWT.None); typeLabel.setLayoutData( new GridData()); typeLabel.setText("Type:"); - + editorWidgets.add(typeLabel); + excludeButt = createButton(editorPanel, SWT.RADIO, excludeIcon(), "Exclude"); excludeButt.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { @@ -321,10 +326,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements } }); + editorWidgets.add(excludeButt); + editorWidgets.add(includeButt); + Label contextLabel = new Label(editorPanel, SWT.None); contextLabel.setLayoutData( new GridData()); contextLabel.setText("Applies to:"); - + editorWidgets.add(contextLabel); + pmdButt = createButton(editorPanel, SWT.CHECK, "PMD"); pmdButt.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { @@ -341,10 +350,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements } }); + editorWidgets.add(pmdButt); + editorWidgets.add(cpdButt); + Label patternLabel = new Label(editorPanel, SWT.None); patternLabel.setLayoutData( new GridData()); patternLabel.setText("Pattern:"); - + editorWidgets.add(patternLabel); + patternField = new Text(editorPanel, SWT.BORDER); patternField.setLayoutData( new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1) ); patternField.addFocusListener(new FocusAdapter() { @@ -353,6 +366,15 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements tableViewer.refresh(); } }); + editorWidgets.add(patternField); + + Label spacer = new Label(editorPanel, SWT.None); + spacer.setLayoutData( new GridData() ); + Label description = new Label(editorPanel, SWT.None); + description.setLayoutData( new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1) ); + description.setText("name or path pattern (* = any string, ? = any character)"); + + editorWidgets.add(description); } /** @@ -535,7 +557,14 @@ public class FilterPreferencesPage extends AbstractPMDPreferencePage implements private void addNewFilter() { FilterHolder newHolder = new FilterHolder(NewFilterPattern, true, false, false); - tableViewer.setInput( tableFiltersWith(newHolder) ); + + FilterHolder[] holders = tableFiltersWith(newHolder); + tableViewer.setInput( holders ); + + tableViewer.getTable().select(holders.length-1); + patternsSelected(); + patternField.selectAll(); + patternField.forceFocus(); } /** diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/br/RuleTableManager.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/br/RuleTableManager.java index b6973a4ada..43a7a74975 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/br/RuleTableManager.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/preferences/br/RuleTableManager.java @@ -84,7 +84,7 @@ public class RuleTableManager extends AbstractTreeTableManager implements private MenuItem useDefaultsItem; private Button addRuleButton; private Button removeRuleButton; - + private Button exportRuleSetButton; private RuleSelectionListener ruleSelectionListener; private ValueResetHandler resetHandler; @@ -312,22 +312,46 @@ public class RuleTableManager extends AbstractTreeTableManager implements button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { - FileDialog dialog = new FileDialog(parent.getShell(), SWT.SAVE); - String fileName = dialog.open(); - if (fileName != null) { - try { - exportTo(fileName, parent.getShell()); - } catch (Exception e) { - plugin.showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e); - } - } + exportSelectedRules(); } - }); return button; } + private void exportSelectedRules() { + + Shell shell = treeViewer.getTree().getShell(); + + FileDialog dialog = new FileDialog(shell, SWT.SAVE); + dialog.setText("Export " + ruleSelection.allRules().size() + " rules"); + + String fileName = dialog.open(); + if (StringUtil.isNotEmpty(fileName)) { + try { + exportTo(fileName, shell); + } catch (Exception e) { + plugin.showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e); + } + } + } + + private RuleSet ruleSelectionAsRuleSet() { + + RuleSet rs = new RuleSet(); + rs.setName( ruleSet.getName() ); + rs.setDescription( ruleSet.getDescription() ); + rs.setFileName( ruleSet.getFileName()); + rs.addExcludePatterns( ruleSet.getExcludePatterns() ); + rs.addIncludePatterns( ruleSet.getIncludePatterns() ); + + for (Rule rule : ruleSelection.allRules()) { + rs.addRule(rule); + } + + return rs; + } + private void exportTo(String fileName, Shell shell) throws FileNotFoundException, WriterException, IOException { File file = new File(fileName); @@ -340,7 +364,12 @@ public class RuleTableManager extends AbstractTreeTableManager implements } InputDialog input = null; + + RuleSet ruleSet = null; + if (flContinue) { + ruleSet = ruleSelectionAsRuleSet(); + input = new InputDialog(shell, getMessage(StringKeys.PREF_RULESET_DIALOG_TITLE), getMessage(StringKeys.PREF_RULESET_DIALOG_RULESET_DESCRIPTION), @@ -466,6 +495,8 @@ public class RuleTableManager extends AbstractTreeTableManager implements } catch (RuntimeException e) { plugin.showError(getMessage(StringKeys.ERROR_IMPORTING_RULESET), e); } + + updateCheckControls(); } public Composite buildGroupCombo(Composite parent, String comboLabelKey, final Object[][] groupingChoices) { @@ -541,7 +572,7 @@ public class RuleTableManager extends AbstractTreeTableManager implements addRuleButton = buildAddRuleButton(composite); removeRuleButton = buildRemoveRuleButton(composite); Button importRuleSetButton = buildImportRuleSetButton(composite); - Button exportRuleSetButton = buildExportRuleSetButton(composite); + exportRuleSetButton = buildExportRuleSetButton(composite); Button ruleDesignerButton = buildRuleDesignerButton(composite); GridData data = new GridData(); @@ -865,7 +896,10 @@ public class RuleTableManager extends AbstractTreeTableManager implements ruleSelectionListener.selection(ruleSelection); } - if (removeRuleButton != null) removeRuleButton.setEnabled(items.length > 0); + boolean hasSelections = items.length > 0; + + if (removeRuleButton != null) removeRuleButton.setEnabled(hasSelections); + if (exportRuleSetButton != null) exportRuleSetButton.setEnabled(hasSelections); } private class SelectionStats { @@ -892,7 +926,7 @@ public class RuleTableManager extends AbstractTreeTableManager implements if (StringUtil.isNotEmpty(rule.dysfunctionReason())) dysfunctionCount++; } } - return new SelectionStats(selectedCount , rules.length, dysfunctionCount) ; + return new SelectionStats(selectedCount, rules.length, dysfunctionCount) ; } protected void setAllItemsActive() { diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/DisableRuleAction.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/DisableRuleAction.java index 68eb9739ad..4eb722bf73 100755 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/DisableRuleAction.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/DisableRuleAction.java @@ -12,6 +12,11 @@ import net.sourceforge.pmd.eclipse.ui.nls.StringKeys; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.viewers.TableViewer; public class DisableRuleAction extends AbstractViolationSelectionAction { @@ -53,21 +58,41 @@ public class DisableRuleAction extends AbstractViolationSelectionAction { System.out.println("Violations deleted: " + deletions); } + private List disableRulesFor(IMarker[] markers) { + + List rules = MarkerUtil.rulesFor(markers); + + for (Rule rule : rules) { + preferences.isActive(rule.getName(), false); + } + + preferences.sync(); + return rules; + } + /** * @see org.eclipse.jface.action.IAction#run() */ public void run() { final IMarker[] markers = getSelectedViolations(); - if (markers == null) return; + if (markers == null) return; - List rules = MarkerUtil.rulesFor(markers); - for (Rule rule : rules) { - preferences.isActive(rule.getName(), false); + try { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + List rules = disableRulesFor(markers); + removeViolationsOf(rules, MarkerUtil.commonProjectsOf(markers) ); + } + }, null); + } catch (CoreException ce) { + logErrorByKey(StringKeys.ERROR_CORE_EXCEPTION, ce); } - preferences.sync(); - removeViolationsOf(rules, MarkerUtil.commonProjectsOf(markers) ); + + + } } diff --git a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/ReviewAction.java b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/ReviewAction.java index 55a39cb3ac..aab3eabba6 100644 --- a/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/ReviewAction.java +++ b/pmd-eclipse-plugin/plugins/net.sourceforge.pmd.eclipse.plugin/src/net/sourceforge/pmd/eclipse/ui/views/actions/ReviewAction.java @@ -37,6 +37,7 @@ import org.eclipse.swt.widgets.Shell; * */ public class ReviewAction extends AbstractViolationSelectionAction { + private static final Logger log = Logger.getLogger(ReviewAction.class); private IProgressMonitor monitor; @@ -64,13 +65,7 @@ public class ReviewAction extends AbstractViolationSelectionAction { // Get confirmation if multiple markers are selected // Not necessary when using PMD style - boolean go = true; - if (markers.length > 1 && !reviewPmdStyle) { - String title = getString(StringKeys.CONFIRM_TITLE); - String message = getString(StringKeys.CONFIRM_REVIEW_MULTIPLE_MARKERS); - Shell shell = Display.getCurrent().getActiveShell(); - go = MessageDialog.openConfirm(shell, title, message); - } + boolean go = confirmForMultiples(markers, reviewPmdStyle); // If only one marker selected or user has confirmed, review violation if (go) { @@ -92,6 +87,17 @@ public class ReviewAction extends AbstractViolationSelectionAction { } } + private static boolean confirmForMultiples(IMarker[] markers, boolean reviewPmdStyle) { + boolean go = true; + if (markers.length > 1 && !reviewPmdStyle) { + String title = getString(StringKeys.CONFIRM_TITLE); + String message = getString(StringKeys.CONFIRM_REVIEW_MULTIPLE_MARKERS); + Shell shell = Display.getCurrent().getActiveShell(); + go = MessageDialog.openConfirm(shell, title, message); + } + return go; + } + /** * Do the insertion of the review comment * @@ -111,11 +117,9 @@ public class ReviewAction extends AbstractViolationSelectionAction { monitorWorked(); - if (reviewPmdStyle) { - sourceCode = addPmdReviewComment(sourceCode, offset, marker); - } else { - sourceCode = addPluginReviewComment(sourceCode, offset, marker); - } + sourceCode = reviewPmdStyle ? + addPmdReviewComment(sourceCode, offset, marker) : + addPluginReviewComment(sourceCode, offset, marker); monitorWorked(); @@ -129,18 +133,8 @@ public class ReviewAction extends AbstractViolationSelectionAction { } } - } catch (JavaModelException e) { - IJavaModelStatus status = e.getJavaModelStatus(); - PMDPlugin.getDefault().logError(status); - log.warn("Ignoring Java Model Exception : " + status.getMessage()); - if (log.isDebugEnabled()) { - log.debug(" code : " + status.getCode()); - log.debug(" severity : " + status.getSeverity()); - IJavaElement[] elements = status.getElements(); - for (int i = 0; i < elements.length; i++) { - log.debug(" element : " + elements[i].getElementName() + " (" + elements[i].getElementType() + ')'); - } - } + } catch (JavaModelException jme) { + ignore(jme); } catch (CoreException e) { logErrorByKey(StringKeys.ERROR_CORE_EXCEPTION, e); } catch (IOException e) { @@ -148,6 +142,21 @@ public class ReviewAction extends AbstractViolationSelectionAction { } } + private static void ignore(JavaModelException jme) { + + IJavaModelStatus status = jme.getJavaModelStatus(); + PMDPlugin.getDefault().logError(status); + log.warn("Ignoring Java Model Exception : " + status.getMessage()); + if (log.isDebugEnabled()) { + log.debug(" code : " + status.getCode()); + log.debug(" severity : " + status.getSeverity()); + IJavaElement[] elements = status.getElements(); + for (int i = 0; i < elements.length; i++) { + log.debug(" element : " + elements[i].getElementName() + " (" + elements[i].getElementType() + ')'); + } + } + } + /** * Get the monitor * @@ -178,7 +187,7 @@ public class ReviewAction extends AbstractViolationSelectionAction { /** * Renvoie la position dans le code source du début de la ligne du marqueur */ - private int getMarkerLineStart(String sourceCode, int lineNumber) { + private static int getMarkerLineStart(String sourceCode, int lineNumber) { int lineStart = 0; int currentLine = 1; for (lineStart = 0; lineStart < sourceCode.length(); lineStart++) { @@ -209,7 +218,7 @@ public class ReviewAction extends AbstractViolationSelectionAction { /** * Insert a review comment with the Plugin style */ - private String addPluginReviewComment(String sourceCode, int offset, IMarker marker) { + private static String addPluginReviewComment(String sourceCode, int offset, IMarker marker) { // Copy the source code until the violation line not included StringBuilder sb = new StringBuilder(sourceCode.substring(0, offset)); @@ -230,7 +239,7 @@ public class ReviewAction extends AbstractViolationSelectionAction { /** * Insert a review comment with the PMD style */ - private String addPmdReviewComment(String sourceCode, int offset, IMarker marker) { + private static String addPmdReviewComment(String sourceCode, int offset, IMarker marker) { String result = sourceCode; // Find the end of line @@ -297,4 +306,4 @@ public class ReviewAction extends AbstractViolationSelectionAction { } } -} +} \ No newline at end of file