Class TemplateVars

  • Direct Known Subclasses:
    AutoAnnotationTemplateVars, AutoValueOrOneOfTemplateVars, GwtSerialization.GwtTemplateVars

    abstract class TemplateVars
    extends java.lang.Object
    A template and a set of variables to be substituted into that template. A concrete subclass of this class defines a set of fields that are template variables, and an implementation of the parsedTemplate() method which is the template to substitute them into. Once the values of the fields have been assigned, the toText() method returns the result of substituting them into the template.

    The subclass may be a direct subclass of this class or a more distant descendant. Every field in the starting class and its ancestors up to this class will be included. Fields cannot be static unless they are also final. They cannot be private, though they can be package-private if the class is in the same package as this class. They cannot be primitive or null, so that there is a clear indication when a field has not been set.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private com.google.common.collect.ImmutableList<java.lang.reflect.Field> fields  
    • Constructor Summary

      Constructors 
      Constructor Description
      TemplateVars()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private static void addFields​(com.google.common.collect.ImmutableList.Builder<java.lang.reflect.Field> fieldsBuilder, java.lang.reflect.Field[] declaredFields)  
      private static java.lang.Object fieldValue​(java.lang.reflect.Field field, java.lang.Object container)  
      private static com.google.common.collect.ImmutableList<java.lang.reflect.Field> getFields​(java.lang.Class<?> c)  
      private static java.io.InputStream inputStreamFromFile​(java.net.URL resourceUrl)  
      private static java.io.InputStream inputStreamFromJar​(java.net.URL resourceUrl)  
      private static boolean isStaticFinal​(java.lang.reflect.Field field)  
      (package private) abstract Template parsedTemplate()  
      (package private) static Template parsedTemplateForResource​(java.lang.String resourceName)  
      private static java.io.Reader readerFromResource​(java.lang.String resourceName)  
      private static java.io.Reader readerFromUrl​(java.lang.String resourceName)  
      private static Template retryParseAfterException​(java.lang.String resourceName, java.lang.Exception exception)  
      (package private) java.lang.String toText()
      Returns the result of substituting the variables defined by the fields of this class (a concrete subclass of TemplateVars) into the template returned by parsedTemplate().
      private java.util.Map<java.lang.String,​java.lang.Object> toVars()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fields

        private final com.google.common.collect.ImmutableList<java.lang.reflect.Field> fields
    • Constructor Detail

      • TemplateVars

        TemplateVars()
    • Method Detail

      • parsedTemplate

        abstract Template parsedTemplate()
      • getFields

        private static com.google.common.collect.ImmutableList<java.lang.reflect.Field> getFields​(java.lang.Class<?> c)
      • addFields

        private static void addFields​(com.google.common.collect.ImmutableList.Builder<java.lang.reflect.Field> fieldsBuilder,
                                      java.lang.reflect.Field[] declaredFields)
      • toText

        java.lang.String toText()
        Returns the result of substituting the variables defined by the fields of this class (a concrete subclass of TemplateVars) into the template returned by parsedTemplate().
      • toVars

        private java.util.Map<java.lang.String,​java.lang.Object> toVars()
      • parsedTemplateForResource

        static Template parsedTemplateForResource​(java.lang.String resourceName)
      • retryParseAfterException

        private static Template retryParseAfterException​(java.lang.String resourceName,
                                                         java.lang.Exception exception)
      • readerFromResource

        private static java.io.Reader readerFromResource​(java.lang.String resourceName)
      • readerFromUrl

        private static java.io.Reader readerFromUrl​(java.lang.String resourceName)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • inputStreamFromJar

        private static java.io.InputStream inputStreamFromJar​(java.net.URL resourceUrl)
                                                       throws java.net.URISyntaxException,
                                                              java.io.IOException
        Throws:
        java.net.URISyntaxException
        java.io.IOException
      • inputStreamFromFile

        private static java.io.InputStream inputStreamFromFile​(java.net.URL resourceUrl)
                                                        throws java.io.IOException,
                                                               java.net.URISyntaxException
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • fieldValue

        private static java.lang.Object fieldValue​(java.lang.reflect.Field field,
                                                   java.lang.Object container)
      • isStaticFinal

        private static boolean isStaticFinal​(java.lang.reflect.Field field)