Search in sources :

Example 1 with ParseResults

use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.

the class PropertiesAntlrParserTest method testCommentLine.

private void testCommentLine(String text, String expectedComment) {
    ParseResults results = parser.parse(text);
    assertTrue(results.syntaxErrors.isEmpty());
    assertTrue(results.problems.isEmpty());
    assertEquals(1, results.ast.getAllNodes().size());
    List<Comment> commentLines = results.ast.getNodes(Comment.class);
    assertEquals(1, commentLines.size());
    Comment comment = commentLines.get(0);
    assertEquals(expectedComment, text.substring(comment.getOffset(), comment.getOffset() + comment.getLength()));
}
Also used : Comment(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Comment) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults)

Example 2 with ParseResults

use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.

the class PropertiesAstTest method positionEmptyLine.

@Test
public void positionEmptyLine() throws Exception {
    ParseResults results = parser.parse("# Comment\n" + "key  = value\n" + "\t\n");
    Node node = results.ast.findNode(23);
    assertTrue(node instanceof EmptyLine);
    assertTrue(node.getOffset() <= 23 && 23 <= node.getOffset() + node.getLength());
    node = results.ast.findNode(24);
    assertTrue(node instanceof EmptyLine);
    assertTrue(node.getOffset() <= 24 && 24 <= node.getOffset() + node.getLength());
}
Also used : Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) EmptyLine(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.EmptyLine) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 3 with ParseResults

use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.

the class PropertiesAstTest method positionValueEofAtEnd.

@Test
public void positionValueEofAtEnd() throws Exception {
    ParseResults results = parser.parse("# Comment\n" + "key  = value");
    Node node = results.ast.findNode(22);
    assertTrue(node instanceof Value);
    assertTrue(node.getOffset() <= 22 && 22 <= node.getOffset() + node.getLength());
    node = results.ast.findNode(16);
    assertTrue(node instanceof Value);
    assertTrue(node.getOffset() <= 16 && 16 <= node.getOffset() + node.getLength());
}
Also used : Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 4 with ParseResults

use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.

the class PropertiesAstTest method positionComment.

@Test
public void positionComment() throws Exception {
    ParseResults results = parser.parse("# Comment\n" + "key  = value\n");
    Node node = results.ast.findNode(7);
    assertTrue(node instanceof Comment);
    assertTrue(node.getOffset() <= 7 && 7 <= node.getOffset() + node.getLength());
    node = results.ast.findNode(9);
    assertTrue(node instanceof Comment);
    assertTrue(node.getOffset() <= 9 && 9 <= node.getOffset() + node.getLength());
    node = results.ast.findNode(0);
    assertTrue(node instanceof Comment);
    assertTrue(node.getOffset() <= 0 && 0 <= node.getOffset() + node.getLength());
}
Also used : Comment(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Comment) Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 5 with ParseResults

use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.

the class PropertiesAstTest method testLines3.

@Test
public void testLines3() throws Exception {
    ParseResults results = parser.parse("# Comment\n\nkey = value  1  \n \t   \t \n\t\t\n");
    assertTrue(results.syntaxErrors.isEmpty());
    assertTrue(results.problems.isEmpty());
    assertEquals(5, results.ast.getAllNodes().size());
    assertEquals(1, results.ast.getNodes(Comment.class).size());
    assertEquals(1, results.ast.getNodes(KeyValuePair.class).size());
    assertEquals(3, results.ast.getNodes(EmptyLine.class).size());
}
Also used : ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Aggregations

ParseResults (org.springframework.ide.vscode.java.properties.parser.ParseResults)21 Test (org.junit.Test)14 Node (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node)9 KeyValuePair (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair)5 Value (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value)5 Problem (org.springframework.ide.vscode.java.properties.parser.Problem)3 Key (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)3 ArrayList (java.util.ArrayList)2 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 Comment (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Comment)2 EmptyLine (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.EmptyLine)2 File (java.io.File)1 URI (java.net.URI)1 BitSet (java.util.BitSet)1 ANTLRErrorListener (org.antlr.v4.runtime.ANTLRErrorListener)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 ATNConfigSet (org.antlr.v4.runtime.atn.ATNConfigSet)1 DFA (org.antlr.v4.runtime.dfa.DFA)1