Search in sources :

Example 1 with DataModelTemplate

use of com.redhat.qute.commons.datamodel.DataModelTemplate in project quarkus-ls by redhat-developer.

the class MockQuteProject method loadDataModelProject.

@Override
protected synchronized CompletableFuture<ExtendedDataModelProject> loadDataModelProject() {
    DataModelProject<DataModelTemplate<DataModelParameter>> project = new DataModelProject<DataModelTemplate<DataModelParameter>>();
    project.setTemplates(templates);
    project.setValueResolvers(valueResolvers);
    project.setNamespaceResolverInfos(namespaceResolverInfos);
    return CompletableFuture.completedFuture(new ExtendedDataModelProject(project));
}
Also used : DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) ExtendedDataModelProject(com.redhat.qute.project.datamodel.ExtendedDataModelProject) DataModelProject(com.redhat.qute.commons.datamodel.DataModelProject) ExtendedDataModelProject(com.redhat.qute.project.datamodel.ExtendedDataModelProject)

Example 2 with DataModelTemplate

use of com.redhat.qute.commons.datamodel.DataModelTemplate in project quarkus-ls by redhat-developer.

the class QuteSupportForTemplateDelegateCommandHandler method getProjectDataModel.

private static DataModelProject<DataModelTemplate<DataModelParameter>> getProjectDataModel(List<Object> arguments, String commandId, IProgressMonitor monitor) throws Exception {
    QuteDataModelProjectParams params = createQuteProjectDataModelParams(arguments, commandId);
    // Execute the getProjectDataModel in a Job to benefit with progress
    // monitor
    final AtomicReference<DataModelProject<DataModelTemplate<DataModelParameter>>> dataModelRef = new AtomicReference<DataModelProject<DataModelTemplate<DataModelParameter>>>(null);
    Job job = Job.create("Qute data model collector", progress -> {
        DataModelProject<DataModelTemplate<DataModelParameter>> project = QuteSupportForTemplate.getInstance().getDataModelProject(params, JDTUtilsLSImpl.getInstance(), progress);
        dataModelRef.set(project);
    });
    job.schedule();
    try {
        job.join();
    } catch (InterruptedException e) {
        LOGGER.log(Level.WARNING, "Error while joining Qute data model collector job", e);
    }
    Exception jobException = (Exception) job.getResult().getException();
    if (jobException != null) {
        if (jobException.getCause() != null) {
            throw (Exception) jobException.getCause();
        }
        throw jobException;
    }
    return dataModelRef.get();
}
Also used : DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) QuteDataModelProjectParams(com.redhat.qute.commons.datamodel.QuteDataModelProjectParams) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) AtomicReference(java.util.concurrent.atomic.AtomicReference) Job(org.eclipse.core.runtime.jobs.Job) DataModelProject(com.redhat.qute.commons.datamodel.DataModelProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with DataModelTemplate

use of com.redhat.qute.commons.datamodel.DataModelTemplate in project quarkus-ls by redhat-developer.

the class CheckedTemplateSupport method createTemplateDataModel.

private static DataModelTemplate<DataModelParameter> createTemplateDataModel(IMethod method, String className, IType type, IProgressMonitor monitor) {
    String methodName = method.getElementName();
    // src/main/resources/templates/${className}/${methodName}.qute.html
    String templateUri = getTemplatePath(className, methodName);
    // Create template data model with:
    // - template uri : Qute template file which must be bind with data model.
    // - source type : the Java class which defines Templates
    // -
    DataModelTemplate<DataModelParameter> template = new DataModelTemplate<DataModelParameter>();
    template.setParameters(new ArrayList<>());
    template.setTemplateUri(templateUri);
    template.setSourceType(type.getFullyQualifiedName());
    template.setSourceMethod(methodName);
    try {
        for (ILocalVariable methodParameter : method.getParameters()) {
            DataModelParameter parameter = createParameterDataModel(methodParameter, type);
            template.getParameters().add(parameter);
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Error while getting method template parameter of '" + method.getElementName() + "'.", e);
    }
    // Collect data parameters for the given template
    TemplateDataSupport.collectParametersFromDataMethodInvocation(method, template, monitor);
    return template;
}
Also used : DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) ILocalVariable(org.eclipse.jdt.core.ILocalVariable) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 4 with DataModelTemplate

use of com.redhat.qute.commons.datamodel.DataModelTemplate in project quarkus-ls by redhat-developer.

the class TemplateGetDataModelProjectTest method quteQuickStart.

@Test
public void quteQuickStart() throws Exception {
    loadMavenProject(QuteMavenProjectName.qute_quickstart);
    QuteDataModelProjectParams params = new QuteDataModelProjectParams(QuteMavenProjectName.qute_quickstart);
    DataModelProject<DataModelTemplate<DataModelParameter>> project = QuteSupportForTemplate.getInstance().getDataModelProject(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertNotNull(project);
    // Test templates
    testTemplates(project);
    // Test value resolvers
    List<ValueResolverInfo> resolvers = project.getValueResolvers();
    Assert.assertNotNull(resolvers);
    Assert.assertFalse(resolvers.isEmpty());
    testValueResolversFomTemplateExtension(resolvers);
    testValueResolversFomInject(resolvers);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) QuteDataModelProjectParams(com.redhat.qute.commons.datamodel.QuteDataModelProjectParams) ValueResolverInfo(com.redhat.qute.commons.datamodel.resolvers.ValueResolverInfo) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) Test(org.junit.Test)

Example 5 with DataModelTemplate

use of com.redhat.qute.commons.datamodel.DataModelTemplate in project quarkus-ls by redhat-developer.

the class ExtendedDataModelProject method getAllNamespaces.

private static Set<String> getAllNamespaces(DataModelProject<DataModelTemplate<DataModelParameter>> project) {
    Set<String> allNamespaces = // 
    project.getValueResolvers().stream().filter(// 
    resolver -> resolver.getNamespace() != null).map(// 
    resolver -> resolver.getNamespace()).distinct().collect(Collectors.toSet());
    allNamespaces.add(NamespacePart.DATA_NAMESPACE);
    for (NamespaceResolverInfo info : project.getNamespaceResolverInfos().values()) {
        info.getNamespaces().forEach(namespace -> {
            allNamespaces.add(namespace);
        });
    }
    return allNamespaces;
}
Also used : DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) DataModelProject(com.redhat.qute.commons.datamodel.DataModelProject) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) Map(java.util.Map) Entry(java.util.Map.Entry) JavaElementKind(com.redhat.qute.commons.JavaElementKind) MATCH_NAME_ANY(com.redhat.qute.project.datamodel.resolvers.ValueResolver.MATCH_NAME_ANY) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) Collections(java.util.Collections) NamespaceResolverInfo(com.redhat.qute.commons.datamodel.resolvers.NamespaceResolverInfo) NamespaceResolverInfo(com.redhat.qute.commons.datamodel.resolvers.NamespaceResolverInfo)

Aggregations

DataModelTemplate (com.redhat.qute.commons.datamodel.DataModelTemplate)6 DataModelParameter (com.redhat.qute.commons.datamodel.DataModelParameter)5 DataModelProject (com.redhat.qute.commons.datamodel.DataModelProject)3 QuteDataModelProjectParams (com.redhat.qute.commons.datamodel.QuteDataModelProjectParams)2 ArrayList (java.util.ArrayList)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JavaElementKind (com.redhat.qute.commons.JavaElementKind)1 NamespaceResolverInfo (com.redhat.qute.commons.datamodel.resolvers.NamespaceResolverInfo)1 ValueResolverInfo (com.redhat.qute.commons.datamodel.resolvers.ValueResolverInfo)1 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)1 ExtendedDataModelProject (com.redhat.qute.project.datamodel.ExtendedDataModelProject)1 FieldValueResolver (com.redhat.qute.project.datamodel.resolvers.FieldValueResolver)1 MethodValueResolver (com.redhat.qute.project.datamodel.resolvers.MethodValueResolver)1 TypeValueResolver (com.redhat.qute.project.datamodel.resolvers.TypeValueResolver)1 MATCH_NAME_ANY (com.redhat.qute.project.datamodel.resolvers.ValueResolver.MATCH_NAME_ANY)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1