Search in sources :

Example 6 with Node

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());
}
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)

Example 7 with Node

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());
}
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) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 8 with Node

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());
}
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) FileReader(java.io.FileReader) TagNode(org.sonar.plugins.web.node.TagNode) Test(org.junit.Test)

Example 9 with Node

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();
}
Also used : Node(org.sonar.plugins.web.node.Node) TextNode(org.sonar.plugins.web.node.TextNode)

Example 10 with Node

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;
    }
}
Also used : Node(org.sonar.plugins.web.node.Node)

Aggregations

Node (org.sonar.plugins.web.node.Node)25 TagNode (org.sonar.plugins.web.node.TagNode)19 Test (org.junit.Test)18 TextNode (org.sonar.plugins.web.node.TextNode)17 CommentNode (org.sonar.plugins.web.node.CommentNode)15 DirectiveNode (org.sonar.plugins.web.node.DirectiveNode)15 StringReader (java.io.StringReader)10 FileReader (java.io.FileReader)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 File (java.io.File)3 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)3 ArrayList (java.util.ArrayList)2 CodeReader (org.sonar.channel.CodeReader)2 Attribute (org.sonar.plugins.web.node.Attribute)2 List (java.util.List)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)1 Channel (org.sonar.channel.Channel)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1