use of com.redhat.qute.project.datamodel.resolvers.MethodValueResolver 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.MethodValueResolver in project quarkus-ls by redhat-developer.
the class QuteProjectRegistry method getResolversFor.
public List<MethodValueResolver> getResolversFor(ResolvedJavaTypeInfo javaType, String projectUri) {
// Search in static value resolvers (ex : orEmpty, take, etc)
List<MethodValueResolver> matches = new ArrayList<>();
for (MethodValueResolver resolver : valueResolversRegistry.getResolvers()) {
if (matchResolver(javaType, resolver, projectUri)) {
matches.add(resolver);
}
}
// Search in template extension value resolvers retrieved by @TemplateExtension
List<MethodValueResolver> allResolvers = getMethodValueResolvers(projectUri).getNow(null);
if (allResolvers != null) {
for (MethodValueResolver resolver : allResolvers) {
if (resolver.getNamespace() == null && matchResolver(javaType, resolver, projectUri)) {
matches.add(resolver);
}
}
}
return matches;
}
use of com.redhat.qute.project.datamodel.resolvers.MethodValueResolver in project quarkus-ls by redhat-developer.
the class QuteProjectRegistry method findMethodResolver.
private boolean findMethodResolver(ResolvedJavaTypeInfo baseType, String namespace, String methodName, List<ResolvedJavaTypeInfo> parameterTypes, List<MethodValueResolver> allResolvers, JavaMemberResult result, String projectUri) {
for (MethodValueResolver resolver : allResolvers) {
if (isMatchMethod(resolver, methodName, null, null)) {
// The current resolver matches the method name.
if (namespace != null) {
if (namespace.equals(resolver.getNamespace())) {
result.setMember(resolver);
result.setMatchVirtualMethod(true);
// Check if the current resolver matches the parameters.
boolean matchParameters = isMatchParameters(resolver, parameterTypes, projectUri);
result.setMatchParameters(matchParameters);
return true;
}
} else {
// Check if the baseType matches the type of the first parameter of the current
// resolver.
boolean matchVirtualMethod = matchResolver(baseType, resolver, methodName);
boolean matchParameters = false;
if (matchVirtualMethod) {
// Check if the current resolver matches the parameters.
matchParameters = isMatchParameters(resolver, parameterTypes, projectUri);
}
if (result.getMember() == null || (matchParameters && matchVirtualMethod)) {
result.setMember(resolver);
result.setMatchParameters(matchParameters);
result.setMatchVirtualMethod(matchVirtualMethod);
}
if (matchParameters && matchVirtualMethod) {
// virtual method,stop the search
return true;
}
}
}
}
return false;
}
use of com.redhat.qute.project.datamodel.resolvers.MethodValueResolver in project quarkus-ls by redhat-developer.
the class QuteCompletionsForExpression method doCompleteForJavaTypeMembers.
/**
* Returns the completion result for Java fields, methods of the given Java type
* class, interface <code>resolvedType</code>
*
* @param resolvedType the Java class, interface.
* @param start the part start index to replace.
* @param end the part end index to replace.
* @param template the owner Qute template.
* @param completionSettings the completion settings.
* @param formattingSettings the formatting settings.
*
* @return the completion list.
*/
private CompletionList doCompleteForJavaTypeMembers(ResolvedJavaTypeInfo resolvedType, int start, int end, Template template, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings) {
CompletionList list = new CompletionList();
list.setItems(new ArrayList<>());
Range range = QutePositionUtility.createRange(start, end, template);
String projectUri = template.getProjectUri();
Set<String> existingProperties = new HashSet<>();
// Completion for Java fields
fillCompletionFields(resolvedType, range, projectUri, existingProperties, list);
// Completion for Java methods
Set<String> existingMethodSignatures = new HashSet<>();
fillCompletionMethods(resolvedType, range, projectUri, completionSettings, formattingSettings, existingProperties, existingMethodSignatures, list);
// Completion for virtual methods (from value resolvers)
// - Static value resolvers (orEmpty, etc)
// - Dynamic value resolvers (from @TemplateExtension)
List<MethodValueResolver> resolvers = javaCache.getResolversFor(resolvedType, projectUri);
for (MethodValueResolver method : resolvers) {
if (method.isValidName()) {
fillCompletionMethod(method, range, completionSettings, formattingSettings, list);
}
}
return list;
}
use of com.redhat.qute.project.datamodel.resolvers.MethodValueResolver 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:
}
}
}
}
Aggregations