use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class FilterParser method tryParsingCriterionHavingValues.
@CheckForNull
private static Criterion tryParsingCriterionHavingValues(String criterion) {
Matcher matcher = PATTERN_HAVING_VALUES.matcher(criterion);
if (!matcher.find()) {
return null;
}
Criterion.Builder builder = new Criterion.Builder();
builder.setKey(matcher.group(1));
builder.setOperator(Operator.IN);
builder.setValues(IN_VALUES_SPLITTER.splitToList(matcher.group(3)));
return builder.build();
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class LoadPeriodsStep method buildPeriod.
@CheckForNull
private Period buildPeriod(Component projectOrView, DbSession session) {
Optional<ComponentDto> projectDto = dbClient.componentDao().selectByKey(session, projectOrView.getKey());
// No project on first analysis, no period
if (!projectDto.isPresent()) {
return null;
}
boolean isReportType = projectOrView.getType().isReportType();
PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null);
Settings settings = settingsRepository.getSettings(projectOrView);
Period period = periodResolver.resolve(settings);
// SONAR-4700 Add a past snapshot only if it exists
if (period != null) {
return period;
}
return null;
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class PeriodResolver method findNearestSnapshotToTargetDate.
@CheckForNull
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Long targetDate) {
long bestDistance = Long.MAX_VALUE;
SnapshotDto nearest = null;
for (SnapshotDto snapshot : snapshots) {
long distance = Math.abs(snapshot.getCreatedAt() - targetDate);
if (distance <= bestDistance) {
bestDistance = distance;
nearest = snapshot;
}
}
return nearest;
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class DebtCalculator method calculate.
@CheckForNull
public Duration calculate(DefaultIssue issue) {
Rule rule = ruleRepository.getByKey(issue.ruleKey());
DebtRemediationFunction fn = rule.getRemediationFunction();
if (fn != null) {
verifyEffortToFix(issue, fn);
Duration debt = Duration.create(0);
String gapMultiplier = fn.gapMultiplier();
if (fn.type().usesGapMultiplier() && !Strings.isNullOrEmpty(gapMultiplier)) {
int effortToFixValue = MoreObjects.firstNonNull(issue.effortToFix(), 1).intValue();
// TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
debt = durations.decode(gapMultiplier).multiply(effortToFixValue);
}
String baseEffort = fn.baseEffort();
if (fn.type().usesBaseEffort() && !Strings.isNullOrEmpty(baseEffort)) {
// TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
debt = debt.add(durations.decode(baseEffort));
}
return debt;
}
return null;
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class FileMoveDetectionStep method getFile.
@CheckForNull
private File getFile(DbSession dbSession, DbComponent dbComponent) {
if (dbComponent.getPath() == null) {
return null;
}
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(dbSession, dbComponent.getUuid());
if (fileSourceDto == null) {
return null;
}
String lineHashes = firstNonNull(fileSourceDto.getLineHashes(), "");
return new File(dbComponent.getPath(), LINES_HASHES_SPLITTER.splitToList(lineHashes));
}
Aggregations