]> source.dussan.org Git - sonarqube.git/commitdiff
Code cleaning : Remove unnecessary casts
authorDavid Gageot <david@gageot.net>
Fri, 27 Apr 2012 14:45:37 +0000 (16:45 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 27 Apr 2012 14:48:58 +0000 (16:48 +0200)
18 files changed:
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/ProjectDsmDecorator.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileImporter.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/AccessorVisitor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/MethodVisitor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/bytecode/asm/AsmMethod.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/DesignBridge.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java
sonar-colorizer/src/main/java/org/sonar/colorizer/CaseInsensitiveKeywordsTokenizer.java
sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java
sonar-colorizer/src/test/java/org/sonar/colorizer/HtmlCodeBuilderTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenPluginTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java
sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java
sonar-squid/src/main/java/org/sonar/squid/measures/MeanAggregationFormula.java

index adaf87e31aa744f5b46305281c3f5e195db79825..b844c588f6cf042e042f9a15a3c60983bd1587a2 100644 (file)
@@ -35,6 +35,6 @@ public class ProjectPurgePostJob implements PostJob {
   }
 
   public void executeOn(final Project project, SensorContext context) {
-    purgeTask.purge((long) project.getId());
+    purgeTask.purge(project.getId());
   }
 }
index e81e3cd30ea8b3d7cfc92c3b18816e6f0df187d8..016e11eeceb55429a1a718d218ec3cb69f273110 100644 (file)
@@ -44,7 +44,7 @@ public class DefaultPeriodCleaner implements PeriodCleaner {
   }
 
   public void purge(Project project, int projectSnapshotId) {
-    clean((long) project.getId());
+    clean(project.getId());
   }
 
   public void clean(long projectId) {
index 41592c0515875e2a6641272f5dadf2f5a5f41714..0cbb9d251d97cd5e31de8789f383e1871436023c 100644 (file)
@@ -92,7 +92,7 @@ public class ProjectDsmDecorator implements Decorator {
 
   private void addSubProjects(Project project, List<Resource> subProjects) {
     for (Project subProject : project.getModules()) {
-      Project indexedSubProject = (Project) index.getResource(subProject);
+      Project indexedSubProject = index.getResource(subProject);
       if (indexedSubProject != null) {
         subProjects.add(indexedSubProject);
       }
index 8c4ddb45286dd6d6950da88a8c2b5a8433aaaf52..7524b9d246540532162190a67afa8cb21fc31758 100644 (file)
@@ -117,9 +117,9 @@ public class PmdProfileImporter extends ProfileImporter {
 
   private List<Element> getChildren(Element parent, String childName, @Nullable Namespace namespace) {
     if (namespace == null) {
-      return (List<Element>) parent.getChildren(childName);
+      return parent.getChildren(childName);
     } else {
-      return (List<Element>) parent.getChildren(childName, namespace);
+      return parent.getChildren(childName, namespace);
     }
   }
 
index 37a4ad8d529f5f259167f74dac2d9fc35a681392..8509dcf31955eb4c5037d76aa5676694605f4b5c 100644 (file)
@@ -126,7 +126,7 @@ public class AccessorVisitor extends JavaAstVisitor {
   }
 
   private boolean inspectSetterMethodBody(DetailAST method, DetailAST methodParams, DetailAST methodBody) {
-    DetailAST expr = (DetailAST) methodBody.getFirstChild();
+    DetailAST expr = methodBody.getFirstChild();
     if (isAstType(expr, TokenTypes.EXPR)) {
       DetailAST assignment = expr.findFirstToken(TokenTypes.ASSIGN);
       if (assignment != null) {
index 316c395595ef101cb151f005911f0866cb3e181e..82abad510996a0aa839cb6b09cf61e76882ac918 100644 (file)
@@ -95,7 +95,7 @@ public class MethodVisitor extends JavaAstVisitor {
         Parameter argumentType = extractArgumentAndReturnType(child.findFirstToken(TokenTypes.TYPE));
         argumentTypes.add(new Parameter(argumentType));
       }
-      child = (DetailAST) child.getNextSibling();
+      child = child.getNextSibling();
     }
     return argumentTypes;
   }
index e5e68d74070a76b9778ca1eca09fc4e614772b09..2c9efe9f0647c07c8f90aef76ed9c0fec9945ba6 100644 (file)
@@ -198,11 +198,11 @@ public class AsmMethod extends AsmResource {
   }
   
   private boolean isCallToNonStaticInternalField(AsmEdge edge) {
-    return edge.getTargetAsmClass() == (AsmClass)getParent() && edge.getUsage() == SourceCodeEdgeUsage.CALLS_FIELD && !((AsmField)edge.getTo()).isStatic();
+    return edge.getTargetAsmClass() == getParent() && edge.getUsage() == SourceCodeEdgeUsage.CALLS_FIELD && !((AsmField) edge.getTo()).isStatic();
   }
   
   private boolean isCallToNonStaticInternalMethod(AsmEdge edge) {
-    return edge.getTargetAsmClass() == (AsmClass)getParent() && edge.getUsage() == SourceCodeEdgeUsage.CALLS_METHOD && !((AsmMethod)edge.getTo()).isStatic();
+    return edge.getTargetAsmClass() == getParent() && edge.getUsage() == SourceCodeEdgeUsage.CALLS_METHOD && !((AsmMethod) edge.getTo()).isStatic();
   }
 
   @Override
index 9e1175faee877b508706496ba4de42e2eff2be2a..cfffeb395b9b4ee519f67c1a0f9f2325816e10cd 100644 (file)
@@ -70,9 +70,9 @@ public class DesignBridge extends Bridge {
       LOG.debug("{} feedback edges", feedbackEdges.size());
       int tangles = cyclesAndFESSolver.getWeightOfFeedbackEdgeSet();
 
-      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_CYCLES, (double) cyclesAndFESSolver.getCycles().size());
-      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_FEEDBACK_EDGES, (double) feedbackEdges.size());
-      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_TANGLES, (double) tangles);
+      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_CYCLES, cyclesAndFESSolver.getCycles().size());
+      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_FEEDBACK_EDGES, feedbackEdges.size());
+      savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_TANGLES, tangles);
       savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_EDGES_WEIGHT, getEdgesWeight(squidPackages));
 
       String dsmJson = serializeDsm(squid, squidPackages, feedbackEdges);
@@ -103,9 +103,9 @@ public class DesignBridge extends Bridge {
       Set<Edge> feedbackEdges = solver.getEdges();
       int tangles = solver.getWeightOfFeedbackEdgeSet();
 
-      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_CYCLES, (double) cycles.size());
-      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_FEEDBACK_EDGES, (double) feedbackEdges.size());
-      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_TANGLES, (double) tangles);
+      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_CYCLES, cycles.size());
+      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_FEEDBACK_EDGES, feedbackEdges.size());
+      savePositiveMeasure(sonarPackage, CoreMetrics.FILE_TANGLES, tangles);
       savePositiveMeasure(sonarPackage, CoreMetrics.FILE_EDGES_WEIGHT, getEdgesWeight(squidFiles));
 
       String dsmJson = serializeDsm(squid, squidFiles, feedbackEdges);
index dae1ded53861f86575f3c7438e999380208bcd46..4a0544c276682b4c454d1f6226c107b21c0ffa62 100644 (file)
@@ -137,7 +137,7 @@ public class ClassVisitorTest {
 
   @Test
   public void testCreateSquidClassFromEmptyPackage() {
-    SourceClass squidClass = ClassVisitor.createSourceClass((SourcePackage) new SourcePackage(""), "Squid");
+    SourceClass squidClass = ClassVisitor.createSourceClass(new SourcePackage(""), "Squid");
     assertEquals("Squid", squidClass.getKey());
   }
 
index 00706d9b13da4eab8f579dda0d0d7608f61875a3..f7111c3b6e6593eea17c69ee3ec9fe292edf81c5 100644 (file)
@@ -34,7 +34,7 @@ public class CaseInsensitiveKeywordsTokenizer extends KeywordsTokenizer {
   }
 
   public KeywordsTokenizer clone() {
-    KeywordsTokenizer clone = (KeywordsTokenizer) super.clone();
+    KeywordsTokenizer clone = super.clone();
     clone.setCaseInsensitive(true);
     return clone;
   }
index c12836465137a7ead7970823b010767e33c8766d..8c830560047e5c2e72c13762ab6354f804bfa2ab 100644 (file)
@@ -32,8 +32,8 @@ public class HtmlDecorator extends Tokenizer {
   private HtmlOptions options;
   private int lineId;
 
-  private static final int LF = (int) '\n';
-  private static final int CR = (int) '\r';
+  private static final int LF = '\n';
+  private static final int CR = '\r';
 
   public HtmlDecorator(HtmlOptions options) {
     this.options = options;
index e005260494e6a579c323a3381449a62dce07e19c..1eef540e83367849d08115b460d8b3b242d4e173 100644 (file)
@@ -73,7 +73,7 @@ public class HtmlCodeBuilderTest {
     assertThat((String) builder.getVariable("foo"), is("yyy"));
 
     builder.setVariable("foo", null);
-    assertThat((String) builder.getVariable("foo"), nullValue());
+    assertThat(builder.getVariable("foo"), nullValue());
 
     assertThat((String) builder.getVariable("foo", "default"), is("default"));
   }
index 4728a25bea7039b2fae312c679a96d415f12f975..d49a7001028ed5206f71197dc67e14ee4ff287fd 100644 (file)
@@ -126,7 +126,7 @@ public class BatchExtensionDictionnary {
     }
     List sortedList = dag.sort();
 
-    return (Collection<T>) Collections2.filter(sortedList, Predicates.in(extensions));
+    return Collections2.filter(sortedList, Predicates.in(extensions));
   }
 
   /**
index d155b8fe42dda1ee734bf401b8abca6a9996ce17..3ec31bbced552b91a6adaf0688b267d577a50dc7 100644 (file)
@@ -162,6 +162,6 @@ public class RuleMeasure extends Measure {
    */
   @Deprecated
   public static RuleMeasure createForCategory(Metric metric, Integer category, Double value) {
-    return (RuleMeasure) new RuleMeasure(metric, null, null, category).setValue(value);
+    return new RuleMeasure(metric, null, null, category).setValue(value);
   }
 }
index ea5fc9f3ef20a3c0445744c5b77ad31a2d3351bf..9900353cb54e69d54053cb19cd844958cbeeece6 100644 (file)
@@ -196,7 +196,7 @@ public class MavenPluginTest {
     MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true);
 
     assertThat(mavenPlugin, not(nullValue()));
-    Plugin plugin = MavenUtils.getPlugin((Collection<Plugin>) pom.getBuildPlugins(), "mygroup", "my.artifact");
+    Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact");
     assertThat(plugin, not(nullValue()));
     assertThat(plugin.getVersion(), is("1.0"));
   }
@@ -207,11 +207,11 @@ public class MavenPluginTest {
     MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", true);
     assertThat(mavenPlugin, not(nullValue()));
 
-    Plugin plugin = MavenUtils.getPlugin((Collection<Plugin>) pom.getBuildPlugins(), "mygroup", "my.artifact");
+    Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact");
     assertThat(plugin, not(nullValue()));
     assertThat(plugin.getVersion(), is("1.0"));
 
-    Plugin pluginManagement = MavenUtils.getPlugin((Collection<Plugin>) pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact");
+    Plugin pluginManagement = MavenUtils.getPlugin(pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact");
     assertThat(pluginManagement, nullValue());
   }
 
@@ -221,11 +221,11 @@ public class MavenPluginTest {
     MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false);
     assertThat(mavenPlugin, not(nullValue()));
 
-    Plugin plugin = MavenUtils.getPlugin((Collection<Plugin>) pom.getBuildPlugins(), "mygroup", "my.artifact");
+    Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact");
     assertThat(plugin, not(nullValue()));
     assertThat(plugin.getVersion(), is("0.9"));
 
-    Plugin pluginManagement = MavenUtils.getPlugin((Collection<Plugin>) pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact");
+    Plugin pluginManagement = MavenUtils.getPlugin(pom.getPluginManagement().getPlugins(), "mygroup", "my.artifact");
     assertThat(pluginManagement, nullValue());
   }
 
@@ -235,7 +235,7 @@ public class MavenPluginTest {
     MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false);
     assertThat(mavenPlugin, not(nullValue()));
 
-    Plugin plugin = MavenUtils.getPlugin((Collection<Plugin>) pom.getBuildPlugins(), "mygroup", "my.artifact");
+    Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact");
     assertThat(plugin, not(nullValue()));
     assertThat(plugin.getVersion(), is("0.9"));
     assertThat(plugin.getDependencies().size(), is(1));
@@ -247,7 +247,7 @@ public class MavenPluginTest {
     MavenPlugin mavenPlugin = MavenPlugin.registerPlugin(pom, "mygroup", "my.artifact", "1.0", false);
     assertThat(mavenPlugin, not(nullValue()));
 
-    Plugin plugin = MavenUtils.getPlugin((Collection<Plugin>) pom.getBuildPlugins(), "mygroup", "my.artifact");
+    Plugin plugin = MavenUtils.getPlugin(pom.getBuildPlugins(), "mygroup", "my.artifact");
     assertThat(plugin, not(nullValue()));
     assertThat(plugin.getVersion(), is("0.9"));
     assertThat(plugin.getDependencies().size(), is(1));
index fad5083e8386d40f4869690fbca7bc73b5d9ba79..380b6cf8bda5799444c3c84aca3ac42a1d05ca8b 100644 (file)
@@ -77,7 +77,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
     setupData("shared");
     task.start();
 
-    List<Rule> rules = (List<Rule>) getSession()
+    List<Rule> rules = getSession()
       .createQuery("from " + Rule.class.getSimpleName() + " where pluginName<>'fake'")
       .getResultList();
     assertThat(rules.size(), greaterThan(0));
index eb83b805941f608fa5a3519665641d703fcb13c9..4ff249519a7d1e68f3a88699c2cc4ad20fd297c2 100644 (file)
@@ -69,7 +69,7 @@ public class ViewsTest {
     final Views views = new Views(VIEWS);
     List resourceViewers = views.getPages(NavigationSection.RESOURCE_TAB);
     assertThat(resourceViewers.size(), is(1 + 4 /* default */));
-    assertThat(resourceViewers.contains(new ViewProxy((View) FAKE_TAB)), is(true));
+    assertThat(resourceViewers.contains(new ViewProxy(FAKE_TAB)), is(true));
   }
 
   @Test
index a16643b028dca20d93004871ad3ab4dba56c2d85..1cccabd96bb216879795f9affe000d3d161d1de4 100644 (file)
@@ -29,7 +29,7 @@ public class MeanAggregationFormula implements AggregationFormula {
       return 0;
     }
     SumAggregationFormula sumFormula = new SumAggregationFormula();
-    return sumFormula.aggregate(metric, measurables) / (double) measurables.size();
+    return sumFormula.aggregate(metric, measurables) / measurables.size();
   }
 
 }