aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-20 11:09:49 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-20 15:05:18 +0100
commit38357bb24905509dd775e40bdf09e40aec6af39c (patch)
treee7043ad143fdf642764b6244dedba4336ee1af09 /plugins/sonar-xoo-plugin
parent54beb6267d98d4e7429480bfbfaa70c8d1f73eff (diff)
downloadsonarqube-38357bb24905509dd775e40bdf09e40aec6af39c.tar.gz
sonarqube-38357bb24905509dd775e40bdf09e40aec6af39c.zip
SONAR-5931 Cleanup symbol reference API
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java19
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java15
2 files changed, 24 insertions, 10 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 5cc2ea832f9..118fe828243 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
@@ -26,8 +26,9 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
-import org.sonar.api.batch.sensor.symbol.Symbol;
-import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
+import org.sonar.api.component.ResourcePerspectives;
+import org.sonar.api.source.Symbol;
+import org.sonar.api.source.Symbolizable;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
@@ -42,6 +43,12 @@ import java.util.List;
*/
public class SymbolReferencesSensor implements Sensor {
+ private ResourcePerspectives perspectives;
+
+ public SymbolReferencesSensor(ResourcePerspectives perspectives) {
+ this.perspectives = perspectives;
+ }
+
private static final Logger LOG = Loggers.get(SymbolReferencesSensor.class);
private static final String SYMBOL_EXTENSION = ".symbol";
@@ -54,7 +61,9 @@ public class SymbolReferencesSensor implements Sensor {
try {
List<String> lines = FileUtils.readLines(symbolFile, context.fileSystem().encoding().name());
int lineNumber = 0;
- SymbolTableBuilder symbolTableBuilder = context.symbolTableBuilder(inputFile);
+ Symbolizable symbolizable = perspectives.as(Symbolizable.class, inputFile);
+
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder();
for (String line : lines) {
lineNumber++;
if (StringUtils.isBlank(line) || line.startsWith("#")) {
@@ -62,14 +71,14 @@ public class SymbolReferencesSensor implements Sensor {
}
processLine(symbolFile, lineNumber, symbolTableBuilder, line);
}
- symbolTableBuilder.done();
+ symbolizable.setSymbolTable(symbolTableBuilder.build());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
- private void processLine(File symbolFile, int lineNumber, SymbolTableBuilder symbolTableBuilder, String line) {
+ private 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());
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 5673221a46e..332629c8469 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
@@ -28,8 +28,9 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.batch.sensor.symbol.Symbol;
-import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
+import org.sonar.api.component.ResourcePerspectives;
+import org.sonar.api.source.Symbol;
+import org.sonar.api.source.Symbolizable;
import java.io.File;
import java.io.IOException;
@@ -47,11 +48,13 @@ public class SymbolReferencesSensorTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private File baseDir;
+ private ResourcePerspectives perspectives;
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- sensor = new SymbolReferencesSensor();
+ perspectives = mock(ResourcePerspectives.class);
+ sensor = new SymbolReferencesSensor(perspectives);
fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -74,8 +77,10 @@ public class SymbolReferencesSensorTest {
FileUtils.write(symbol, "1,4,7\n12,15,23\n\n#comment");
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
- SymbolTableBuilder symbolTableBuilder = mock(SymbolTableBuilder.class);
- when(context.symbolTableBuilder(inputFile)).thenReturn(symbolTableBuilder);
+ Symbolizable symbolizable = mock(Symbolizable.class);
+ when(perspectives.as(Symbolizable.class, inputFile)).thenReturn(symbolizable);
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = mock(Symbolizable.SymbolTableBuilder.class);
+ when(symbolizable.newSymbolTableBuilder()).thenReturn(symbolTableBuilder);
Symbol symbol1 = mock(Symbol.class);
when(symbolTableBuilder.newSymbol(1, 4)).thenReturn(symbol1);