summaryrefslogtreecommitdiffstats
path: root/sonar-channel
diff options
context:
space:
mode:
authorfmallet <freddy.mallet@gmail.com>2010-11-25 20:23:16 +0000
committerfmallet <freddy.mallet@gmail.com>2010-11-25 20:23:16 +0000
commit9e6291e748bd2020d82989e8344f98305ee34b91 (patch)
treee10d6bb810e82028181cb6291be747e4637e6a02 /sonar-channel
parent8ccd8b6a76f817de4fee9ed539648fd118a5f034 (diff)
downloadsonarqube-9e6291e748bd2020d82989e8344f98305ee34b91.tar.gz
sonarqube-9e6291e748bd2020d82989e8344f98305ee34b91.zip
fix SONAR-2010 : the Integer.MAX_VALUE is returned only when the buffer can't contain all characters.
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;
}