aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java20
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java14
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java30
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java6
4 files changed, 53 insertions, 17 deletions
diff --git a/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java b/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java
index 0834a52850e..c68265a1d33 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/ChannelCodeReaderFilter.java
@@ -27,17 +27,26 @@ import java.io.Reader;
* declared for the CodeReader.
*
*/
-public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter {
+public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter<OUTPUT> {
@SuppressWarnings("unchecked")
private Channel<OUTPUT>[] channels = new Channel[0];
private CodeReader internalCodeReader;
- private OUTPUT output;
+ /**
+ * Creates a CodeReaderFilter that will use the provided Channels to filter the character stream it gets from its reader.
+ *
+ * @param channels
+ * the different channels
+ */
+ public ChannelCodeReaderFilter(Channel<OUTPUT>... channels) {
+ super();
+ this.channels = channels;
+ }
/**
- * Creates a CodeReaderFilter that will use the provided Channels to filter the character stream it gets from its reader. And optionaly,
+ * Creates a CodeReaderFilter that will use the provided Channels to filter the character stream it gets from its reader. And optionally,
* it can push token to the provided output object.
*
* @param output
@@ -46,9 +55,8 @@ public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter {
* the different channels
*/
public ChannelCodeReaderFilter(OUTPUT output, Channel<OUTPUT>... channels) {
- super();
+ super(output);
this.channels = channels;
- this.output = output;
}
/**
@@ -72,7 +80,7 @@ public final class ChannelCodeReaderFilter<OUTPUT> extends CodeReaderFilter {
}
boolean consumed = false;
for (Channel<OUTPUT> channel : channels) {
- if (channel.consume(internalCodeReader, output)) {
+ if (channel.consume(internalCodeReader, getOutput())) {
consumed = true;
break;
}
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 fcddb8d827f..d308a48104a 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
@@ -51,28 +51,28 @@ public class CodeBuffer implements CharSequence {
private boolean recordingMode = false;
private StringBuilder recordedCharacters = new StringBuilder();
- public CodeBuffer(Reader code, CodeReaderFilter... codeReaderFilters) {
+ public CodeBuffer(Reader code, CodeReaderFilter<?>... codeReaderFilters) {
this(code, DEFAULT_BUFFER_CAPACITY, codeReaderFilters);
}
- private CodeBuffer(Reader initialCodeReader, int bufferCapacity, CodeReaderFilter... codeReaderFilters) {
+ private CodeBuffer(Reader initialCodeReader, int bufferCapacity, CodeReaderFilter<?>... codeReaderFilters) {
lastChar = -1;
cursor = new Cursor();
this.bufferCapacity = bufferCapacity;
buffer = new char[bufferCapacity];
Reader reader = initialCodeReader;
- for (CodeReaderFilter codeReaderFilter : codeReaderFilters) {
+ for (CodeReaderFilter<?> codeReaderFilter : codeReaderFilters) {
reader = new Filter(reader, codeReaderFilter);
}
this.code = reader;
fillBuffer();
}
- public CodeBuffer(String code, CodeReaderFilter... codeReaderFilters) {
+ public CodeBuffer(String code, CodeReaderFilter<?>... codeReaderFilters) {
this(new StringReader(code), codeReaderFilters);
}
- protected CodeBuffer(String code, int bufferCapacity, CodeReaderFilter... codeReaderFilters) {
+ protected CodeBuffer(String code, int bufferCapacity, CodeReaderFilter<?>... codeReaderFilters) {
this(new StringReader(code), bufferCapacity, codeReaderFilters);
}
@@ -258,9 +258,9 @@ public class CodeBuffer implements CharSequence {
*/
final class Filter extends FilterReader {
- private CodeReaderFilter codeReaderFilter;
+ private CodeReaderFilter<?> codeReaderFilter;
- public Filter(Reader in, CodeReaderFilter codeReaderFilter) {
+ public Filter(Reader in, CodeReaderFilter<?> codeReaderFilter) {
super(in);
this.codeReaderFilter = codeReaderFilter;
this.codeReaderFilter.setReader(in);
diff --git a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java b/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java
index da5a1dcb4f3..7b5106b153f 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/CodeReaderFilter.java
@@ -33,10 +33,19 @@ import java.io.Reader;
* @see CodeBufferTest#testSeveralCodeReaderFilter()
*
*/
-public abstract class CodeReaderFilter {
+public abstract class CodeReaderFilter<OUTPUT> {
private Reader reader;
+ private OUTPUT output;
+
+ public CodeReaderFilter() {
+ }
+
+ public CodeReaderFilter(OUTPUT output) {
+ this.output = output;
+ }
+
/**
* Returns the reader from which this class reads the character stream.
*
@@ -57,6 +66,25 @@ public abstract class CodeReaderFilter {
}
/**
+ * Returns the output object.
+ *
+ * @return the output
+ */
+ public OUTPUT getOutput() {
+ return output;
+ }
+
+ /**
+ * Sets the output object
+ *
+ * @param output
+ * the output to set
+ */
+ public void setOutput(OUTPUT output) {
+ this.output = output;
+ }
+
+ /**
* This method implements the filtering logic, that is:
* <ul>
* <li>
diff --git a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
index 3807951eee0..ab1183806c0 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
@@ -178,7 +178,7 @@ public class CodeBufferTest {
public void testChannelCodeReaderFilter() throws Exception {
// create a windowing channel that drops the 2 first characters, keeps 6 characters and drops the rest of the line
@SuppressWarnings({ "rawtypes", "unchecked" })
- CodeBuffer code = new CodeBuffer("0123456789\nABCDEFGHIJ", new ChannelCodeReaderFilter(null, new WindowingChannel()));
+ CodeBuffer code = new CodeBuffer("0123456789\nABCDEFGHIJ", new ChannelCodeReaderFilter(new Object(), new WindowingChannel()));
// test #charAt
assertEquals('2', code.charAt(0));
assertEquals('7', code.charAt(5));
@@ -205,7 +205,7 @@ public class CodeBufferTest {
assertThat(code.pop(), is( -1));
}
- class ReplaceNumbersFilter extends CodeReaderFilter {
+ class ReplaceNumbersFilter extends CodeReaderFilter<Object> {
private Pattern pattern = Pattern.compile("\\d");
private String REPLACEMENT = "-";
@@ -221,7 +221,7 @@ public class CodeBufferTest {
}
}
- class ReplaceCharFilter extends CodeReaderFilter {
+ class ReplaceCharFilter extends CodeReaderFilter<Object> {
private Pattern pattern = Pattern.compile("[a-zA-Z]");
private String REPLACEMENT = "*";