diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-07-11 00:40:00 +0600 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-07-11 00:48:54 +0600 |
commit | 747425b29ed43f41c1d55a0a93610f8e19076db3 (patch) | |
tree | 724f2b5eaa07991807d5400fbfac45d896179fae /sonar-colorizer | |
parent | 28c9f88fc9ceb6c29d91c8422bbdd4aa71a425ef (diff) | |
download | sonarqube-747425b29ed43f41c1d55a0a93610f8e19076db3.tar.gz sonarqube-747425b29ed43f41c1d55a0a93610f8e19076db3.zip |
SONAR-3531 Allow to use two instances of MultilinesDocTokenizer without subclassing
Diffstat (limited to 'sonar-colorizer')
3 files changed, 17 insertions, 8 deletions
diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java index ed6d6b4c832..83350fd433b 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlCodeBuilder.java @@ -25,7 +25,7 @@ import java.util.Map; public class HtmlCodeBuilder implements Appendable { private StringBuilder colorizedCode = new StringBuilder(); - private Map variables = new HashMap(); // stateful data + private Map variables = new HashMap(); public Appendable append(CharSequence csq) { for (int i = 0; i < csq.length(); i++) { @@ -67,7 +67,7 @@ public class HtmlCodeBuilder implements Appendable { /** * Save a stateful variable. - * + * * @param key * can NOT be null * @param value diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java index 5471bcc4fc8..f77f2bd7dd4 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/MultilinesDocTokenizer.java @@ -104,16 +104,12 @@ public class MultilinesDocTokenizer extends Tokenizer { private boolean isCommentStartedOnPreviousLine(HtmlCodeBuilder codeBuilder) { Boolean b = (Boolean) codeBuilder.getVariable(COMMENT_STARTED_ON_PREVIOUS_LINE, Boolean.FALSE); - return (b == Boolean.TRUE) && (getTokenizerId().equals(codeBuilder.getVariable(COMMENT_TOKENIZER))); + return (b == Boolean.TRUE) && (this.equals(codeBuilder.getVariable(COMMENT_TOKENIZER))); } private void setCommentStartedOnPreviousLine(HtmlCodeBuilder codeBuilder, Boolean b) { codeBuilder.setVariable(COMMENT_STARTED_ON_PREVIOUS_LINE, b); - codeBuilder.setVariable(COMMENT_TOKENIZER, b ? getTokenizerId() : null); - } - - private String getTokenizerId() { - return getClass().getSimpleName(); + codeBuilder.setVariable(COMMENT_TOKENIZER, b ? this : null); } } diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/MultilinesDocTokenizerTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/MultilinesDocTokenizerTest.java index 8265efae16c..bf77bfe8b4f 100644 --- a/sonar-colorizer/src/test/java/org/sonar/colorizer/MultilinesDocTokenizerTest.java +++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/MultilinesDocTokenizerTest.java @@ -83,6 +83,19 @@ public class MultilinesDocTokenizerTest { assertThat(codeBuilder.toString()).isEqualTo("<!-- multi-line comment-->"); } + /** + * SONAR-3531 + */ + @Test + public void should_be_possible_to_use_two_instances() { + CodeReader reader = new CodeReader("<!-- multi-line comment\n--> private part"); + MultilinesDocTokenizer tokenizer1 = new MultiLineDocTokenizerImpl("<!--", "-->"); + MultilinesDocTokenizer tokenizer2 = new MultiLineDocTokenizerImpl("<!--", "-->"); + assertThat(tokenizer1.consume(reader, codeBuilder)).isTrue(); + reader.pop(); + assertThat(tokenizer2.consume(reader, codeBuilder)).isFalse(); + } + public class MultiLineDocTokenizerImpl extends MultilinesDocTokenizer { public MultiLineDocTokenizerImpl(String startToken, String endToken) { super(startToken, endToken, "", ""); |