aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2016-06-30 15:05:16 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-07-01 09:39:04 +0200
commit6f6d435949e41f7abf8c09a513381f0e4c8d6189 (patch)
treec1fadf67dbd9c3f56789ca47ac10353dea65ae88 /sonar-plugin-api
parentd1b715bfd572f5554181cf6e9ce29e24ac2f8ff3 (diff)
downloadsonarqube-6f6d435949e41f7abf8c09a513381f0e4c8d6189.tar.gz
sonarqube-6f6d435949e41f7abf8c09a513381f0e4c8d6189.zip
SONAR-7850 Improve SensorContextTester to differentiate no symbol from no
references
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java7
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java11
2 files changed, 13 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index 6906d3ca850..71a35021a28 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -271,12 +271,13 @@ public class SensorContextTester implements SensorContext {
* @param componentKey Key of the file like 'myProjectKey:src/foo.php'
* @param line Line you want to query
* @param lineOffset Offset you want to query.
- * @return List of references for the symbol or empty list if there is no symbol at this position or if there is no reference for this symbol.
+ * @return List of references for the symbol (potentially empty) or null if there is no symbol at this position.
*/
+ @CheckForNull
public Collection<TextRange> referencesForSymbolAt(String componentKey, int line, int lineOffset) {
DefaultSymbolTable symbolTable = sensorStorage.symbolsPerComponent.get(componentKey);
if (symbolTable == null) {
- return Collections.emptyList();
+ return null;
}
DefaultTextPointer location = new DefaultTextPointer(line, lineOffset);
for (Map.Entry<TextRange, Set<TextRange>> symbol : symbolTable.getReferencesBySymbol().entrySet()) {
@@ -284,7 +285,7 @@ public class SensorContextTester implements SensorContext {
return symbol.getValue();
}
}
- return Collections.emptyList();
+ return null;
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
index c8c983b87be..75d49b3a7b3 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
@@ -142,15 +142,22 @@ public class SensorContextTesterTest {
@Test
public void testSymbolReferences() {
- assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)).isEmpty();
+ assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull();
+
NewSymbolTable symbolTable = tester.newSymbolTable()
.onFile(new DefaultInputFile("foo", "src/Foo.java").initMetadata(new FileMetadata().readMetadata(new StringReader("annot dsf fds foo bar"))));
symbolTable
- .newSymbol(1, 0, 1, 5)
+ .newSymbol(1, 8, 1, 10);
+
+ symbolTable
+ .newSymbol(1, 1, 1, 5)
.newReference(6, 9)
.newReference(1, 10, 1, 13);
symbolTable.save();
+
+ assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull();
+ assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 8)).isEmpty();
assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)).extracting("start.line", "start.lineOffset", "end.line", "end.lineOffset").containsExactly(tuple(1, 6, 1, 9),
tuple(1, 10, 1, 13));
}