use of org.springframework.ide.vscode.boot.metadata.types.Type 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.Type in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getNavigationProposals.
private Collection<ICompletionProposal> getNavigationProposals() {
String navPrefix = navigationPrefixFinder.getPrefix(doc, offset);
try {
if (navPrefix != null) {
// offset of 'nav' operator char (i.e. '.' or ']').
int navOffset = offset - navPrefix.length() - 1;
navPrefix = fuzzySearchPrefix.getPrefix(doc, navOffset);
if (navPrefix != null && !navPrefix.isEmpty()) {
PropertyInfo prop = findLongestValidProperty(index, navPrefix);
if (prop != null) {
int regionStart = navOffset - navPrefix.length();
Collection<ICompletionProposal> hintProposals = getKeyHintProposals(prop, navOffset);
if (CollectionUtil.hasElements(hintProposals)) {
return hintProposals;
}
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, regionStart, navOffset));
Type type = navigator.navigate(regionStart + prop.getId().length(), TypeParser.parse(prop.getType()));
if (type != null) {
return getNavigationProposals(type, navOffset);
}
}
}
}
} catch (Exception e) {
Log.log(e);
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.boot.metadata.types.Type 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.Type in project sts4 by spring-projects.
the class CommonLanguageTools method getValueHints.
public static Collection<StsValueHint> getValueHints(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String query, String propertyName, EnumCaseMode caseMode) {
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);
}
List<StsValueHint> allHints = new ArrayList<>();
{
Collection<StsValueHint> hints = typeUtil.getHintValues(type, query, caseMode);
if (CollectionUtil.hasElements(hints)) {
allHints.addAll(hints);
}
}
{
PropertyInfo prop = index.findLongestCommonPrefixEntry(propertyName);
if (prop != null) {
HintProvider hintProvider = prop.getHints(typeUtil, false);
if (!HintProviders.isNull(hintProvider)) {
allHints.addAll(hintProvider.getValueHints(query));
}
}
}
return allHints;
}
use of org.springframework.ide.vscode.boot.metadata.types.Type in project sts4 by spring-projects.
the class TypeParserTest method testNonGeneric.
@Test
public void testNonGeneric() throws Exception {
Type type = TypeParser.parse("java.lang.String");
assertEquals("java.lang.String", type.getErasure());
assertFalse(type.isGeneric());
assertEquals("java.lang.String", type.toString());
}
Aggregations