use of org.springframework.ide.vscode.boot.metadata.types.TypedProperty in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method createPropertyProposals.
protected Collection<ICompletionProposal> createPropertyProposals(Type type, int navOffset, String prefix, List<TypedProperty> objectProperties) {
ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
for (TypedProperty prop : objectProperties) {
double score = FuzzyMatcher.matchScore(prefix, prop.getName());
if (score != 0) {
Type valueType = prop.getType();
String postFix = propertyCompletionPostfix(typeUtil, valueType);
DocumentEdits edits = new DocumentEdits(doc);
edits.delete(navOffset + 1, offset);
edits.insert(offset, prop.getName() + postFix);
proposals.add(completionFactory.beanProperty(doc, null, type, prefix, prop, score, edits, typeUtil));
}
}
return proposals;
}
use of org.springframework.ide.vscode.boot.metadata.types.TypedProperty in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getNavigationProposals.
/**
* @param type Type of the expression leading upto the 'nav' operator
* @param navOffset Offset of the nav operator (either ']' or '.'
* @param offset Offset of the cursor where CA was requested.
*/
private Collection<ICompletionProposal> getNavigationProposals(Type type, int navOffset) {
try {
char navOp = doc.getChar(navOffset);
if (navOp == '.') {
String prefix = doc.get(navOffset + 1, offset - (navOffset + 1));
EnumCaseMode caseMode = caseMode(prefix);
List<TypedProperty> objectProperties = typeUtil.getProperties(type, caseMode, BeanPropertyNameMode.HYPHENATED);
// Note: properties editor itself deals with relaxed names. So it expects the properties here to be returned in hyphenated form only.
if (objectProperties != null && !objectProperties.isEmpty()) {
return createPropertyProposals(type, navOffset, prefix, objectProperties);
}
} else {
// TODO: other cases ']' or '[' ?
}
} catch (Exception e) {
Log.log(e);
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.boot.metadata.types.TypedProperty in project sts4 by spring-projects.
the class PropertyNavigator method dotNavigate.
/**
* Handle dot navigation into given type, after a '.' was
* was found at given offset. Assumes the type has already been
* checked to be 'dotable'.
*/
private Type dotNavigate(int offset, Type type) {
if (TypeUtil.isMap(type)) {
int keyStart = offset + 1;
Type domainType = TypeUtil.getDomainType(type);
int keyEnd = -1;
if (typeUtil.isDotable(domainType)) {
// '.' should be interpreted as navigation.
keyEnd = nextNavOp(".[", offset + 1);
} else {
// '.' should *not* be interpreted as navigation.
keyEnd = nextNavOp("[", offset + 1);
}
String key = textBetween(keyStart, keyEnd);
Type keyType = typeUtil.getKeyType(type);
if (keyType != null) {
ValueParser keyParser = typeUtil.getValueParser(keyType);
if (keyParser != null) {
try {
keyParser.parse(key);
} catch (Exception e) {
problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_VALUE_TYPE_MISMATCH, "Expecting " + typeUtil.niceTypeName(keyType), keyStart, keyEnd - keyStart));
}
}
}
return navigate(keyEnd, domainType);
} else {
// dot navigation into object properties
int keyStart = offset + 1;
int keyEnd = nextNavOp(".[", offset + 1);
if (keyEnd < 0) {
keyEnd = region.getEnd();
}
String key = StringUtil.camelCaseToHyphens(textBetween(keyStart, keyEnd));
List<TypedProperty> properties = typeUtil.getProperties(type, EnumCaseMode.ALIASED, BeanPropertyNameMode.ALIASED);
if (properties != null) {
TypedProperty prop = null;
for (TypedProperty p : properties) {
if (p.getName().equals(key)) {
prop = p;
break;
}
}
if (prop == null) {
problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_INVALID_BEAN_PROPERTY, "Type '" + typeUtil.niceTypeName(type) + "' has no property '" + key + "'", keyStart, keyEnd - keyStart));
} else {
if (prop.isDeprecated()) {
problemCollector.accept(problemDeprecated(type, prop, keyStart, keyEnd - keyStart));
}
return navigate(keyEnd, prop.getType());
}
}
}
return null;
}
use of org.springframework.ide.vscode.boot.metadata.types.TypedProperty in project sts4 by spring-projects.
the class TypeUtilTest method getPropertyType.
private Type getPropertyType(Type type, String propName, EnumCaseMode enumMode, BeanPropertyNameMode beanMode) {
List<TypedProperty> props = getProperties(type, enumMode, beanMode);
assertNotNull(props);
for (TypedProperty prop : props) {
if (prop.getName().equals(propName)) {
return prop.getType();
}
}
return null;
}
use of org.springframework.ide.vscode.boot.metadata.types.TypedProperty in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getKeyHintProposals.
private Collection<ICompletionProposal> getKeyHintProposals(PropertyInfo prop, int navOffset) {
HintProvider hintProvider = prop.getHints(typeUtil, false);
if (!HintProviders.isNull(hintProvider)) {
String query = textBetween(doc, navOffset + 1, offset);
List<TypedProperty> hintProperties = hintProvider.getPropertyHints(query);
if (CollectionUtil.hasElements(hintProperties)) {
return createPropertyProposals(TypeParser.parse(prop.getType()), navOffset, query, hintProperties);
}
}
return ImmutableList.of();
}
Aggregations