From: Simon Brandhof Date: Wed, 2 Mar 2016 09:33:41 +0000 (+0100) Subject: Fix quality flaws X-Git-Tag: 5.5-M6~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=902099c8dd84d1e3d845caf8a4b4a445b3903439;p=sonarqube.git Fix quality flaws --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueCounter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueCounter.java index 75925943942..3373eb62bd3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueCounter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueCounter.java @@ -184,7 +184,7 @@ public class IssueCounter extends IssueVisitor { if (!periodsHolder.getPeriods().isEmpty()) { Double[] unresolvedVariations = new Double[PeriodsHolder.MAX_NUMBER_OF_PERIODS]; for (Period period : periodsHolder.getPeriods()) { - unresolvedVariations[period.getIndex() - 1] = new Double(currentCounters.counterForPeriod(period.getIndex()).unresolved); + unresolvedVariations[period.getIndex() - 1] = (double) currentCounters.counterForPeriod(period.getIndex()).unresolved; } measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder() .setVariations(new MeasureVariations(unresolvedVariations)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java index c3dcbf831a5..59766be6e0d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java @@ -71,7 +71,8 @@ public class CommentDensityRule extends CommonRule { return min; } - private static CommonRuleIssue generateIssue(Optional commentDensityMeasure, Optional commentLinesMeasure, Optional nclocMeasure, double minCommentDensity) { + private static CommonRuleIssue generateIssue(Optional commentDensityMeasure, Optional commentLinesMeasure, + Optional nclocMeasure, double minCommentDensity) { int commentLines = commentLinesMeasure.isPresent() ? commentLinesMeasure.get().getIntValue() : 0; int ncloc = nclocMeasure.get().getIntValue(); int minExpectedCommentLines = (int) Math.ceil(minCommentDensity * ncloc / (100 - minCommentDensity)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java index e90fe003eb2..f1d6ace71a8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java @@ -50,7 +50,7 @@ class IssuesFinderSort { return issues; } - private IssueProcessor getIssueProcessor(String sort) { + private static IssueProcessor getIssueProcessor(String sort) { if (IssueQuery.SORT_BY_ASSIGNEE.equals(sort)) { return new AssigneeSortIssueProcessor(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java index a03c55119e1..74cff9ae97c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java @@ -317,7 +317,7 @@ public class IssueFilterService { return authorizationDao.selectGlobalPermissions(user).contains(GlobalPermissions.SYSTEM_ADMIN); } - private IssueFilterResult createIssueFilterResult(SearchResult issues, SearchOptions options) { + private static IssueFilterResult createIssueFilterResult(SearchResult issues, SearchOptions options) { Paging paging = Paging.forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) issues.getTotal()); return new IssueFilterResult(issues.getDocs(), paging); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java index 051de066299..d61b0ff76a2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueAuthorizationDao.java @@ -182,7 +182,7 @@ public class IssueAuthorizationDao { return stmt; } - private void processRow(ResultSet rs, Map dtosByProjectUuid) throws SQLException { + private static void processRow(ResultSet rs, Map dtosByProjectUuid) throws SQLException { String projectUuid = rs.getString(1); String userLogin = rs.getString(2); String group = rs.getString(3); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 37ac9f4af75..f143eec7791 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -541,7 +541,7 @@ public class IssueIndex extends BaseIndex { .subAggregation(facetTopAggregation); } - private Collection escapeValuesForFacetInclusion(@Nullable Collection values) { + private static Collection escapeValuesForFacetInclusion(@Nullable Collection values) { return values == null ? Arrays.asList() : Collections2.transform(values, new Function() { @Override public String apply(String input) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java index b80490b26e4..e19336c5ea0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java @@ -76,7 +76,7 @@ public class ChangesOnMyIssueNotificationDispatcher extends NotificationDispatch } } - private void addUserToContextIfSubscribed(Context context, @Nullable String user, Multimap subscribedRecipients) { + private static void addUserToContextIfSubscribed(Context context, @Nullable String user, Multimap subscribedRecipients) { if (user != null) { Collection channels = subscribedRecipients.get(user); for (NotificationChannel channel : channels) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java index 971d3fe7976..69fca8eef51 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java @@ -66,7 +66,7 @@ public class DoNotFixNotificationDispatcher extends NotificationDispatcher { } } - private void notify(String author, Context context, Multimap subscribedRecipients) { + private static void notify(String author, Context context, Multimap subscribedRecipients) { for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { String login = channelsByRecipients.getKey(); // Do not notify the person that resolved the issue diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java index cc3a7f3fc22..97cd80d2d9d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -35,7 +36,6 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; import org.sonar.api.utils.Paging; -import org.sonar.server.issue.workflow.Transition; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.ActionPlanDto; import org.sonar.db.issue.IssueChangeDto; @@ -46,6 +46,7 @@ import org.sonar.db.rule.RuleDto; import org.sonar.db.user.UserDto; import org.sonar.markdown.Markdown; import org.sonar.server.es.Facets; +import org.sonar.server.issue.workflow.Transition; import org.sonar.server.ws.WsResponseCommonFormat; import org.sonarqube.ws.Common; import org.sonarqube.ws.Issues; @@ -64,7 +65,7 @@ public class SearchResponseFormat { this.languages = languages; } - public Issues.SearchWsResponse formatSearch(Set fields, SearchResponseData data, + public Issues.SearchWsResponse formatSearch(EnumSet fields, SearchResponseData data, Paging paging, @Nullable Facets facets) { Issues.SearchWsResponse.Builder response = Issues.SearchWsResponse.newBuilder(); @@ -123,7 +124,7 @@ public class SearchResponseFormat { response.setPaging(commonFormat.formatPaging(paging)); } - private List formatIssues(Set fields, SearchResponseData data) { + private List formatIssues(EnumSet fields, SearchResponseData data) { List result = new ArrayList<>(); Issues.Issue.Builder issueBuilder = Issues.Issue.newBuilder(); for (IssueDto dto : data.getIssues()) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java index 5ca140ba8f6..301214454fb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServicesWs.java @@ -104,7 +104,7 @@ public class WebServicesWs implements WebService { .setExampleValue("search"); } - private void handleResponseExample(Action action, Response response) throws IOException { + private static void handleResponseExample(Action action, Response response) throws IOException { if (action.responseExample() != null) { response .newJsonWriter() @@ -189,7 +189,7 @@ public class WebServicesWs implements WebService { } } - private void writeParam(JsonWriter writer, Param param) { + private static void writeParam(JsonWriter writer, Param param) { writer.beginObject(); writer.prop("key", param.key()); writer.prop("description", param.description()); diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java index 82d94305d86..19c28a62261 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyDao.java @@ -83,7 +83,7 @@ public class WidgetPropertyDao implements Dao { }); } - private WidgetPropertyMapper mapper(DbSession session) { + private static WidgetPropertyMapper mapper(DbSession session) { return session.getMapper(WidgetPropertyMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java index cb9c14a51d8..cd593b8b8b2 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java @@ -117,7 +117,7 @@ public class PermissionTemplateDao implements Dao { return countGroups(session, query, templateId, null); } - private int countGroups(DbSession session, PermissionQuery query, long templateId, @Nullable String groupName) { + private static int countGroups(DbSession session, PermissionQuery query, long templateId, @Nullable String groupName) { Map parameters = groupsParameters(query, templateId); if (groupName != null) { parameters.put("groupName", groupName.toUpperCase()); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java index 2778afe56e9..7f021639917 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java @@ -171,7 +171,7 @@ public class Checks { throw new IllegalStateException(String.format("Fail to instantiate class %s for rule %s", checkClassOrInstance, activeRule.ruleKey()), e); } - private void configureFields(ActiveRule activeRule, Object check) { + private static void configureFields(ActiveRule activeRule, Object check) { for (Map.Entry param : activeRule.params().entrySet()) { Field field = getField(check, param.getKey()); if (field == null) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index 0bd6997a7dd..be86b62992e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -89,7 +89,7 @@ public final class AnnotationCheckFactory extends CheckFactory { } } - private void configureFields(ActiveRule activeRule, Object check) { + private static void configureFields(ActiveRule activeRule, Object check) { for (ActiveRuleParam param : activeRule.getActiveRuleParams()) { Field field = getField(check, param.getKey()); if (field == null) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index 404da38046e..fd0df622783 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -64,7 +64,7 @@ public final class AnnotationRuleParser { return null; } - private Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) { + private static Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) { String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName()); String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null); String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);