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