Class IteratingWrapperClassBuilder

java.lang.Object
com.google.common.truth.codegen.IteratingWrapperClassBuilder

@GwtIncompatible("java.lang.reflect.*") public class IteratingWrapperClassBuilder extends Object
A builder of classes to wrap a provided SubjectFactory's concrete Subject subclass. The generated class will be a direct subclass of the concrete Subject subclass, but each public, protected, or friendly method not declared by Object will be wrapped such that invocations on it will be invoked on a new Subject instance populated with an element in the provided collection. This allows for a type-safe, IDE-discoverable Subject in a for-each style.
  • Field Details

    • CLASS_TEMPLATE

      private static final String CLASS_TEMPLATE

      A string intended for use in String.format() representing the text of the code of the wrapper class.

      Format parameters include:

      1. package name
      2. simple name of a concrete subtype of Subject
      3. the fully qualified name of the target type
      4. the text of the code of the wrapped methods

      See Also:
    • WRAPPER_METHOD_TEMPLATE

      private static final String WRAPPER_METHOD_TEMPLATE

      A string intended for use in String.format() representing the text of the code of all wrapped methods.

      Format parameters include:

      1. visibility
      2. fully qualified name of the return type
      3. method name
      4. method's parameter list
      5. the target type of the Subject
      6. concrete subtype of Subject to be wrapped
      7. parameter list

      See Also:
    • TARGET_TYPE_PARAMETER

      private static final int TARGET_TYPE_PARAMETER
      See Also:
    • ITERATING_WRAPPER

      private static final String ITERATING_WRAPPER
      See Also:
    • subjectFactory

      private final SubjectFactory<?,?> subjectFactory
    • className

      public final String className
  • Constructor Details

    • IteratingWrapperClassBuilder

      public IteratingWrapperClassBuilder(SubjectFactory<?,?> subjectFactory)
  • Method Details

    • build

      public String build()
    • appendMethodWrapper

      private void appendMethodWrapper(StringBuilder code, Class<?> subjectType, Class<?> targetType, Method method)
    • methodParameterList

      private static StringBuilder methodParameterList(int length)
    • methodSignature

      private static StringBuilder methodSignature(Class<?>[] parameters, Annotation[][] annotations)
      Builds a string for the parameters within a method signature.
    • stringVisibility

      private static String stringVisibility(int modifiers)