diff options
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, "", ""); |