Search in sources :

Example 1 with ProblemType

use of org.eclipse.titanium.markers.types.ProblemType in project titan.EclipsePlug-ins by eclipse.

the class RiskFactorCalculator method measure.

/**
 * Calculate the quality of a project.
 * <p>
 * The code smells are not counted by this method, but rather supplied as
 * parameter. The keys of the map are the enum names of markers (thus,
 * {@link TaskType#getMarkerObject()} and {@link CodeSmellType#getMarkerObject()}). Exactly the
 * code smells enumerated in {@link #USED_MARKERS} are taken in account:
 * other keys are ignored; upon missing ones an exception is thrown.
 *
 * @throws IllegalArgumentException
 *             when a key is missing from <code>smellCount</code>
 *
 * @param project
 *            the project to measure
 * @param smellCount
 *            the number of occurrences for the code smells
 *
 * @return the quality assignment of the project
 */
// TODO: it worth reconsidering to refactor, i.e. the smell counting as a
// separate method of this class
public int measure(final IProject project, final Map<String, Integer> smellCount) {
    final MetricData data = MetricData.measure(project);
    final Number n = data.getStatistics(ModuleMetric.LINES_OF_CODE).get(StatColumn.TOTAL);
    final int loc = n.intValue();
    int riskFactor = 0;
    int relativeOccurrene;
    for (final ProblemType marker : USED_MARKERS) {
        final Integer count = smellCount.get(marker.toString());
        if (count == null) {
            throw new IllegalArgumentException("The supplied map has no entry for " + marker.toString() + ". Collate the parameters and the 'usedMarkers' field.");
        }
        if (count.intValue() == 0) {
            relativeOccurrene = 0;
        } else {
            int actualS = loc / count;
            int baseS = marker.getBaseLine();
            if (actualS == 0) {
                relativeOccurrene = 0;
            } else if (actualS > baseS) {
                relativeOccurrene = 1;
            } else if (actualS > baseS / 2) {
                relativeOccurrene = 2;
            } else if (actualS > baseS / 8) {
                relativeOccurrene = 3;
            } else {
                relativeOccurrene = 4;
            }
        }
        riskFactor += relativeOccurrene * marker.getImpact();
    }
    return riskFactor;
}
Also used : ProblemType(org.eclipse.titanium.markers.types.ProblemType) MetricData(org.eclipse.titanium.metrics.MetricData)

Aggregations

ProblemType (org.eclipse.titanium.markers.types.ProblemType)1 MetricData (org.eclipse.titanium.metrics.MetricData)1