use of com.redhat.qute.project.datamodel.resolvers.ValueResolver in project quarkus-ls by redhat-developer.
the class QuteProjectRegistry method getNamespaceResolvers.
/**
* Returns namespace resolvers from the given Qute project Uri.
*
* @param projectUri the Qute project Uri
*
* @return namespace resolvers from the given Qute project Uri.
*/
public List<ValueResolver> getNamespaceResolvers(String namespace, String projectUri) {
if (StringUtils.isEmpty(projectUri)) {
return Collections.emptyList();
}
QuteProject project = getProject(projectUri);
if (project == null) {
return Collections.emptyList();
}
ExtendedDataModelProject dataModel = project.getDataModelProject().getNow(null);
if (dataModel == null) {
return Collections.emptyList();
}
List<ValueResolver> namespaceResolvers = new ArrayList<>();
List<TypeValueResolver> allTypeResolvers = dataModel.getTypeValueResolvers();
if (allTypeResolvers != null) {
for (ValueResolver resolver : allTypeResolvers) {
if (isMatchNamespace(resolver, namespace, dataModel)) {
namespaceResolvers.add(resolver);
}
}
}
List<MethodValueResolver> allMethodResolvers = dataModel.getMethodValueResolvers();
if (allMethodResolvers != null) {
for (ValueResolver resolver : allMethodResolvers) {
if (isMatchNamespace(resolver, namespace, dataModel)) {
namespaceResolvers.add(resolver);
}
}
}
List<FieldValueResolver> allFieldResolvers = dataModel.getFieldValueResolvers();
if (allFieldResolvers != null) {
for (ValueResolver resolver : allFieldResolvers) {
if (isMatchNamespace(resolver, namespace, dataModel)) {
namespaceResolvers.add(resolver);
}
}
}
return namespaceResolvers;
}
use of com.redhat.qute.project.datamodel.resolvers.ValueResolver in project quarkus-ls by redhat-developer.
the class QuteCompletionsForExpression method doCompleteNamespaceResolvers.
public void doCompleteNamespaceResolvers(String namespace, Template template, Range range, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings, CompletionList list) {
if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
// {data:|}
// Collect alias declared from parameter declaration
doCompleteExpressionForObjectPartWithParameterAlias(template, range, list);
// Collect parameters from CheckedTemplate method parameters
doCompleteExpressionForObjectPartWithCheckedTemplate(template, range, list);
return;
}
// {inject:|}
// {|inject:}
// {config:|}
// {|config:}
Set<String> existingResovers = new HashSet<>();
List<ValueResolver> namespaceResolvers = javaCache.getNamespaceResolvers(namespace, template.getProjectUri());
for (ValueResolver resolver : namespaceResolvers) {
boolean useNamespaceInTextEdit = namespace == null;
String named = resolver.getNamed();
if (named != null) {
// @Named("user")
// User getUser();
String label = useNamespaceInTextEdit ? resolver.getNamespace() + ':' + named : named;
if (!existingResovers.contains(label)) {
existingResovers.add(label);
CompletionItem item = new CompletionItem();
item.setLabel(label);
item.setFilterText(label);
item.setKind(CompletionItemKind.Field);
TextEdit textEdit = new TextEdit();
textEdit.setRange(range);
textEdit.setNewText(label);
item.setTextEdit(Either.forLeft(textEdit));
item.setSortText("Zb" + item.getLabel());
list.getItems().add(item);
}
} else {
switch(resolver.getJavaElementKind()) {
case METHOD:
{
MethodValueResolver method = (MethodValueResolver) resolver;
CompletionItem item = fillCompletionMethod(method, method.getNamespace(), useNamespaceInTextEdit, range, completionSettings, formattingSettings, list);
item.setKind(CompletionItemKind.Function);
// Display namespace resolvers (ex : config:getConfigProperty(...)) after
// declared objects
item.setSortText("Zc" + item.getLabel());
break;
}
case FIELD:
{
FieldValueResolver field = (FieldValueResolver) resolver;
CompletionItem item = fillCompletionField(field, field.getNamespace(), namespace == null, range, list);
item.setKind(CompletionItemKind.Field);
// Display namespace resolvers (ex : inject:bean) after
// declared objects
item.setSortText("Zb" + item.getLabel());
break;
}
default:
}
}
}
}
use of com.redhat.qute.project.datamodel.resolvers.ValueResolver in project quarkus-ls by redhat-developer.
the class QuteCompletionsForExpression method createMethodSnippet.
private static String createMethodSnippet(JavaMethodInfo method, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings) {
boolean snippetsSupported = completionSettings.isCompletionSnippetsSupported();
String methodName = method.getMethodName();
StringBuilder snippet = new StringBuilder();
if (MATCH_NAME_ANY.equals(methodName)) {
// config:*
JavaParameterInfo firstParameter = method.getParameterAt(0);
String parameterName = firstParameter != null ? firstParameter.getName() : methodName;
if (snippetsSupported) {
SnippetsBuilder.placeholders(1, parameterName, snippet);
} else {
snippet.append(parameterName);
}
if (snippetsSupported) {
SnippetsBuilder.tabstops(0, snippet);
}
} else {
snippet.append(methodName);
if (method.hasParameters()) {
int start = 0;
if (method.isVirtual() && ((ValueResolver) method).getNamespace() == null) {
start++;
}
snippet.append("(");
for (int i = start; i < method.getParameters().size(); i++) {
if (i > start) {
snippet.append(", ");
}
JavaParameterInfo parameter = method.getParameterAt(i);
if (snippetsSupported) {
SnippetsBuilder.placeholders(i - start + 1, parameter.getName(), snippet);
} else {
snippet.append(parameter.getName());
}
}
snippet.append(")");
if (snippetsSupported) {
SnippetsBuilder.tabstops(0, snippet);
}
}
}
return snippet.toString();
}
Aggregations