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++) {
/**
* Save a stateful variable.
- *
+ *
* @param key
* can NOT be null
* @param value
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);
}
}
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, "", "");