diff options
author | David Gageot <david@gageot.net> | 2012-05-23 08:19:35 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-23 08:19:35 +0200 |
commit | d7d95106d0e46906477da9c7f93be156823d7bce (patch) | |
tree | c127910d4f0ded6168c0bbfefdfc59b05593997a | |
parent | 67b5de980cb96e1a500f87db8997fee49ba1556d (diff) | |
download | sonarqube-d7d95106d0e46906477da9c7f93be156823d7bce.tar.gz sonarqube-d7d95106d0e46906477da9c7f93be156823d7bce.zip |
Remove warnings
8 files changed, 62 insertions, 63 deletions
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java index d3ed73a54f2..48d01e66053 100644 --- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java +++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java @@ -26,7 +26,6 @@ import org.sonar.api.SonarPlugin; import java.util.List; public class PmdPlugin extends SonarPlugin { - @SuppressWarnings("unchecked") public List<Class<? extends Extension>> getExtensions() { return ImmutableList.of( PmdSensor.class, diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java index 7a216b12c95..d973c0207d6 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java @@ -62,7 +62,7 @@ public abstract class DetectorTestCase { return new ClonePart(resourceId, unitStart, unitStart, unitStart + cloneUnitLength + LINES_PER_BLOCK - 1); } - protected abstract List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks); + protected abstract List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks); /** * Given: @@ -82,7 +82,7 @@ public abstract class DetectorTestCase { CloneIndex index = createIndex( newBlocks("y", "2 3 4 5"), newBlocks("z", "3 4")); - List<Block> fileBlocks = newBlocks("x", "1 2 3 4 5 6"); + Block[] fileBlocks = newBlocks("x", "1 2 3 4 5 6"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -116,7 +116,7 @@ public abstract class DetectorTestCase { CloneIndex cloneIndex = createIndex( newBlocks("a", "2 3 4 5"), newBlocks("b", "3 4")); - List<Block> fileBlocks = newBlocks("c", "1 2 3 4 5 6"); + Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6"); List<CloneGroup> clones = detect(cloneIndex, fileBlocks); print(clones); @@ -151,7 +151,7 @@ public abstract class DetectorTestCase { CloneIndex index = createIndex( newBlocks("b", "3 4 5 6"), newBlocks("c", "5 6 7")); - List<Block> fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9"); + Block[] fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -188,7 +188,7 @@ public abstract class DetectorTestCase { CloneIndex index = createIndex( newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"), newBlocks("c", "1 2 3 4")); - List<Block> fileBlocks = newBlocks("a", "1 2 3 5"); + Block[] fileBlocks = newBlocks("a", "1 2 3 5"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -216,7 +216,7 @@ public abstract class DetectorTestCase { @Test public void clonesInFileItself() { CloneIndex index = createIndex(); - List<Block> fileBlocks = newBlocks("a", "1 2 3 1 2 4"); + Block[] fileBlocks = newBlocks("a", "1 2 3 1 2 4"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -244,7 +244,7 @@ public abstract class DetectorTestCase { public void covered() { CloneIndex index = createIndex( newBlocks("b", "1 2 1 2")); - List<Block> fileBlocks = newBlocks("a", "1 2 1"); + Block[] fileBlocks = newBlocks("a", "1 2 1"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -276,7 +276,7 @@ public abstract class DetectorTestCase { public void problemWithNestedCloneGroups() { CloneIndex index = createIndex( newBlocks("b", "1 2 1 2 1 2 1")); - List<Block> fileBlocks = newBlocks("a", "1 2 1 2 1 2"); + Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -310,7 +310,7 @@ public abstract class DetectorTestCase { newBlocks("a", "1 2 3"), newBlocks("b", "1 2 4")); // Note about blocks with hashes "3", "4" and "5": those blocks here in order to not face another problem - with EOF (see separate test) - List<Block> fileBlocks = newBlocks("a", "1 2 5"); + Block[] fileBlocks = newBlocks("a", "1 2 5"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -328,7 +328,7 @@ public abstract class DetectorTestCase { @Test public void only_one_query_of_index_for_each_unique_hash() { CloneIndex index = spy(createIndex()); - List<Block> fileBlocks = newBlocks("a", "1 2 1 2"); + Block[] fileBlocks = newBlocks("a", "1 2 1 2"); detect(index, fileBlocks); verify(index).getBySequenceHash(new ByteArray("01")); @@ -342,7 +342,7 @@ public abstract class DetectorTestCase { */ @Test public void shouldReturnEmptyListWhenNoBlocksForFile() { - List<CloneGroup> result = detect(null, new ArrayList<Block>()); + List<CloneGroup> result = detect(null, new Block[0]); assertThat(result, sameInstance(Collections.EMPTY_LIST)); } @@ -361,7 +361,7 @@ public abstract class DetectorTestCase { public void problemWithEndOfFile() { CloneIndex cloneIndex = createIndex( newBlocks("b", "1 2 3 4")); - List<Block> fileBlocks = + Block[] fileBlocks = newBlocks("a", "1 2 3"); List<CloneGroup> clones = detect(cloneIndex, fileBlocks); @@ -393,10 +393,11 @@ public abstract class DetectorTestCase { Block.Builder block = Block.builder() .setResourceId("a") .setLines(0, 1); - List<Block> fileBlocks = Arrays.asList( - block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(), - block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(), - block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build()); + Block[] fileBlocks = new Block[] { + block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(), + block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(), + block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build() + }; List<CloneGroup> clones = detect(cloneIndex, fileBlocks); print(clones); @@ -418,7 +419,7 @@ public abstract class DetectorTestCase { System.out.println(); } - protected static List<Block> newBlocks(String resourceId, String hashes) { + protected static Block[] newBlocks(String resourceId, String hashes) { List<Block> result = Lists.newArrayList(); int indexInFile = 0; for (int i = 0; i < hashes.length(); i += 2) { @@ -426,12 +427,12 @@ public abstract class DetectorTestCase { result.add(block); indexInFile++; } - return result; + return result.toArray(new Block[result.size()]); } - protected static CloneIndex createIndex(List<Block>... blocks) { + protected static CloneIndex createIndex(Block[]... blocks) { CloneIndex cloneIndex = new MemoryCloneIndex(); - for (List<Block> b : blocks) { + for (Block[] b : blocks) { for (Block block : b) { cloneIndex.insert(block); } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java index 957a89de13a..78369d4d300 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithmTest.java @@ -19,6 +19,7 @@ */ package org.sonar.duplications.detector.original; +import java.util.Arrays; import java.util.List; import org.sonar.duplications.block.Block; @@ -29,8 +30,8 @@ import org.sonar.duplications.index.CloneIndex; public class OriginalCloneDetectionAlgorithmTest extends DetectorTestCase { @Override - protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) { - return OriginalCloneDetectionAlgorithm.detect(index, fileBlocks); + protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) { + return OriginalCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks)); } } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java index 996c22a96c7..dc1caa9db6a 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/suffixtree/SuffixTreeCloneDetectionAlgorithmTest.java @@ -19,14 +19,6 @@ */ package org.sonar.duplications.detector.suffixtree; -import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup; - -import java.util.Collections; -import java.util.List; - import org.junit.Test; import org.sonar.duplications.block.Block; import org.sonar.duplications.block.ByteArray; @@ -34,7 +26,14 @@ import org.sonar.duplications.detector.DetectorTestCase; import org.sonar.duplications.index.CloneGroup; import org.sonar.duplications.index.CloneIndex; -import com.google.common.collect.Lists; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup; public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { @@ -45,7 +44,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { @Test public void noDuplications() { CloneIndex index = createIndex(); - List<Block> fileBlocks = newBlocks("a", "1 2 3"); + Block[] fileBlocks = newBlocks("a", "1 2 3"); List<CloneGroup> result = detect(index, fileBlocks); assertThat(result, sameInstance(Collections.EMPTY_LIST)); } @@ -65,12 +64,9 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { @Test public void huge() { CloneIndex index = createIndex(); - List<Block> fileBlocks = Lists.newArrayList(); - int indexInFile = 0; + Block[] fileBlocks = new Block[5000]; for (int i = 0; i < 5000; i++) { - Block block = newBlock("x", new ByteArray("01"), indexInFile); - fileBlocks.add(block); - indexInFile++; + fileBlocks[i] = newBlock("x", new ByteArray("01"), i); } List<CloneGroup> result = detect(index, fileBlocks); @@ -92,7 +88,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { @Test public void myTest() { CloneIndex index = createIndex(); - List<Block> fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2"); + Block[] fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -128,7 +124,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { @Test public void myTest2() { CloneIndex index = createIndex(); - List<Block> fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3"); + Block[] fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -171,7 +167,7 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { newBlocks("b", "4 3 2"), newBlocks("c", "4 3 1") ); - List<Block> fileBlocks = newBlocks("a", "1 2 3 4"); + Block[] fileBlocks = newBlocks("a", "1 2 3 4"); List<CloneGroup> result = detect(index, fileBlocks); print(result); @@ -197,8 +193,8 @@ public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase { } @Override - protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) { - return SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks); + protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) { + return SuffixTreeCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks)); } } diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java index d509c8728f2..15e9aa6f08f 100644 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java +++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java @@ -19,6 +19,7 @@ */ package org.sonar.maven3; +import com.google.common.collect.Maps; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -39,8 +40,6 @@ import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.batch.bootstrapper.LoggingConfiguration; -import java.util.Map; - /** * @goal sonar * @aggregator @@ -144,7 +143,7 @@ public final class SonarMojo extends AbstractMojo { } private void configureLogging(LoggingConfiguration logging) { - logging.setProperties((Map) session.getSystemProperties()); + logging.setProperties(Maps.fromProperties(session.getSystemProperties())); logging.setFormat(LoggingConfiguration.FORMAT_MAVEN); if (getLog().isDebugEnabled()) { logging.setVerbose(true); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java index d49a7001028..1f2eedc3631 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/BatchExtensionDictionnary.java @@ -199,7 +199,7 @@ public class BatchExtensionDictionnary { return Phase.Name.DEFAULT; } - private void evaluateMethod(Object extension, Method method, List results) { + private void evaluateMethod(Object extension, Method method, List<Object> results) { try { Object result = method.invoke(extension); if (result != null) { @@ -207,8 +207,8 @@ public class BatchExtensionDictionnary { if (result instanceof Class) { results.addAll(componentContainer.getComponentsByType((Class) result)); - } else if (result instanceof Collection) { - results.addAll((Collection) result); + } else if (result instanceof Collection<?>) { + results.addAll((Collection<?>) result); } else { results.add(result); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/DefaultFormulaDataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/DefaultFormulaDataTest.java index b3d90477d53..f3fd0079ac1 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/DefaultFormulaDataTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/DefaultFormulaDataTest.java @@ -19,16 +19,19 @@ */ package org.sonar.api.batch; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; import org.junit.Test; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.Metric; import java.util.Arrays; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class DefaultFormulaDataTest { @Test @@ -36,17 +39,17 @@ public class DefaultFormulaDataTest { DecoratorContext context = mock(DecoratorContext.class); DefaultFormulaData data = new DefaultFormulaData(context); - data.getChildrenMeasures((MeasuresFilter) anyObject()); - verify(context).getChildrenMeasures((MeasuresFilter) anyObject()); + data.getChildrenMeasures(any(MeasuresFilter.class)); + verify(context).getChildrenMeasures(any(MeasuresFilter.class)); - data.getChildrenMeasures((Metric) anyObject()); - verify(context).getChildrenMeasures((Metric) anyObject()); + data.getChildrenMeasures(any(Metric.class)); + verify(context).getChildrenMeasures(any(Metric.class)); - data.getMeasures((MeasuresFilter) anyObject()); - verify(context).getMeasures((MeasuresFilter) anyObject()); + data.getMeasures(any(MeasuresFilter.class)); + verify(context).getMeasures(any(MeasuresFilter.class)); - data.getMeasure((Metric) anyObject()); - verify(context).getMeasure((Metric) anyObject()); + data.getMeasure(any(Metric.class)); + verify(context).getMeasure(any(Metric.class)); } @Test diff --git a/sonar-server/src/main/java/org/sonar/server/ui/Views.java b/sonar-server/src/main/java/org/sonar/server/ui/Views.java index f90787e60c7..9837410beba 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/Views.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/Views.java @@ -53,18 +53,18 @@ public class Views implements ServerComponent { } private void register(View view) { - ViewProxy proxy = new ViewProxy(view); if (view instanceof Widget) { + ViewProxy<Widget> proxy = new ViewProxy<Widget>((Widget) view); widgets.add(proxy); widgetsPerId.put(proxy.getId(), proxy); } else if (view instanceof Page) { + ViewProxy<Page> proxy = new ViewProxy<Page>((Page) view); pagesPerId.put(proxy.getId(), proxy); pages.add(proxy); } } - public ViewProxy<Page> getPage(String id) { return pagesPerId.get(id); } |