Search in sources :

Example 1 with TypeUtil

use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil in project sts4 by spring-projects.

the class SpringPropertiesReconcileEngine method reconcileType.

private void reconcileType(DocumentRegion escapedValue, Type expectType, IProblemCollector problems) {
    TypeUtil typeUtil = typeUtilProvider.getTypeUtil(escapedValue.getDocument());
    ValueParser parser = typeUtil.getValueParser(expectType);
    if (parser != null) {
        try {
            String valueStr = PropertiesFileEscapes.unescape(escapedValue.toString());
            if (!valueStr.contains("${")) {
                // Don't check strings that look like they use variable substitution.
                parser.parse(valueStr);
            }
        } catch (ValueParseException e) {
            problems.accept(problem(ApplicationPropertiesProblemType.PROP_VALUE_TYPE_MISMATCH, ExceptionUtil.getMessage(e), e.getHighlightRegion(escapedValue)));
        } catch (Exception e) {
            problems.accept(problem(ApplicationPropertiesProblemType.PROP_VALUE_TYPE_MISMATCH, "Expecting '" + typeUtil.niceTypeName(expectType) + "'", escapedValue));
        }
    }
}
Also used : ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) TypeUtil(org.springframework.ide.vscode.boot.metadata.types.TypeUtil) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) ValueParseException(org.springframework.ide.vscode.commons.util.ValueParseException) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 2 with TypeUtil

use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil 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 3 with TypeUtil

use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil in project sts4 by spring-projects.

the class TypeUtilTest method useProject.

// @Test
// public void testTypeFromSignature() throws Exception {
// useProject("enums-boot-1.3.2-app");
// assertType("java.lang.String", Type.fromSignature("QString;", project.findType("demo.ColorData")));
// assertType("java.lang.String", Type.fromSignature("Ljava.lang.String;", project.findType("demo.ColorData")));
// assertType("java.lang.String[]", Type.fromSignature("[Ljava.lang.String;", project.findType("demo.ColorData")));
// assertType("java.lang.String[]", Type.fromSignature("[QString;", project.findType("demo.ColorData")));
// }
private void useProject(String name) throws Exception {
    project = projects.mavenProject(name);
    ;
    typeUtil = new TypeUtil(project);
}
Also used : TypeUtil(org.springframework.ide.vscode.boot.metadata.types.TypeUtil)

Aggregations

TypeUtil (org.springframework.ide.vscode.boot.metadata.types.TypeUtil)3 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 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 EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)1 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)1 FuzzyMap (org.springframework.ide.vscode.commons.util.FuzzyMap)1 Renderable (org.springframework.ide.vscode.commons.util.Renderable)1 Renderables.bold (org.springframework.ide.vscode.commons.util.Renderables.bold)1 Renderables.concat (org.springframework.ide.vscode.commons.util.Renderables.concat)1