use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLinesHtmlFile.
@Test
public void testCountLinesHtmlFile() {
List<Node> nodeList = lexer.parse(readFile("checks/AvoidHtmlCommentCheck/document.html"));
HtmlSourceCode htmlSourceCode = createHtmlSourceCode("test/document.html");
scanner.scan(nodeList, htmlSourceCode);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(8);
assertThat(htmlSourceCode.getDetailedLinesOfCode()).containsOnly(1, 2, 3, 4, 6, 7, 8, 9);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(1);
}
use of org.sonar.plugins.html.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 + 1) : null;
handleToken(node, previousNode, nextNode);
}
addMeasures();
}
use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class ElementTokenizer method parseNestedTag.
/**
* Parse a nested tag with PageLexer.
* The nested tag is added as an attribute to its parent element.
*/
private static void parseNestedTag(CodeReader codeReader, TagNode element) {
PageLexer nestedPageLexer = new PageLexer();
List<Node> nodeList = nestedPageLexer.nestedParse(codeReader);
// add the nested tags as attribute.
for (Node node : nodeList) {
element.getAttributes().add(new Attribute(node.getCode()));
}
}
use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class VueLexer method parse.
@Override
public List<Node> parse(Reader reader) {
List<Node> nodes = super.parse(reader);
boolean firstTemplateTag = true;
List<Node> templateNodes = new LinkedList<>();
Deque<Object> templateLevels = new LinkedList<>();
for (Node node : nodes) {
if (node.getNodeType() == NodeType.TAG) {
TagNode tagNode = (TagNode) node;
if (tagNode.equalsElementName(TEMPLATE)) {
if (tagNode.isEndElement()) {
if (!templateLevels.isEmpty()) {
templateLevels.pop();
if (templateLevels.isEmpty()) {
break;
}
}
} else if (!tagNode.hasEnd()) {
templateLevels.push(TEMPLATE_LEVEL);
}
}
}
if (!templateLevels.isEmpty()) {
if (firstTemplateTag) {
firstTemplateTag = false;
} else {
templateNodes.add(node);
}
}
}
return templateNodes;
}
use of org.sonar.plugins.html.node.Node in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLines.
@Test
public void testCountLines() {
List<Node> nodeList = lexer.parse(readFile("src/main/webapp/user-properties.jsp"));
assertThat(nodeList.size()).isGreaterThan(100);
HtmlSourceCode htmlSourceCode = createHtmlSourceCode("test/user-properties.jsp");
scanner.scan(nodeList, htmlSourceCode);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(224);
assertThat(htmlSourceCode.getDetailedLinesOfCode().size()).isEqualTo(224);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(14);
}
Aggregations