aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java27
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java4
2 files changed, 25 insertions, 6 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
index 66573470ddb..62927ccda7e 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
@@ -81,17 +81,36 @@ public class SymbolReferencesSensor implements Sensor {
private static void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) {
try {
Iterator<String> split = Splitter.on(",").split(line).iterator();
- int startOffset = Integer.parseInt(split.next());
- int endOffset = Integer.parseInt(split.next());
- Symbol s = symbolTableBuilder.newSymbol(startOffset, endOffset);
+
+ Symbol s = addSymbol(symbolTableBuilder, split.next());
while (split.hasNext()) {
- symbolTableBuilder.newReference(s, Integer.parseInt(split.next()));
+ addReference(symbolTableBuilder, s, split.next());
}
} catch (Exception e) {
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e);
}
}
+ private static void addReference(Symbolizable.SymbolTableBuilder symbolTableBuilder, Symbol s, String str) {
+ if (str.contains(":")) {
+ Iterator<String> split = Splitter.on(":").split(str).iterator();
+ int startOffset = Integer.parseInt(split.next());
+ int toOffset = Integer.parseInt(split.next());
+ symbolTableBuilder.newReference(s, startOffset, toOffset);
+ } else {
+ symbolTableBuilder.newReference(s, Integer.parseInt(str));
+ }
+ }
+
+ private static Symbol addSymbol(Symbolizable.SymbolTableBuilder symbolTableBuilder, String str) {
+ Iterator<String> split = Splitter.on(":").split(str).iterator();
+
+ int startOffset = Integer.parseInt(split.next());
+ int endOffset = Integer.parseInt(split.next());
+
+ return symbolTableBuilder.newSymbol(startOffset, endOffset);
+ }
+
@Override
public void describe(SensorDescriptor descriptor) {
descriptor
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
index 332629c8469..d42ab2e5a79 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
@@ -74,7 +74,7 @@ public class SymbolReferencesSensorTest {
@Test
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.symbol");
- FileUtils.write(symbol, "1,4,7\n12,15,23\n\n#comment");
+ FileUtils.write(symbol, "1:4,7\n12:15,23:33\n\n#comment");
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
Symbolizable symbolizable = mock(Symbolizable.class);
@@ -92,7 +92,7 @@ public class SymbolReferencesSensorTest {
verify(symbolTableBuilder).newSymbol(1, 4);
verify(symbolTableBuilder).newReference(symbol1, 7);
verify(symbolTableBuilder).newSymbol(12, 15);
- verify(symbolTableBuilder).newReference(symbol2, 23);
+ verify(symbolTableBuilder).newReference(symbol2, 23, 33);
}
}