Search in sources :

Example 1 with TypeValueResolver

use of com.redhat.qute.project.datamodel.resolvers.TypeValueResolver 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 TypeValueResolver

use of com.redhat.qute.project.datamodel.resolvers.TypeValueResolver 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 3 with TypeValueResolver

use of com.redhat.qute.project.datamodel.resolvers.TypeValueResolver 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)3 MethodValueResolver (com.redhat.qute.project.datamodel.resolvers.MethodValueResolver)3 TypeValueResolver (com.redhat.qute.project.datamodel.resolvers.TypeValueResolver)3 JavaElementKind (com.redhat.qute.commons.JavaElementKind)1 ExtendedDataModelProject (com.redhat.qute.project.datamodel.ExtendedDataModelProject)1 ValueResolver (com.redhat.qute.project.datamodel.resolvers.ValueResolver)1 ArrayList (java.util.ArrayList)1