Search in sources :

Example 1 with CodeReader

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);
    }
}
Also used : DuplicationsException(org.sonar.duplications.DuplicationsException) CodeReader(org.sonar.channel.CodeReader) DuplicationsException(org.sonar.duplications.DuplicationsException)

Example 2 with CodeReader

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();
}
Also used : CodeReader(org.sonar.channel.CodeReader)

Example 3 with CodeReader

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));
}
Also used : CodeReader(org.sonar.channel.CodeReader) Test(org.junit.Test)

Example 4 with CodeReader

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));
}
Also used : CodeReader(org.sonar.channel.CodeReader) Test(org.junit.Test)

Example 5 with CodeReader

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());
}
Also used : TagNode(org.sonar.plugins.web.node.TagNode) TextNode(org.sonar.plugins.web.node.TextNode) CommentNode(org.sonar.plugins.web.node.CommentNode) Node(org.sonar.plugins.web.node.Node) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) ArrayList(java.util.ArrayList) DirectiveNode(org.sonar.plugins.web.node.DirectiveNode) CodeReader(org.sonar.channel.CodeReader) Test(org.junit.Test)

Aggregations

CodeReader (org.sonar.channel.CodeReader)10 Test (org.junit.Test)6 TagNode (org.sonar.plugins.web.node.TagNode)3 ArrayList (java.util.ArrayList)2 Node (org.sonar.plugins.web.node.Node)2 List (java.util.List)1 Channel (org.sonar.channel.Channel)1 DuplicationsException (org.sonar.duplications.DuplicationsException)1 CommentNode (org.sonar.plugins.web.node.CommentNode)1 DirectiveNode (org.sonar.plugins.web.node.DirectiveNode)1 TextNode (org.sonar.plugins.web.node.TextNode)1