Class ToPrettyStringExtension

    • Constructor Detail

      • ToPrettyStringExtension

        public ToPrettyStringExtension()
    • Method Detail

      • generateClass

        public String generateClass​(AutoValueExtension.Context context,
                                    String className,
                                    String classToExtend,
                                    boolean isFinal)
        Description copied from class: AutoValueExtension
        Returns the generated source code of the class named className to extend classToExtend, or null if this extension does not generate a class in the hierarchy. If there is a generated class, it should be final if isFinal is true; otherwise it should be abstract. The returned string should be a complete Java class definition of the class className in the package context.packageName().

        The returned string will typically look like this:

        
         package <package>;
         ...
         <finalOrAbstract> class <className> extends <classToExtend> {
           // Constructor
           <className>(<constructorParameters>) {
             super(<constructorParameterNames>);
             ...
           }
           ...
         }
         

        Here, <package> is AutoValueExtension.Context.packageName(); <finalOrAbstract> is the keyword final if isFinal is true or abstract otherwise; and <className> and <classToExtend> are the values of this method's parameters of the same name. The <constructorParameters> and <constructorParameterNames> are typically derived from AutoValueExtension.Context.propertyTypes().

        An extension can also generate a subclass of the nested Builder class if there is one. In that case, it should check if AutoValueExtension.BuilderContext.toBuilderMethods() is empty. If not, the Builder subclass should include a "copy constructor", like this:

        
         ...
         <finalOrAbstract> class <className> extends <classToExtend> {
           ...
           static class Builder extends <classToExtend>.Builder {
             Builder() {}
             Builder(<autoValueClass> copyFrom) {
               super(copyFrom);
             }
             ...
           }
         }
         

        Here, <autoValueClass> is AutoValueExtension.Context.autoValueClass().}

        Specified by:
        generateClass in class AutoValueExtension
        Parameters:
        context - The AutoValueExtension.Context of the code generation for this class.
        className - The simple name of the resulting class. The returned code will be written to a file named accordingly.
        classToExtend - The simple name of the direct parent of the generated class. This could be the AutoValue generated class, or a class generated as the result of another Extension.
        isFinal - True if this class is the last class in the chain, meaning it should be marked as final. Otherwise it should be marked as abstract.
        Returns:
        The source code of the generated class, or null if this extension does not generate a class in the hierarchy.
      • consumeMethods

        public com.google.common.collect.ImmutableSet<ExecutableElement> consumeMethods​(AutoValueExtension.Context context)
        Description copied from class: AutoValueExtension
        Returns a possibly empty set of abstract methods that this Extension intends to implement. This will prevent AutoValue from generating an implementation, in cases where it would have, and it will also avoid complaints about abstract methods that AutoValue doesn't expect. The default set returned by this method is empty.

        Each returned method must be one of the abstract methods in AutoValueExtension.Context.abstractMethods().

        For example, Android's Parcelable interface includes a method void writeToParcel(Parcel, int). Normally AutoValue would not know what to do with that abstract method. But an AutoValueExtension that understands Parcelable can provide a useful implementation and return the writeToParcel method here. That will prevent a warning about the method from AutoValue.

        Overrides:
        consumeMethods in class AutoValueExtension
        Parameters:
        context - the Context of the code generation for this class.