Package 

Class AutoValueTypePrinter

  • All Implemented Interfaces:
    com.airbnb.mvrx.mocking.printer.TypePrinter

    
    public final class AutoValueTypePrinter
     implements TypePrinter<Any>
                        

    This looks for classes generated via AutoValue, indicated by the class prefix GENERATED_PREFIX. When an autovalue class is found, code to reconstruct it is generated by reflectively accessing the Builder and its setter functions.

    This relies on the class using the naming pattern of builder() and build() for its functions, as well as Builder for its builder class.

    • Method Summary

      Modifier and Type Method Description
      Boolean acceptsObject(Object obj) Return true if obj is a valid object to pass to generateCode.
      String generateCode(Object instance, Function1<Object, String> generateConstructor) A function that takes an instance of an object and returns a String representing the Kotlin code that can be used to recreate the instance with the same data.
      List<String> modifyImports(List<String> imports) Optionally modify the import statements that will be added to the generated mock file.
      • Methods inherited from class java.lang.Object

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

      • AutoValueTypePrinter

        AutoValueTypePrinter()
    • Method Detail

      • generateCode

         String generateCode(Object instance, Function1<Object, String> generateConstructor)

        A function that takes an instance of an object and returns a String representing the Kotlin code that can be used to recreate the instance with the same data.

        Parameters:
        generateConstructor - This function can be used to access the default code generation for arbitrary object types.
      • modifyImports

         List<String> modifyImports(List<String> imports)

        Optionally modify the import statements that will be added to the generated mock file. By default, each processed type is added as an import.

        This function can be used if your generated code depends on anything beyond the instance types that are processed.

        This will be called once per registered TypePrinter, after all other code has been generated, but only if this instance is actually used to generated code (ie it returned true from acceptsObject at least once).