Search in sources :

Example 1 with Value

use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value 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 2 with Value

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

the class PropertiesHoverCalculator method calculate.

Tuple2<Renderable, IRegion> calculate() {
    ParseResults parseResults = parser.parse(doc.get());
    Node node = parseResults.ast.findNode(offset);
    if (node instanceof Value) {
        return getValueHover((Value) node);
    } else if (node instanceof Key) {
        return getPropertyHover((Key) node);
    }
    return null;
}
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) Key(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)

Example 3 with Value

use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value 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 4 with Value

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

the class PropertiesHoverCalculator method getValueHover.

private Tuple2<Renderable, IRegion> getValueHover(Value value) {
    DocumentRegion valueRegion = createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES);
    if (valueRegion.getStart() <= offset && offset < valueRegion.getEnd()) {
        String valueString = valueRegion.toString();
        String propertyName = value.getParent().getKey().decode();
        Type type = getValueType(index, typeUtil, propertyName);
        if (TypeUtil.isSequencable(type)) {
            // It is useful to provide content assist for the values in the list when entering a list
            type = TypeUtil.getDomainType(type);
        }
        if (TypeUtil.isClass(type)) {
            // Special case. We want to provide hoverinfos more liberally than what's suggested for completions (i.e. even class names
            // that are not suggested by the hints because they do not meet subtyping constraints should be hoverable and linkable!
            StsValueHint hint = StsValueHint.className(valueString, typeUtil);
            if (hint != null) {
                return Tuples.of(createRenderable(hint), valueRegion.asRegion());
            }
        }
        // Hack: pretend to invoke content-assist at the end of the value text. This should provide hints applicable to that value
        // then show hoverinfo based on that. That way we can avoid duplication a lot of similar logic to compute hoverinfos and hyperlinks.
        Collection<StsValueHint> hints = getValueHints(index, typeUtil, valueString, propertyName, EnumCaseMode.ALIASED);
        if (hints != null) {
            Optional<StsValueHint> hint = hints.stream().filter(h -> valueString.equals(h.getValue())).findFirst();
            if (hint.isPresent()) {
                return Tuples.of(createRenderable(hint.get()), valueRegion.asRegion());
            }
        }
    }
    return null;
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) SpringPropertyIndex(org.springframework.ide.vscode.boot.metadata.SpringPropertyIndex) Tuples(reactor.util.function.Tuples) Type(org.springframework.ide.vscode.boot.metadata.types.Type) Tuple2(reactor.util.function.Tuple2) AntlrParser(org.springframework.ide.vscode.java.properties.antlr.parser.AntlrParser) ImmutableList(com.google.common.collect.ImmutableList) FuzzyMap(org.springframework.ide.vscode.commons.util.FuzzyMap) Renderables.paragraph(org.springframework.ide.vscode.commons.util.Renderables.paragraph) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) EnumCaseMode(org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode) Collection(java.util.Collection) SPACES(org.springframework.ide.vscode.boot.common.CommonLanguageTools.SPACES) Renderables.concat(org.springframework.ide.vscode.commons.util.Renderables.concat) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Renderables.bold(org.springframework.ide.vscode.commons.util.Renderables.bold) Renderables.text(org.springframework.ide.vscode.commons.util.Renderables.text) Key(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key) InformationTemplates(org.springframework.ide.vscode.boot.common.InformationTemplates) Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) CommonLanguageTools.getValueHints(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueHints) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) Optional(java.util.Optional) Renderable(org.springframework.ide.vscode.commons.util.Renderable) TypeUtil(org.springframework.ide.vscode.boot.metadata.types.TypeUtil) Builder(com.google.common.collect.ImmutableList.Builder) CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Example 5 with Value

use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value 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)

Aggregations

ParseResults (org.springframework.ide.vscode.java.properties.parser.ParseResults)6 Node (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node)6 Value (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value)6 Test (org.junit.Test)3 Key (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)3 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 SPACES (org.springframework.ide.vscode.boot.common.CommonLanguageTools.SPACES)1 CommonLanguageTools.getValueHints (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueHints)1 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)1 InformationTemplates (org.springframework.ide.vscode.boot.common.InformationTemplates)1 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)1 SpringPropertyIndex (org.springframework.ide.vscode.boot.metadata.SpringPropertyIndex)1 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)1 Type (org.springframework.ide.vscode.boot.metadata.types.Type)1 TypeUtil (org.springframework.ide.vscode.boot.metadata.types.TypeUtil)1 EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)1 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)1