From 2b560c35ab24a4f7db27d7e180a64e830b9a56a1 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Sun, 27 Mar 2011 21:26:17 +0200 Subject: [PATCH] fix coding violations --- .../org/sonar/plugins/cpd/CpdAnalyser.java | 19 ++++-------- .../org/sonar/plugins/pmd/PmdExecutor.java | 29 ++++--------------- .../duplications/cpd/MatchAlgorithm.java | 2 +- .../src/main/java/org/sonar/graph/Cycle.java | 2 +- .../java/org/sonar/api/measures/Measure.java | 2 +- .../java/org/sonar/api/utils/DateUtils.java | 11 +++---- .../org/sonar/api/utils/KeyValueFormat.java | 5 +++- .../api/utils/command/CommandException.java | 3 +- .../server/rules/DeprecatedProfiles.java | 15 +++++----- .../java/org/sonar/server/ui/ViewProxy.java | 2 +- 10 files changed, 35 insertions(+), 55 deletions(-) diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdAnalyser.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdAnalyser.java index a185eed64af..4214a736039 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdAnalyser.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdAnalyser.java @@ -19,17 +19,7 @@ */ package org.sonar.plugins.cpd; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import net.sourceforge.pmd.cpd.TokenEntry; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.CpdMapping; @@ -40,6 +30,9 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.duplications.cpd.Match; +import java.io.File; +import java.util.*; + public class CpdAnalyser { private static final Logger LOG = LoggerFactory.getLogger(CpdAnalyser.class); @@ -84,7 +77,7 @@ public class CpdAnalyser { continue; } - firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount(), match); + firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount()); } } } @@ -116,8 +109,7 @@ public class CpdAnalyser { this.resource = resource; } - protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines, - Match match) { + protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines) { StringBuilder xml = new StringBuilder(); xml.append(" occurrences = match.iterator(); occurrences.hasNext();) { TokenEntry mark = occurrences.next(); diff --git a/sonar-graph/src/main/java/org/sonar/graph/Cycle.java b/sonar-graph/src/main/java/org/sonar/graph/Cycle.java index 0e781641f77..ce1e87b3cf3 100644 --- a/sonar-graph/src/main/java/org/sonar/graph/Cycle.java +++ b/sonar-graph/src/main/java/org/sonar/graph/Cycle.java @@ -27,7 +27,7 @@ public class Cycle { private int hashcode = 0; public Cycle(List edges) { - this.edges = edges.toArray(new Edge[0]); + this.edges = edges.toArray(new Edge[edges.size()]); for(Edge edge : edges) { hashcode += edge.hashCode(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index 6462db590d5..808328f877f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -598,7 +598,7 @@ public class Measure { if (this == o) { return true; } - if (!(o.getClass().equals(Measure.class))) { + if (o == null || getClass() != o.getClass()) { return false; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index b7702d660e5..4d19a4144ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -19,6 +19,7 @@ */ package org.sonar.api.utils; +import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.text.*; import java.util.Date; @@ -33,8 +34,8 @@ public final class DateUtils { public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; - private static final DateFormat dateFormat = new ThreadSafeDateFormat(DATE_FORMAT); - private static final DateFormat dateTimeFormat = new ThreadSafeDateFormat(DATETIME_FORMAT); + private static final ThreadSafeDateFormat dateFormat = new ThreadSafeDateFormat(DATE_FORMAT); + private static final ThreadSafeDateFormat dateTimeFormat = new ThreadSafeDateFormat(DATETIME_FORMAT); public static String formatDate(Date d) { return dateFormat.format(d); @@ -69,9 +70,9 @@ public final class DateUtils { this.format = format; } - private final ThreadLocal cache = new ThreadLocal() { + private final transient ThreadLocal cache = new ThreadLocal() { public Object get() { - SoftReference softRef = (SoftReference) super.get(); + Reference softRef = (Reference)super.get(); if (softRef == null || softRef.get() == null) { softRef = new SoftReference(new SimpleDateFormat(format)); super.set(softRef); @@ -81,7 +82,7 @@ public final class DateUtils { }; private DateFormat getDateFormat() { - return (DateFormat) ((SoftReference) cache.get()).get(); + return (DateFormat) ((Reference)cache.get()).get(); } public StringBuffer format(Date date,StringBuffer toAppendTo, FieldPosition fieldPosition) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java index 165152c3537..996bfccd826 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java @@ -29,7 +29,6 @@ import org.apache.commons.lang.math.NumberUtils; import org.slf4j.LoggerFactory; import org.sonar.api.rules.RulePriority; -import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -432,6 +431,9 @@ public final class KeyValueFormat { } + /** + * @deprecated since 2.7 replaced by Converter + */ @Deprecated public interface Transformer { KeyValue transform(String key, String value); @@ -439,6 +441,7 @@ public final class KeyValueFormat { /** * Implementation of Transformer + * @deprecated since 2.7 replaced by Converter */ @Deprecated public static class StringNumberPairTransformer implements Transformer { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandException.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandException.java index 5f39b6af5a3..f23d458a684 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandException.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandException.java @@ -20,7 +20,8 @@ package org.sonar.api.utils.command; public final class CommandException extends RuntimeException { - private Command command; + + private transient Command command = null; public CommandException(Command command, String message, Throwable throwable) { super(message + " [command: " + command + "]", throwable); diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java index 7d61dc8ccb8..9b7474ad594 100644 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java @@ -19,6 +19,7 @@ */ package org.sonar.server.rules; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.Plugins; import org.sonar.api.checks.profiles.Check; @@ -42,23 +43,23 @@ public final class DeprecatedProfiles { private CheckProfileProvider[] deprecatedCheckProfileProviders; public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) { - this.deprecatedRepositories = r; + this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r); this.plugins = plugins; this.ruleFinder = ruleFinder; - this.deprecatedCheckProfiles = deprecatedCheckProfiles; - this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders; + this.deprecatedCheckProfiles = (CheckProfile[])ArrayUtils.clone(deprecatedCheckProfiles); + this.deprecatedCheckProfileProviders = (CheckProfileProvider[])ArrayUtils.clone(deprecatedCheckProfileProviders); } public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) { - this.deprecatedRepositories = r; + this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r); this.plugins = plugins; this.ruleFinder = ruleFinder; - this.deprecatedCheckProfiles = deprecatedCheckProfiles; + this.deprecatedCheckProfiles = (CheckProfile[])ArrayUtils.clone(deprecatedCheckProfiles); this.deprecatedCheckProfileProviders = new CheckProfileProvider[0]; } public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) { - this.deprecatedRepositories = r; + this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r); this.plugins = plugins; this.ruleFinder = ruleFinder; this.deprecatedCheckProfiles = new CheckProfile[0]; @@ -66,7 +67,7 @@ public final class DeprecatedProfiles { } public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r) { - this.deprecatedRepositories = r; + this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r); this.plugins = plugins; this.ruleFinder = ruleFinder; this.deprecatedCheckProfiles = new CheckProfile[0]; diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java index d36e9562dab..c00437ac9dc 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java @@ -73,7 +73,7 @@ public class ViewProxy implements Comparable { DefaultTab defaultTabAnnotation = AnnotationUtils.getClassAnnotation(view, DefaultTab.class); if (defaultTabAnnotation != null) { - if (defaultTabAnnotation == null || defaultTabAnnotation.metrics().length == 0) { + if (defaultTabAnnotation.metrics().length == 0) { isDefaultTab = true; defaultForMetrics = new String[0]; -- 2.39.5