diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 10:53:39 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-20 15:05:18 +0100 |
commit | 54beb6267d98d4e7429480bfbfaa70c8d1f73eff (patch) | |
tree | 996bac5291ac026eb7ce3d4fde217f4c5d300f55 /plugins | |
parent | 884231b56a62223f15a52e98eb9ad1fcc0dcaefe (diff) | |
download | sonarqube-54beb6267d98d4e7429480bfbfaa70c8d1f73eff.tar.gz sonarqube-54beb6267d98d4e7429480bfbfaa70c8d1f73eff.zip |
SONAR-5931 Cleanup highlighting API
Diffstat (limited to 'plugins')
2 files changed, 11 insertions, 8 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java index 549a655573e..8daffb64026 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java @@ -26,7 +26,7 @@ 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.highlighting.HighlightingBuilder; +import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -54,7 +54,7 @@ public class SyntaxHighlightingSensor implements Sensor { try { List<String> lines = FileUtils.readLines(highlightingFile, context.fileSystem().encoding().name()); int lineNumber = 0; - HighlightingBuilder highlightingBuilder = context.highlightingBuilder(inputFile); + NewHighlighting highlightingBuilder = context.newHighlighting().onFile(inputFile); for (String line : lines) { lineNumber++; if (StringUtils.isBlank(line) || line.startsWith("#")) { @@ -62,14 +62,14 @@ public class SyntaxHighlightingSensor implements Sensor { } processLine(highlightingFile, lineNumber, highlightingBuilder, line); } - highlightingBuilder.done(); + highlightingBuilder.save(); } catch (IOException e) { throw new IllegalStateException(e); } } } - private void processLine(File highlightingFile, int lineNumber, HighlightingBuilder highlightingBuilder, String line) { + private void processLine(File highlightingFile, int lineNumber, NewHighlighting highlightingBuilder, 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/SyntaxHighlightingSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java index 559f6b37b08..4bd8aa2da61 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java @@ -24,16 +24,18 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.fs.InputFile; 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.highlighting.HighlightingBuilder; +import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import java.io.File; import java.io.IOException; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -74,13 +76,14 @@ public class SyntaxHighlightingSensorTest { FileUtils.write(symbol, "1:4:k\n12:15:cppd\n\n#comment"); DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo"); fileSystem.add(inputFile); - HighlightingBuilder builder = mock(HighlightingBuilder.class); - when(context.highlightingBuilder(inputFile)).thenReturn(builder); + NewHighlighting builder = mock(NewHighlighting.class); + when(context.newHighlighting()).thenReturn(builder); + when(builder.onFile(any(InputFile.class))).thenReturn(builder); sensor.execute(context); verify(builder).highlight(1, 4, TypeOfText.KEYWORD); verify(builder).highlight(12, 15, TypeOfText.CPP_DOC); - verify(builder).done(); + verify(builder).save(); } } |