use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class CdataTokenizer method createNode.
@Override
Node createNode() {
TagNode node = new TagNode();
node.setNodeName("![CDATA[");
return node;
}
use of org.sonar.plugins.html.node.TagNode 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.TagNode 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.TagNode in project sonar-web by SonarSource.
the class UnclosedTagCheck method endElement.
@Override
public void endElement(TagNode element) {
if (skipFile) {
return;
}
if (isNotIgnoreTag(element) && !nodes.isEmpty()) {
TagNode previousNode = nodes.remove(0);
if (!previousNode.getNodeName().equals(element.getNodeName())) {
createViolation(previousNode, "The tag \"" + previousNode.getNodeName() + "\" has no corresponding closing tag.");
List<TagNode> rollup = new ArrayList<>();
for (TagNode node : nodes) {
rollup.add(node);
if (node.getNodeName().equals(element.getNodeName())) {
nodes.removeAll(rollup);
break;
}
}
}
}
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexer method createNodeHierarchy.
/**
* Scan the nodes and build the hierarchy of parent and child nodes.
*/
private static void createNodeHierarchy(List<Node> nodeList) {
Deque<TagNode> openElementStack = new ArrayDeque<>();
for (Node node : nodeList) {
if (node.getNodeType() != NodeType.TAG) {
continue;
}
TagNode element = (TagNode) node;
// start element
if (!element.isEndElement()) {
TagNode parent = openElementStack.peek();
while (parent != null && (shouldCloseParent(nodeName(element), nodeName(parent)) || isVoidElement(parent))) {
openElementStack.pop();
parent = openElementStack.peek();
}
element.setParent(parent);
openElementStack.push(element);
}
// end element
if (isEndElement(element) && !openElementStack.isEmpty()) {
TagNode openElement = openElementStack.peek();
if (openElement.equalsElementName(element.getNodeName())) {
openElementStack.pop();
} else {
// non-well formed, close HTML elements if there is matching open element
if (openElementStack.stream().anyMatch(tag -> tag.equalsElementName(element.getNodeName()))) {
while (!openElement.equalsElementName(element.getNodeName()) && isHtmlElement(openElement)) {
openElement = openElementStack.pop();
}
}
}
}
}
}
Aggregations