aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-channel/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-06-28 08:42:53 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-06-28 08:43:11 +0200
commit4e1655566e26035164f644b0a933e7c0e7891436 (patch)
tree7229e1f543abd0a76be2f2b34e313f6adfea760d /sonar-channel/src
parent595485bb2bf8b327cb50e24597894d97d28c178d (diff)
downloadsonarqube-4e1655566e26035164f644b0a933e7c0e7891436.tar.gz
sonarqube-4e1655566e26035164f644b0a933e7c0e7891436.zip
Add method ChannelDispatcher.Builder#addChannels(Channel...) + minor fixes
Diffstat (limited to 'sonar-channel/src')
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java17
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java2
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java18
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java6
4 files changed, 33 insertions, 10 deletions
diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java
index 58b8c95afba..d21ac683abd 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/ChannelDispatcher.java
@@ -36,7 +36,7 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
private final Channel[] channels;
/**
- * @deprecated please use the builder() method
+ * @deprecated in version 2.9. Please use the builder() method
*/
@SuppressWarnings("rawtypes")
@Deprecated
@@ -45,7 +45,7 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
}
/**
- * @deprecated please use the builder() method
+ * @deprecated in version 2.9. Please use the builder() method
*/
@SuppressWarnings("rawtypes")
@Deprecated
@@ -54,7 +54,7 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
}
/**
- * @deprecated please use the builder() method
+ * @deprecated in version 2.9. Please use the builder() method
*/
@SuppressWarnings("rawtypes")
@Deprecated
@@ -94,6 +94,10 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
return true;
}
+ Channel[] getChannels() {
+ return channels;
+ }
+
/**
* Get a Builder instance to build a new ChannelDispatcher
*/
@@ -114,6 +118,13 @@ public class ChannelDispatcher<OUTPUT> extends Channel<OUTPUT> {
return this;
}
+ public Builder addChannels(Channel... c) {
+ for (Channel channel : c) {
+ addChannel(channel);
+ }
+ return this;
+ }
+
/**
* If this option is activated, an IllegalStateException will be thrown as soon as a character won't be consumed by any channel.
*/
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
index 6373bb0ff40..7274181662e 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
@@ -48,13 +48,11 @@ public class CodeBuffer implements CharSequence {
private static final char LF = '\n';
private static final char CR = '\r';
private int tabWidth;
- private CodeReaderConfiguration configuration;
private boolean recordingMode = false;
private StringBuilder recordedCharacters = new StringBuilder();
protected CodeBuffer(Reader initialCodeReader, CodeReaderConfiguration configuration) {
- this.configuration = configuration;
lastChar = -1;
cursor = new Cursor();
bufferCapacity = configuration.getBufferCapacity();
diff --git a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
index 030d82feb70..f24761e8045 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
@@ -34,14 +34,21 @@ public class ChannelDispatcherTest {
assertThat(output.toString(), is("twowords"));
}
+ @Test
+ public void shouldAddChannels() {
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannels(new SpaceDeletionChannel(), new FakeChannel()).build();
+ assertThat(dispatcher.getChannels().length, is(2));
+ assertThat(dispatcher.getChannels()[0], is(SpaceDeletionChannel.class));
+ assertThat(dispatcher.getChannels()[1], is(FakeChannel.class));
+ }
+
@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionWhenNoChannelToConsumeNextCharacter() {
ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().failIfNoChannelToConsumeOneCharacter().build();
dispatcher.consume(new CodeReader("two words"), new StringBuilder());
}
- private class SpaceDeletionChannel extends Channel<StringBuilder> {
-
+ private static class SpaceDeletionChannel extends Channel<StringBuilder> {
@Override
public boolean consume(CodeReader code, StringBuilder output) {
if (code.peek() == ' ') {
@@ -51,6 +58,13 @@ public class ChannelDispatcherTest {
}
return true;
}
+ }
+ private static class FakeChannel extends Channel<StringBuilder> {
+ @Override
+ public boolean consume(CodeReader code, StringBuilder output) {
+ return true;
+ }
}
+
}
diff --git a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
index 7fb5c3a11ab..35d9c936b78 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
@@ -28,13 +28,13 @@ public class RegexChannelTest {
@Test
public void shouldMatch() {
- ChannelDispatcher<StringBuilder> dispatcher = new ChannelDispatcher<StringBuilder>(new MyWordChannel(), new BlackholeChannel());
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannel(new MyWordChannel()).addChannel(new BlackholeChannel()).build();
StringBuilder output = new StringBuilder();
dispatcher.consume(new CodeReader("my word"), output);
assertThat(output.toString(), is("<w>my</w> <w>word</w>"));
}
- private class MyWordChannel extends RegexChannel<StringBuilder> {
+ private static class MyWordChannel extends RegexChannel<StringBuilder> {
public MyWordChannel() {
super("\\w++");
@@ -46,7 +46,7 @@ public class RegexChannelTest {
}
}
- class BlackholeChannel extends Channel<StringBuilder> {
+ private static class BlackholeChannel extends Channel<StringBuilder> {
@Override
public boolean consume(CodeReader code, StringBuilder output) {