private void computeViolationsPerRules(DecoratorContext context) { Map<RulePriority, Multiset<Rule>> rulesPerSeverity = Maps.newHashMap(); for (Violation violation : context.getViolations()) { Multiset<Rule> rulesBag = initRules(rulesPerSeverity, violation.getSeverity()); rulesBag.add(violation.getRule()); } for (RulePriority severity : RulePriority.values()) { Metric metric = SeverityUtils.severityToViolationMetric(severity); Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric)); for (Measure child : children) { RuleMeasure childRuleMeasure = (RuleMeasure) child; Rule rule = childRuleMeasure.getRule(); if (rule != null && MeasureUtils.hasValue(childRuleMeasure)) { Multiset<Rule> rulesBag = initRules(rulesPerSeverity, severity); rulesBag.add(rule, childRuleMeasure.getIntValue()); } } Multiset<Rule> rulesBag = rulesPerSeverity.get(severity); if (rulesBag != null) { for (Multiset.Entry<Rule> entry : rulesBag.entrySet()) { RuleMeasure measure = RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount()); measure.setSeverity(severity); context.saveMeasure(measure); } } } }
/** {@inheritDoc} */ public void decorate(Resource resource, DecoratorContext context) { if (!shouldDecorateResource(context)) { return; } Measure dividend = context.getMeasure(getDividendMetric()); Measure divisor = context.getMeasure(getDivisorMetric()); if (MeasureUtils.hasValue(dividend) && MeasureUtils.hasValue(divisor) && divisor.getValue() > 0.0) { context.saveMeasure( new Measure( getQuotientMetric(), compute(dividend, divisor, getQuotientMetric().isPercentageType()))); } }
private boolean shouldDecorateResource(Resource resource, DecoratorContext context) { return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY)); }