import org.sonar.core.component.ComponentKeys;
import org.sonar.core.component.ScanGraph;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import java.util.*;
public class DefaultIndex extends SonarIndex {
*/
@Override
public Measure addMeasure(Resource resource, Measure measure) {
- Bucket bucket = checkIndexed(resource);
+ Bucket bucket = getBucket(resource);
if (bucket != null) {
Metric metric = metricFinder.findByKey(measure.getMetricKey());
if (metric == null) {
@Override
public void setSource(Resource reference, String source) {
- Bucket bucket = checkIndexed(reference);
+ Bucket bucket = getBucket(reference);
if (bucket != null) {
persistence.setSource(reference, source);
}
}
@Override
- public <R extends Resource> R getResource(R reference) {
+ @CheckForNull
+ public <R extends Resource> R getResource(@Nullable R reference) {
Bucket bucket = getBucket(reference);
if (bucket != null) {
return (R) bucket.getResource();
return getBucket(reference, acceptExcluded) != null;
}
- private Bucket getBucket(Resource resource, boolean acceptExcluded) {
+ private Bucket getBucket(@Nullable Resource resource, boolean acceptExcluded) {
Bucket bucket = null;
if (resource != null) {
bucket = getBucket(resource);
}
@Test
- public void shouldIndexResourceWhenAddingMeasure() {
+ public void shouldNotIndexResourceWhenAddingMeasure() {
Resource dir = Directory.create("src/org/foo", "org/foo");
index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
- assertThat(index.isIndexed(dir, true)).isTrue();
- assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc")).getIntValue()).isEqualTo(50);
+ assertThat(index.isIndexed(dir, true)).isFalse();
+ assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull();
}
/**