001package io.jstach.jstachio.spi; 002 003import java.util.List; 004 005import io.jstach.jstachio.Template; 006import io.jstach.jstachio.TemplateConfig; 007import io.jstach.jstachio.TemplateInfo; 008 009/** 010 * A {@link java.util.ServiceLoader} interface for finding {@link Template}s. 011 * <p> 012 * In non modular applications the Templates can be found using this interface and the 013 * {@link java.util.ServiceLoader} mechanism through the <code>META-INF/services</code> 014 * file as the code generator generates the services file. However in modular applications 015 * this is not possible as the implementations are described in the module-info.java and 016 * the code generator does not touch that. 017 * <p> 018 * Regardless of modular or not the generated META-INF/services also might give hints to 019 * Graal native compilation for reflective access to the templates. 020 * 021 * @author agentgt 022 */ 023public interface TemplateProvider { 024 025 /** 026 * Provides a list of instantiated renderers. 027 * @param templateConfig template collaborators. 028 * @return a list of renderers. An empty list would mean none were found. 029 */ 030 public List<Template<?>> provideTemplates(TemplateConfig templateConfig); 031 032 /** 033 * Provides templates with empty config. 034 * @return a list of templates. An empty list would mean none were fond. 035 */ 036 default List<Template<?>> provideTemplates() { 037 return provideTemplates(TemplateConfig.empty()); 038 } 039 040 /** 041 * Generated template providers implement this interface to support easier 042 * ServiceLoader registration for modular libraries/applications. <strong>It is mainly 043 * an implementation detail and not recommended for manual usage.</strong> 044 * 045 * @author agentgt 046 */ 047 public interface GeneratedTemplateProvider extends TemplateProvider, JStachioTemplateFinder.SimpleTemplateFinder { 048 049 @Override 050 default Iterable<? extends TemplateInfo> templates() { 051 return provideTemplates(); 052 } 053 054 } 055 056}