use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class CommonLanguageTools method findLongestValidProperty.
/**
* Find the longest known property that is a prefix of the given name. Here prefix does not mean
* 'string prefix' but a prefix in the sense of treating '.' as a kind of separators. So
* 'prefix' is not allowed to end in the middle of a 'segment'.
*/
public static PropertyInfo findLongestValidProperty(FuzzyMap<PropertyInfo> index, String name) {
int bracketPos = name.indexOf('[');
int endPos = bracketPos >= 0 ? bracketPos : name.length();
PropertyInfo prop = null;
String prefix = null;
while (endPos > 0 && prop == null) {
prefix = name.substring(0, endPos);
String canonicalPrefix = camelCaseToHyphens(prefix);
prop = index.get(canonicalPrefix);
if (prop == null) {
endPos = name.lastIndexOf('.', endPos - 1);
}
}
if (prop != null) {
// match the names exactly even if we found them using relaxed name matching.
return prop.withId(prefix);
}
return null;
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class CommonLanguageTools method getValueType.
/**
* Determine the value type for a give propertyName.
*/
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
try {
PropertyInfo prop = index.get(propertyName);
if (prop != null) {
return TypeParser.parse(prop.getType());
} else {
prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
if (prop != null) {
TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
doc.setText(propertyName);
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
}
}
} catch (Exception e) {
Log.log(e);
}
return null;
}
Aggregations