use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getFuzzyCompletions.
protected Collection<ICompletionProposal> getFuzzyCompletions() {
final String prefix = fuzzySearchPrefix.getPrefix(doc, offset);
if (prefix != null) {
Collection<Match<PropertyInfo>> matches = findMatches(prefix);
if (matches != null && !matches.isEmpty()) {
ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(matches.size());
for (final Match<PropertyInfo> match : matches) {
DocumentEdits docEdits;
try {
docEdits = LazyProposalApplier.from(() -> {
try {
Type type = TypeParser.parse(match.data.getType());
DocumentEdits edits = new DocumentEdits(doc);
edits.delete(offset - prefix.length(), offset);
edits.insert(offset, match.data.getId() + propertyCompletionPostfix(typeUtil, type));
return edits;
} catch (Throwable t) {
Log.log(t);
return new DocumentEdits(doc);
}
});
proposals.add(completionFactory.property(doc, docEdits, match, typeUtil));
} catch (Throwable e) {
Log.log(e);
}
}
return proposals;
}
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class SpringPropertiesReconcileEngine method reconcile.
@Override
public void reconcile(IDocument doc, IProblemCollector problemCollector) {
FuzzyMap<PropertyInfo> index = fIndexProvider.getIndex(doc);
problemCollector.beginCollecting();
try {
ParseResults results = parser.parse(doc.get());
DuplicateNameChecker duplicateNameChecker = new DuplicateNameChecker(problemCollector);
results.syntaxErrors.forEach(syntaxError -> {
problemCollector.accept(problem(PROP_SYNTAX_ERROR, syntaxError.getMessage(), syntaxError.getOffset(), syntaxError.getLength()));
});
if (index == null || index.isEmpty()) {
// some problem putting information about properties into the index.
return;
}
results.ast.getNodes(KeyValuePair.class).forEach(pair -> {
try {
DocumentRegion propertyNameRegion = createRegion(doc, pair.getKey());
String keyName = PropertiesFileEscapes.unescape(propertyNameRegion.toString());
duplicateNameChecker.check(propertyNameRegion);
PropertyInfo validProperty = SpringPropertyIndex.findLongestValidProperty(index, keyName);
if (validProperty != null) {
// in PropertyNavigator (probably these changes are also for the better making it simpler as well)
if (validProperty.isDeprecated()) {
problemCollector.accept(problemDeprecated(propertyNameRegion, validProperty));
}
int offset = validProperty.getId().length() + propertyNameRegion.getStart();
PropertyNavigator navigator = new PropertyNavigator(doc, problemCollector, typeUtilProvider.getTypeUtil(doc), propertyNameRegion);
Type valueType = navigator.navigate(offset, TypeParser.parse(validProperty.getType()));
if (valueType != null) {
reconcileType(doc, valueType, pair.getValue(), problemCollector);
}
} else {
// validProperty==null
// The name is invalid, with no 'prefix' of the name being a valid property name.
PropertyInfo similarEntry = index.findLongestCommonPrefixEntry(propertyNameRegion.toString());
CharSequence validPrefix = commonPrefix(similarEntry.getId(), keyName);
problemCollector.accept(problemUnkownProperty(propertyNameRegion, similarEntry, validPrefix));
}
// end: validProperty==null
} catch (Exception e) {
Log.log(e);
}
});
} catch (Throwable e2) {
Log.log(e2);
} finally {
problemCollector.endCollecting();
}
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class ApplicationYamlASTReconciler method reconcile.
private void reconcile(YamlFileAST root, NodeTuple entry, IndexNavigator nav) {
Node keyNode = entry.getKeyNode();
String key = asScalar(keyNode);
if (key == null) {
expectScalar(keyNode);
} else {
IndexNavigator subNav = nav.selectSubProperty(key);
PropertyInfo match = subNav.getExactMatch();
PropertyInfo extension = subNav.getExtensionCandidate();
if (match == null && extension == null) {
// nothing found for this key. Maybe user is using camelCase variation of the key?
String keyAlias = StringUtil.camelCaseToHyphens(key);
IndexNavigator subNavAlias = nav.selectSubProperty(keyAlias);
match = subNavAlias.getExactMatch();
extension = subNavAlias.getExtensionCandidate();
if (match != null || extension != null) {
// Got something for the alias, so use that instead.
// Note: do not swap for alias unless we actually found something.
// This gives more logical errors (in terms of user's key, not its canonical alias)
subNav = subNavAlias;
}
}
if (match != null && extension != null) {
// This ambiguity is hard to deal with and we choose not to do so for now
return;
} else if (match != null) {
Type type = TypeParser.parse(match.getType());
if (match.isDeprecated()) {
deprecatedProperty(match, keyNode);
}
reconcile(root, entry.getValueNode(), type);
} else if (extension != null) {
// We don't really care about the extension only about the fact that it
// exists and so it is meaningful to continue checking...
Node valueNode = entry.getValueNode();
reconcile(root, valueNode, subNav);
} else {
// both are null, this means there's no valid property with the current prefix
// whether exact or extending it with further navigation
unkownProperty(keyNode, subNav.getPrefix(), entry);
}
}
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class ValueCompletionProcessor method computeProposalsForSimpleName.
private void computeProposalsForSimpleName(ASTNode node, List<ICompletionProposal> completions, int offset, IDocument doc, FuzzyMap<PropertyInfo> index) {
String prefix = identifyPropertyPrefix(node.toString(), offset - node.getStartPosition());
int startOffset = node.getStartPosition();
int endOffset = node.getStartPosition() + node.getLength();
String proposalPrefix = "\"";
String proposalPostfix = "\"";
List<Match<PropertyInfo>> matches = findMatches(prefix, index);
for (Match<PropertyInfo> match : matches) {
DocumentEdits edits = new DocumentEdits(doc);
edits.replace(startOffset, endOffset, proposalPrefix + "${" + match.data.getId() + "}" + proposalPostfix);
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match.data.getId(), match.data.getName(), null);
completions.add(proposal);
}
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class ValueCompletionProcessor method provideCompletions.
@Override
public Collection<ICompletionProposal> provideCompletions(ASTNode node, Annotation annotation, ITypeBinding type, int offset, IDocument doc) {
List<ICompletionProposal> result = new ArrayList<>();
try {
FuzzyMap<PropertyInfo> index = indexProvider.getIndex(doc);
// case: @Value(<*>)
if (node == annotation && doc.get(offset - 1, 2).endsWith("()")) {
List<Match<PropertyInfo>> matches = findMatches("", index);
for (Match<PropertyInfo> match : matches) {
DocumentEdits edits = new DocumentEdits(doc);
edits.replace(offset, offset, "\"${" + match.data.getId() + "}\"");
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match.data.getId(), match.data.getName(), null);
result.add(proposal);
}
} else // case: @Value(prefix<*>)
if (node instanceof SimpleName && node.getParent() instanceof Annotation) {
computeProposalsForSimpleName(node, result, offset, doc, index);
} else // case: @Value(value=<*>)
if (node instanceof SimpleName && node.getParent() instanceof MemberValuePair && "value".equals(((MemberValuePair) node.getParent()).getName().toString())) {
computeProposalsForSimpleName(node, result, offset, doc, index);
} else // case: @Value("prefix<*>")
if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
computeProposalsForStringLiteral(node, result, offset, doc, index);
}
} else // case: @Value(value="prefix<*>")
if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair && "value".equals(((MemberValuePair) node.getParent()).getName().toString())) {
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
computeProposalsForStringLiteral(node, result, offset, doc, index);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
Aggregations