summaryrefslogtreecommitdiffstats
path: root/sonar-channel
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-channel')
-rw-r--r--sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java15
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java15
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java1
3 files changed, 22 insertions, 9 deletions
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 acabfb14467..0b5a72822ba 100644
--- a/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
+++ b/sonar-channel/src/main/java/org/sonar/channel/CodeBuffer.java
@@ -93,7 +93,7 @@ public class CodeBuffer implements CharSequence {
return character;
}
- private final void updateCursorPosition(int character) {
+ private void updateCursorPosition(int character) {
if (character == LF || character == CR) {
if ((lastChar != LF && lastChar != CR) || lastChar == character || lastChar == LF) {
cursor.line++;
@@ -241,15 +241,14 @@ public class CodeBuffer implements CharSequence {
}
/**
- * Warning : this method always returns Integer.MAX_VALUE
- * as the length of the stream can't be known before having consumed
- * all characters.
+ * Warning : this method always returns Integer.MAX_VALUE as the length of the stream can't be known before having consumed all
+ * characters.
*
- * Integer.MAX_VALUE is returned to prevent regular expression matchers
- * to stop consuming the stream of characters (see http://jira.codehaus.org/browse/SONAR-2010)
+ * Integer.MAX_VALUE is returned to prevent regular expression matchers to stop consuming the stream of characters (see
+ * http://jira.codehaus.org/browse/SONAR-2010)
*/
public final int length() {
- return Integer.MAX_VALUE;
+ return (bufferSize == bufferCapacity ? Integer.MAX_VALUE : bufferSize);
}
public final CharSequence subSequence(int start, int end) {
@@ -267,7 +266,7 @@ public class CodeBuffer implements CharSequence {
return result.toString();
}
- public final class Cursor {
+ public final class Cursor implements Cloneable {
private int line = 1;
private int column = 0;
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 98ffb19af42..840a7f46f03 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/CodeBufferTest.java
@@ -195,6 +195,20 @@ public class CodeBufferTest {
}
@Test
+ public void theLengthShouldBeTheSameThanTheStringLength() {
+ String myCode = "myCode";
+ assertThat(new CodeBuffer(myCode, new CodeReaderConfiguration()).length(), is(myCode.length()));
+ }
+
+ @Test
+ public void theLengthShouldBeIntegerMaxValueWhenTheBufferCantContainAllCharacters() {
+ String myCode = "myCode";
+ CodeReaderConfiguration conf = new CodeReaderConfiguration();
+ conf.setBufferCapacity(2);
+ assertThat(new CodeBuffer(myCode, conf).length(), is(Integer.MAX_VALUE));
+ }
+
+ @Test
public void testSeveralCodeReaderFilter() throws Exception {
CodeReaderConfiguration configuration = new CodeReaderConfiguration();
configuration.setCodeReaderFilters(new ReplaceNumbersFilter(), new ReplaceCharFilter());
@@ -304,5 +318,4 @@ public class CodeBufferTest {
return false;
}
}
-
}
diff --git a/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java b/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java
index 874abd0033c..0064443fd05 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/CodeReaderTest.java
@@ -71,6 +71,7 @@ public class CodeReaderTest {
CodeReader reader = new CodeReader(new StringReader("package org.sonar;"));
StringBuilder result = new StringBuilder();
reader.popTo(new EndMatcher() {
+
public boolean match(int endFlag) {
return 'r' == (char) endFlag;
}