Class AutoValueSupport

java.lang.Object
org.checkerframework.checker.calledmethods.builder.AutoValueSupport
All Implemented Interfaces:
BuilderFrameworkSupport

public class AutoValueSupport extends Object implements BuilderFrameworkSupport
AutoValue support for the Called Methods Checker. This class adds @CalledMethods annotations to the code generated by AutoValue.
  • Constructor Details

    • AutoValueSupport

      public AutoValueSupport(CalledMethodsAnnotatedTypeFactory atypeFactory)
      Create a new AutoValueSupport.
      Parameters:
      atypeFactory - the typechecker's type factory
  • Method Details

    • handleConstructor

      public void handleConstructor(NewClassTree tree, AnnotatedTypeMirror type)
      This method modifies the type of a copy constructor generated by AutoValue to match the type of the AutoValue toBuilder method, and has no effect if tree is a call to any other constructor.
      Specified by:
      handleConstructor in interface BuilderFrameworkSupport
      Parameters:
      tree - an AST for a constructor call
      type - type of the call expression
    • isBuilderBuildMethod

      public boolean isBuilderBuildMethod(ExecutableElement candidateBuildElement)
      Description copied from interface: BuilderFrameworkSupport
      Determines if a method is a build method on a Builder type for the builder framework.
      Specified by:
      isBuilderBuildMethod in interface BuilderFrameworkSupport
      Parameters:
      candidateBuildElement - a method
      Returns:
      true if candidateBuildElement is a build method on a Builder type for the builder framework
    • handleBuilderBuildMethod

      public void handleBuilderBuildMethod(AnnotatedTypeMirror.AnnotatedExecutableType builderBuildType)
      Description copied from interface: BuilderFrameworkSupport
      Hook for adding annotations to a build() method (i.e. a finalizer) generated by a builder framework.

      For build methods on Builder types, implementations of this method should determine the required properties and add a corresponding CalledMethods annotation to the type of the receiver parameter.

      Specified by:
      handleBuilderBuildMethod in interface BuilderFrameworkSupport
      Parameters:
      builderBuildType - the type of a method that is the build method (as determined by BuilderFrameworkSupport.isBuilderBuildMethod(ExecutableElement)) for a builder
    • isToBuilderMethod

      public boolean isToBuilderMethod(ExecutableElement candidateToBuilderElement)
      Description copied from interface: BuilderFrameworkSupport
      Determines if a method is a toBuilder method on a type generated by the builder framework.
      Specified by:
      isToBuilderMethod in interface BuilderFrameworkSupport
      Parameters:
      candidateToBuilderElement - a method
      Returns:
      true if candidateToBuilderElement is a toBuilder method on a type generated by the builder framework
    • handleToBuilderMethod

      public void handleToBuilderMethod(AnnotatedTypeMirror.AnnotatedExecutableType toBuilderType)
      Description copied from interface: BuilderFrameworkSupport
      Hook for supporting a builder framework's toBuilder routine. Typically, the returned Builder has had all of its required setters invoked. So, implementations of this method should add a CalledMethods annotation capturing this fact.
      Specified by:
      handleToBuilderMethod in interface BuilderFrameworkSupport
      Parameters:
      toBuilderType - the type of a method that is the toBuilder method (as determined by BuilderFrameworkSupport.isToBuilderMethod(ExecutableElement)) for a type that has an associated builder
    • getAllAbstractMethods

      public List<ExecutableElement> getAllAbstractMethods(TypeElement classElement)
      Get all the abstract methods for a class. This includes inherited abstract methods that are not overridden by the class or a superclass. There is no guarantee that this method will work as intended on code that implements an interface (which AutoValue classes are not supposed to do: https://github.com/google/auto/blob/master/value/userguide/howto.md#inherit).
      Parameters:
      classElement - the class
      Returns:
      list of all abstract methods