Class ImmutablesBuilderProvider

java.lang.Object
org.mapstruct.ap.spi.DefaultBuilderProvider
de.firehead.mapstruct.spi.protobuf.builderprovider.ImmutablesBuilderProvider
All Implemented Interfaces:
org.mapstruct.ap.spi.BuilderProvider

@Experimental("The Immutables builder provider might change in a subsequent release") public class ImmutablesBuilderProvider extends org.mapstruct.ap.spi.DefaultBuilderProvider
Builder provider for Immutables. A custom provider is needed because Immutables creates an implementation of an interface and that implementation has the builder. This implementation would try to find the type created by Immutables and would look for the builder in it. Only types annotated with the org.immutables.value.Value.Immutable are considered for this discovery.
Author:
Filip Hrisafov
  • Constructor Details

    • ImmutablesBuilderProvider

      public ImmutablesBuilderProvider()
  • Method Details

    • findBuilderInfo

      protected org.mapstruct.ap.spi.BuilderInfo findBuilderInfo(TypeElement typeElement)
      Overrides:
      findBuilderInfo in class org.mapstruct.ap.spi.DefaultBuilderProvider
    • findBuilderInfoForImmutables

      protected org.mapstruct.ap.spi.BuilderInfo findBuilderInfoForImmutables(TypeElement targetTypeElement, TypeElement immutableAnnotation)
      Finds the builder info for the given type or returns null if not found.
      Parameters:
      targetTypeElement - a type which may require a builder
      immutableAnnotation - type of the immutables annotation we're looking for
      Returns:
      BuilderInfo or null if none found
      Throws:
      org.mapstruct.ap.spi.TypeHierarchyErroneousException - if unable to process in this round
    • findTypeWithImmutableAnnotation

      protected Optional<TypeElement> findTypeWithImmutableAnnotation(TypeElement targetTypeElement, TypeMirror immutableAnnotationTypeMirror)
      This method looks for the Value.Immutable on the targetTypeElement in the following order:

      1) directly on the element itself 2) on an interface in the same package that the element implements 3) on the superclass for the element

      We're looking for the immutable annotation since there could be additional annotations there which affect the name of the generated immutable builder.

      Parameters:
      targetTypeElement - element to analyze for the immutables annotation
      immutableAnnotationTypeMirror - type of the annotation we're looking for
      Returns:
      first found element with the type or empty
    • asImmutableElement

      protected TypeElement asImmutableElement(TypeElement typeElement)
      Parameters:
      typeElement - element that has the Value.Immutable annotation
      Returns:
      type that should have the builder or null if none found
    • enclosingQualifierFromStyle

      protected String enclosingQualifierFromStyle(AnnotationMirror style, Element element)
    • builderFromStyle

      protected String builderFromStyle(AnnotationMirror style, TypeElement element, boolean valueEnclosingFound)
    • nameWithoutAbstractPrefix

      protected String nameWithoutAbstractPrefix(AnnotationMirror style, Element element)
    • getSingleAnnotationValue

      protected Optional<String> getSingleAnnotationValue(String annotationKey, AnnotationMirror style)
    • getTypeAbstractValues

      protected List<String> getTypeAbstractValues(AnnotationMirror styleOrNull)
    • hasValueEnclosingAnnotation

      protected boolean hasValueEnclosingAnnotation(Element enclosingElement)
    • findStyle

      protected AnnotationMirror findStyle(Element element)
    • immutableNameFromStylePattern

      protected String immutableNameFromStylePattern(String simpleNameOfElement, String typeImmutablePattern)
    • findPackage

      protected String findPackage(Element element)