use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode 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.TypeUtil.EnumCaseMode in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getValueCompletions.
private Collection<ICompletionProposal> getValueCompletions(Value value) {
DocumentRegion valueRegion = createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES);
String query = valuePrefixFinder.getPrefix(doc, offset, valueRegion.getStart());
int startOfValue = offset - query.length();
EnumCaseMode caseMode = caseMode(query);
// note: no need to skip whitespace backwards.
String propertyName = /*fuzzySearchPrefix.getPrefix(doc, pair.getOffset())*/
value.getParent().getKey().decode();
// because value partition includes whitespace around the assignment
if (propertyName != null) {
Collection<StsValueHint> valueCompletions = getValueHints(index, typeUtil, query, propertyName, caseMode);
if (valueCompletions != null && !valueCompletions.isEmpty()) {
ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
for (StsValueHint hint : valueCompletions) {
String valueCandidate = hint.getValue();
double score = FuzzyMatcher.matchScore(query, valueCandidate);
if (score != 0) {
DocumentEdits edits = new DocumentEdits(doc);
edits.delete(startOfValue, offset);
edits.insert(offset, valueCandidate);
String valueTypeName = typeUtil.niceTypeName(getValueType(index, typeUtil, propertyName));
proposals.add(completionFactory.valueProposal(valueCandidate, query, valueTypeName, score, edits, ValueHintHoverInfo.create(hint)));
}
}
return proposals;
}
}
return Collections.emptyList();
}
Aggregations