Search in sources :

Example 1 with FieldValueResolver

use of com.redhat.qute.project.datamodel.resolvers.FieldValueResolver 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;
}
Also used : TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) ExtendedDataModelProject(com.redhat.qute.project.datamodel.ExtendedDataModelProject) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) ValueResolver(com.redhat.qute.project.datamodel.resolvers.ValueResolver) TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) ArrayList(java.util.ArrayList) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver)

Example 2 with FieldValueResolver

use of com.redhat.qute.project.datamodel.resolvers.FieldValueResolver 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:
            }
        }
    }
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) ValueResolver(com.redhat.qute.project.datamodel.resolvers.ValueResolver) TextEdit(org.eclipse.lsp4j.TextEdit) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) HashSet(java.util.HashSet)

Example 3 with FieldValueResolver

use of com.redhat.qute.project.datamodel.resolvers.FieldValueResolver in project quarkus-ls by redhat-developer.

the class QuteProjectRegistry method findJavaElementWithNamespace.

public CompletableFuture<JavaElementInfo> findJavaElementWithNamespace(String namespace, String partName, String projectUri) {
    if (StringUtils.isEmpty(projectUri)) {
        return JAVA_ELEMENT_INFO_NULL_FUTURE;
    }
    QuteProject project = getProject(projectUri);
    if (project == null) {
        return JAVA_ELEMENT_INFO_NULL_FUTURE;
    }
    return // 
    project.getDataModelProject().thenApply(dataModel -> {
        if (dataModel == null) {
            return null;
        }
        // Search in types resolvers
        List<TypeValueResolver> typeResolvers = dataModel.getTypeValueResolvers();
        for (TypeValueResolver resolver : typeResolvers) {
            if (isMatchNamespaceResolver(namespace, partName, resolver, dataModel)) {
                return resolver;
            }
        }
        // Search in methods resolvers
        List<MethodValueResolver> methodResolvers = dataModel.getMethodValueResolvers();
        for (MethodValueResolver resolver : methodResolvers) {
            if (isMatchNamespaceResolver(namespace, partName, resolver, dataModel)) {
                return resolver;
            }
        }
        // Search in field resolvers
        List<FieldValueResolver> fieldResolvers = dataModel.getFieldValueResolvers();
        for (FieldValueResolver resolver : fieldResolvers) {
            if (isMatchNamespaceResolver(namespace, partName, resolver, dataModel)) {
                return resolver;
            }
        }
        return null;
    });
}
Also used : TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver)

Example 4 with FieldValueResolver

use of com.redhat.qute.project.datamodel.resolvers.FieldValueResolver in project quarkus-ls by redhat-developer.

the class ExtendedDataModelProject method updateValueResolvers.

private static void updateValueResolvers(List<TypeValueResolver> typeValueResolvers, List<FieldValueResolver> fieldValueResolvers, List<MethodValueResolver> methodValueResolvers, DataModelProject<DataModelTemplate<DataModelParameter>> project) {
    project.getValueResolvers().forEach(resolver -> {
        JavaElementKind kind = resolver.getJavaElementKind();
        switch(kind) {
            case TYPE:
                TypeValueResolver typeValueResolver = new TypeValueResolver();
                typeValueResolver.setNamed(resolver.getNamed());
                typeValueResolver.setNamespace(resolver.getNamespace());
                typeValueResolver.setSignature(resolver.getSignature());
                typeValueResolver.setSourceType(resolver.getSourceType());
                typeValueResolvers.add(typeValueResolver);
                break;
            case FIELD:
                FieldValueResolver fieldValueResolver = new FieldValueResolver();
                fieldValueResolver.setNamed(resolver.getNamed());
                fieldValueResolver.setNamespace(resolver.getNamespace());
                fieldValueResolver.setSignature(resolver.getSignature());
                fieldValueResolver.setSourceType(resolver.getSourceType());
                fieldValueResolvers.add(fieldValueResolver);
                break;
            case METHOD:
                MethodValueResolver methodValueResolver = new MethodValueResolver();
                methodValueResolver.setNamed(resolver.getNamed());
                methodValueResolver.setNamespace(resolver.getNamespace());
                methodValueResolver.setMatchName(resolver.getMatchName());
                methodValueResolver.setSignature(resolver.getSignature());
                methodValueResolver.setSourceType(resolver.getSourceType());
                methodValueResolvers.add(methodValueResolver);
                break;
            default:
                break;
        }
    });
}
Also used : TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) JavaElementKind(com.redhat.qute.commons.JavaElementKind) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver)

Aggregations

FieldValueResolver (com.redhat.qute.project.datamodel.resolvers.FieldValueResolver)4 MethodValueResolver (com.redhat.qute.project.datamodel.resolvers.MethodValueResolver)4 TypeValueResolver (com.redhat.qute.project.datamodel.resolvers.TypeValueResolver)3 ValueResolver (com.redhat.qute.project.datamodel.resolvers.ValueResolver)2 JavaElementKind (com.redhat.qute.commons.JavaElementKind)1 ExtendedDataModelProject (com.redhat.qute.project.datamodel.ExtendedDataModelProject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 TextEdit (org.eclipse.lsp4j.TextEdit)1