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
-
Field Summary
Fields inherited from class org.mapstruct.ap.spi.DefaultBuilderProvider
elementUtils, typeUtils -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TypeElementasImmutableElement(TypeElement typeElement) protected StringbuilderFromStyle(AnnotationMirror style, TypeElement element, boolean valueEnclosingFound) protected StringenclosingQualifierFromStyle(AnnotationMirror style, Element element) protected org.mapstruct.ap.spi.BuilderInfofindBuilderInfo(TypeElement typeElement) protected org.mapstruct.ap.spi.BuilderInfofindBuilderInfoForImmutables(TypeElement targetTypeElement, TypeElement immutableAnnotation) Finds the builder info for the given type or returns null if not found.protected StringfindPackage(Element element) protected AnnotationMirrorprotected Optional<TypeElement>findTypeWithImmutableAnnotation(TypeElement targetTypeElement, TypeMirror immutableAnnotationTypeMirror) This method looks for theValue.Immutableon the targetTypeElement in the following order:getSingleAnnotationValue(String annotationKey, AnnotationMirror style) getTypeAbstractValues(AnnotationMirror styleOrNull) protected booleanhasValueEnclosingAnnotation(Element enclosingElement) protected StringimmutableNameFromStylePattern(String simpleNameOfElement, String typeImmutablePattern) protected StringnameWithoutAbstractPrefix(AnnotationMirror style, Element element) Methods inherited from class org.mapstruct.ap.spi.DefaultBuilderProvider
findBuilderInfo, findBuildMethods, getTypeElement, init, isBuildMethod, isBuildMethod, isPossibleBuilderCreationMethod, shouldIgnore
-
Constructor Details
-
ImmutablesBuilderProvider
public ImmutablesBuilderProvider()
-
-
Method Details
-
findBuilderInfo
- Overrides:
findBuilderInfoin classorg.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 builderimmutableAnnotation- 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 theValue.Immutableon 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 annotationimmutableAnnotationTypeMirror- type of the annotation we're looking for- Returns:
- first found element with the type or empty
-
asImmutableElement
- Parameters:
typeElement- element that has the Value.Immutable annotation- Returns:
- type that should have the builder or null if none found
-
enclosingQualifierFromStyle
-
builderFromStyle
protected String builderFromStyle(AnnotationMirror style, TypeElement element, boolean valueEnclosingFound) -
nameWithoutAbstractPrefix
-
getSingleAnnotationValue
-
getTypeAbstractValues
-
hasValueEnclosingAnnotation
-
findStyle
-
immutableNameFromStylePattern
-
findPackage
-