Package net.sourceforge.pmd
Class Report
- java.lang.Object
-
- net.sourceforge.pmd.Report
-
- All Implemented Interfaces:
java.lang.Iterable<RuleViolation>
public class Report extends java.lang.Object implements java.lang.Iterable<RuleViolation>
AReport
collects all informations during a PMD execution. This includes violations, suppressed violations, metrics, error during processing and configuration errors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Report.ConfigurationError
Represents a configuration error.static class
Report.ProcessingError
Represents a processing error, such as a parse error.static class
Report.ReadableDuration
Represents a duration.static class
Report.SuppressedViolation
Represents a violation, that has been suppressed.
-
Constructor Summary
Constructors Constructor Description Report()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConfigError(Report.ConfigurationError error)
Adds a new configuration error to the report.void
addError(Report.ProcessingError error)
Adds a new processing error to the report.void
addListener(ThreadSafeReportListener listener)
Registers a report listenervoid
addListeners(java.util.List<ThreadSafeReportListener> allListeners)
Adds all given listeners to this reportvoid
addMetric(Metric metric)
Deprecated.seeStatisticalRule
void
addRuleViolation(RuleViolation violation)
Adds a new rule violation to the report and notify the listeners.java.util.Iterator<Report.ConfigurationError>
configErrors()
Returns an iterator of the reported configuration errors.static Report
createReport(RuleContext ctx, java.lang.String fileName)
Creates a new, initialized, empty report for the given file name.void
end()
Mark the end time of the report.java.util.Iterator<Report.ProcessingError>
errors()
Returns an iterator of the reported processing errors.java.util.Map<java.lang.String,java.lang.Integer>
getCountSummary()
Calculate a summary of violation counts per fully classified class name.long
getElapsedTimeInMillis()
java.util.List<ThreadSafeReportListener>
getListeners()
java.util.Map<java.lang.String,java.lang.Integer>
getSummary()
Calculate a summary of violations per rule.java.util.List<Report.SuppressedViolation>
getSuppressedRuleViolations()
ReportTree
getViolationTree()
boolean
hasConfigErrors()
Checks whether any configuration errors have been reported.boolean
hasErrors()
Checks whether any processing errors have been reported.boolean
hasMetrics()
Check whether any metrics have been reportedboolean
isEmpty()
java.util.Iterator<RuleViolation>
iterator()
void
merge(Report r)
Merges the given report into this report.java.util.Iterator<Metric>
metrics()
Iterate over the metrics.int
size()
The number of violations.void
start()
Mark the start time of the report.void
suppress(java.util.Map<java.lang.Integer,java.lang.String> lines)
Configure the lines, that are suppressed via a NOPMD comment.boolean
treeIsEmpty()
Checks whether no violations have been reported.java.util.Iterator<RuleViolation>
treeIterator()
Returns an iteration over the reported violations.int
treeSize()
The number of violations.
-
-
-
Method Detail
-
createReport
public static Report createReport(RuleContext ctx, java.lang.String fileName)
Creates a new, initialized, empty report for the given file name.- Parameters:
ctx
- The context to use to connect to the reportfileName
- the filename used to report any violations- Returns:
- the new report
-
suppress
public void suppress(java.util.Map<java.lang.Integer,java.lang.String> lines)
Configure the lines, that are suppressed via a NOPMD comment.- Parameters:
lines
- the suppressed lines
-
getCountSummary
public java.util.Map<java.lang.String,java.lang.Integer> getCountSummary()
Calculate a summary of violation counts per fully classified class name.- Returns:
- violations per class name
-
getViolationTree
public ReportTree getViolationTree()
-
getSummary
public java.util.Map<java.lang.String,java.lang.Integer> getSummary()
Calculate a summary of violations per rule.- Returns:
- a Map summarizing the Report: String (rule name) -> Integer (count of violations)
-
addListener
public void addListener(ThreadSafeReportListener listener)
Registers a report listener- Parameters:
listener
- the listener
-
getSuppressedRuleViolations
public java.util.List<Report.SuppressedViolation> getSuppressedRuleViolations()
-
addRuleViolation
public void addRuleViolation(RuleViolation violation)
Adds a new rule violation to the report and notify the listeners.- Parameters:
violation
- the violation to add
-
addMetric
@Deprecated public void addMetric(Metric metric)
Deprecated.seeStatisticalRule
Adds a new metric to the report and notify the listeners- Parameters:
metric
- the metric to add
-
addConfigError
public void addConfigError(Report.ConfigurationError error)
Adds a new configuration error to the report.- Parameters:
error
- the error to add
-
addError
public void addError(Report.ProcessingError error)
Adds a new processing error to the report.- Parameters:
error
- the error to add
-
merge
public void merge(Report r)
Merges the given report into this report. This might be necessary, if a summary over all violations is needed as PMD creates one report per file by default.- Parameters:
r
- the report to be merged into this.- See Also:
AbstractAccumulatingRenderer
-
hasMetrics
public boolean hasMetrics()
Check whether any metrics have been reported- Returns:
true
if there are metrics,false
otherwise
-
metrics
public java.util.Iterator<Metric> metrics()
Iterate over the metrics.- Returns:
- an iterator over the metrics
-
isEmpty
public boolean isEmpty()
-
hasErrors
public boolean hasErrors()
Checks whether any processing errors have been reported.- Returns:
true
if there were any processing errors,false
otherwise
-
hasConfigErrors
public boolean hasConfigErrors()
Checks whether any configuration errors have been reported.- Returns:
true
if there were any configuration errors,false
otherwise
-
treeIsEmpty
public boolean treeIsEmpty()
Checks whether no violations have been reported.- Returns:
true
if no violations have been reported,false
otherwise
-
treeIterator
public java.util.Iterator<RuleViolation> treeIterator()
Returns an iteration over the reported violations.- Returns:
- an iterator
-
iterator
public java.util.Iterator<RuleViolation> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<RuleViolation>
-
errors
public java.util.Iterator<Report.ProcessingError> errors()
Returns an iterator of the reported processing errors.- Returns:
- the iterator
-
configErrors
public java.util.Iterator<Report.ConfigurationError> configErrors()
Returns an iterator of the reported configuration errors.- Returns:
- the iterator
-
treeSize
public int treeSize()
The number of violations.- Returns:
- number of violations.
-
size
public int size()
The number of violations.- Returns:
- number of violations.
-
start
public void start()
Mark the start time of the report. This is used to get the elapsed time in the end.- See Also:
getElapsedTimeInMillis()
-
end
public void end()
Mark the end time of the report. This is ued to get the elapsed time.- See Also:
getElapsedTimeInMillis()
-
getElapsedTimeInMillis
public long getElapsedTimeInMillis()
-
getListeners
public java.util.List<ThreadSafeReportListener> getListeners()
-
addListeners
public void addListeners(java.util.List<ThreadSafeReportListener> allListeners)
Adds all given listeners to this report- Parameters:
allListeners
- the report listeners
-
-