use of org.sonar.channel.CodeReader in project sonar-web by SonarSource.
the class ElementTokenizer method parseToken.
private void parseToken(Node node) {
TagNode element = (TagNode) node;
CodeReader codeReader = new CodeReader(node.getCode());
ParseMode mode = ParseMode.BEFORE_NODE_NAME;
for (int ch = codeReader.peek(); ch != -1; ch = codeReader.peek()) {
// handle white space
if (Character.isWhitespace(ch)) {
codeReader.pop();
continue;
}
// handle special characters
switch(ch) {
case '=':
mode = ParseMode.BEFORE_ATTRIBUTE_VALUE;
codeReader.pop();
continue;
case '<':
nestedTag(element, codeReader, mode);
continue;
case '>':
case '/':
case '%':
case '@':
codeReader.pop();
continue;
default:
break;
}
mode = parseToken(mode, codeReader, element);
}
}
use of org.sonar.channel.CodeReader in project sonar-web by SonarSource.
the class PageLexer method parse.
/**
* Parse the input into a list of tokens, with parent/child relations between the tokens.
*/
public List<Node> parse(Reader reader) {
// CodeReader reads the file stream
CodeReader codeReader = new CodeReader(reader);
// ArrayList collects the nodes
List<Node> nodeList = new ArrayList<>();
// ChannelDispatcher manages the tokenizers
ChannelDispatcher<List<Node>> channelDispatcher = ChannelDispatcher.builder().addChannels((Channel[]) tokenizers.toArray(new Channel[tokenizers.size()])).build();
channelDispatcher.consume(codeReader, nodeList);
createNodeHierarchy(nodeList);
return nodeList;
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class BlackHoleTokenChannelTest method shouldConsume.
@Test
public void shouldConsume() {
BlackHoleTokenChannel channel = new BlackHoleTokenChannel("ABC");
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("ABCD");
assertThat(channel.consume(codeReader, output)).isTrue();
assertThat(codeReader.getLinePosition()).isEqualTo(1);
assertThat(codeReader.getColumnPosition()).isEqualTo(3);
verifyZeroInteractions(output);
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class TokenChannelTest method shouldNotConsume.
@Test
public void shouldNotConsume() {
TokenChannel channel = new TokenChannel("ABC");
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("123");
assertThat(channel.consume(new CodeReader("123"), output), is(false));
verifyZeroInteractions(output);
assertThat(codeReader.getLinePosition(), is(1));
assertThat(codeReader.getColumnPosition(), is(0));
}
use of org.sonar.channel.CodeReader in project sonarqube by SonarSource.
the class TokenChannelTest method shouldCorrectlyDeterminePositionWhenTokenSpansMultipleLines.
@Test
public void shouldCorrectlyDeterminePositionWhenTokenSpansMultipleLines() {
TokenChannel channel = new TokenChannel("AB\nC");
TokenQueue output = mock(TokenQueue.class);
CodeReader codeReader = new CodeReader("AB\nCD");
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("AB\nC", 1, 0)));
verifyNoMoreInteractions(output);
assertThat(codeReader.getLinePosition(), is(2));
assertThat(codeReader.getColumnPosition(), is(1));
}
Aggregations