use of org.sonar.plugins.web.node.Node 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());
}
use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method javaScriptWithComments.
@Test
public void javaScriptWithComments() throws FileNotFoundException {
String fileName = "src/test/resources/lexer/script-with-comments.jsp";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertEquals(3, nodeList.size());
}
use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.
the class PageLexerTest method javaScriptWithNestedTags.
@Test
public void javaScriptWithNestedTags() throws FileNotFoundException {
String fileName = "src/test/resources/lexer/javascript-nestedtags.jsp";
PageLexer lexer = new PageLexer();
List<Node> nodeList = lexer.parse(new FileReader(fileName));
assertEquals(12, nodeList.size());
// check script node
Node node = nodeList.get(2);
assertTrue(node instanceof TagNode);
TagNode scriptNode = (TagNode) node;
assertEquals("script", scriptNode.getNodeName());
assertEquals(0, scriptNode.getChildren().size());
}
use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.
the class PageCountLines method count.
private void count(List<Node> nodeList) {
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
Node previousNode = i > 0 ? nodeList.get(i - 1) : null;
Node nextNode = i < nodeList.size() - 1 ? nodeList.get(i) : null;
handleToken(node, previousNode, nextNode);
}
addMeasures();
}
use of org.sonar.plugins.web.node.Node in project sonar-web by SonarSource.
the class AbstractTokenizer method consume.
@Override
public boolean consume(CodeReader codeReader, T nodeList) {
if (equalsIgnoreCase(codeReader.peek(startChars.length), startChars)) {
Node node = createNode();
setStartPosition(codeReader, node);
StringBuilder stringBuilder = new StringBuilder();
codeReader.popTo(getEndMatcher(codeReader), stringBuilder);
for (int i = 0; i < endChars.length; i++) {
codeReader.pop(stringBuilder);
}
node.setCode(stringBuilder.toString());
setEndPosition(codeReader, node);
addNode(nodeList, node);
return true;
} else {
return false;
}
}
Aggregations