use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class TokenChunker method chunk.
public TokenQueue chunk(Reader reader) {
CodeReader code = new CodeReader(reader);
TokenQueue queue = new TokenQueue();
try {
channelDispatcher.consume(code, queue);
return queue;
} catch (Exception e) {
throw new DuplicationsException("Unable to lex source code at line : " + code.getLinePosition() + " and column : " + code.getColumnPosition(), e);
}
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class Markdown method convert.
private String convert(String input) {
CodeReader reader = new CodeReader(input);
MarkdownOutput output = new MarkdownOutput();
dispatcher.consume(reader, output);
return output.toString();
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class TokenChannelTest method shouldConsume.
@Test
public void shouldConsume() {
TokenChannel channel = new TokenChannel("ABC");
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("ABCD");
assertThat(channel.consume(codeReader, output), is(true));
ArgumentCaptor<Token> token = ArgumentCaptor.forClass(Token.class);
verify(output).add(token.capture());
assertThat(token.getValue(), is(new Token("ABC", 1, 0)));
verifyNoMoreInteractions(output);
assertThat(codeReader.getLinePosition(), is(1));
assertThat(codeReader.getColumnPosition(), is(3));
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class TokenChannelTest method shouldNormalize.
@Test
public void shouldNormalize() {
TokenChannel channel = new TokenChannel("ABC", "normalized");
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("ABCD");
assertThat(channel.consume(codeReader, output), is(true));
ArgumentCaptor<Token> token = ArgumentCaptor.forClass(Token.class);
verify(output).add(token.capture());
assertThat(token.getValue(), is(new Token("normalized", 1, 0)));
verifyNoMoreInteractions(output);
assertThat(codeReader.getLinePosition(), is(1));
assertThat(codeReader.getColumnPosition(), is(3));
}
use of org.sonar.channel.CodeReader in project sonar-web by SonarSource.
the class PageLexerTest method testDirectiveNode.
@Test
public void testDirectiveNode() {
String directive = "<!docTyPE html " + "PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
DoctypeTokenizer tokenizer = new DoctypeTokenizer("<!DOCTYPE", ">");
List<Node> nodeList = new ArrayList<>();
CodeReader codeReader = new CodeReader(directive);
tokenizer.consume(codeReader, nodeList);
assertEquals(nodeList.size(), 1);
Node node = nodeList.get(0);
assertEquals(node.getClass(), DirectiveNode.class);
DirectiveNode directiveNode = (DirectiveNode) node;
assertEquals(4, directiveNode.getAttributes().size());
}
Aggregations