Search in sources :

Example 6 with Node

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

the class PropertiesCompletionProposalsCalculator method calculate.

/**
 * Create completions proposals in the context of a properties text editor.
 */
public Collection<ICompletionProposal> calculate() throws BadLocationException {
    ParseResults parseResults = parser.parse(doc.get());
    Node node = parseResults.ast.findNode(offset);
    if (node instanceof Value) {
        return getValueCompletions((Value) node);
    } else if (node instanceof Key || node instanceof EmptyLine || node == null) {
        return getPropertyCompletions();
    }
    return Collections.emptyList();
}
Also used : Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) EmptyLine(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.EmptyLine) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Key(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)

Example 7 with Node

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

the class PropertiesAstTest method positionPair.

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

Example 8 with Node

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

the class PropertiesAstTest method positionValue.

@Test
public void positionValue() throws Exception {
    ParseResults results = parser.parse("# Comment\n" + "key  = value\n");
    Node node = results.ast.findNode(17);
    assertTrue(node instanceof Value);
    assertTrue(node.getOffset() <= 17 && 17 <= node.getOffset() + node.getLength());
    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 9 with Node

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

the class PropertiesAstTest method positionEmptyValue.

@Test
public void positionEmptyValue() throws Exception {
    ParseResults results = parser.parse("# Comment\n" + "key  =");
    Node 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)

Aggregations

ParseResults (org.springframework.ide.vscode.java.properties.parser.ParseResults)9 Node (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node)9 Test (org.junit.Test)7 Value (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value)5 Key (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)3 EmptyLine (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.EmptyLine)2 Comment (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Comment)1 KeyValuePair (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair)1