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));
}
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();
}
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;
}
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);
}
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;
}
Aggregations