java.lang.Object
io.helidon.service.codegen.DefaultsCodegen
Code generation for handling of
Default
annotations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Information about a default element. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
codegenOptional
(ContentBuilder<?> contentBuilder, DefaultsCodegen.DefaultCode defaultCode, FieldHandler constantHandler, DefaultsParams params) Code generate default handling after an optional of the correct type.static Optional
<DefaultsCodegen.DefaultCode> findDefault
(Set<Annotation> annotations, TypeName targetType) Find a default annotation within the set of annotations on an element.
-
Method Details
-
findDefault
public static Optional<DefaultsCodegen.DefaultCode> findDefault(Set<Annotation> annotations, TypeName targetType) Find a default annotation within the set of annotations on an element.- Parameters:
annotations
- annotations on an elementtargetType
- type that is expected in the code- Returns:
- default annotation, or empty if no default is defined
-
codegenOptional
public static void codegenOptional(ContentBuilder<?> contentBuilder, DefaultsCodegen.DefaultCode defaultCode, FieldHandler constantHandler, DefaultsParams params) Code generate default handling after an optional of the correct type.Example with fixed default value (such as
Default.Int
:headers.find(MY_HEADER) .map(Header::getInt) // this is expected to be part of the already generated code // will be generated by this method .orElse(42)
Example with mapping (when using
Default.Value
and a non-string type):headers.find(MY_HEADER) .map(Header::getInt) // this is expected to be part of the already generated code // will be generated by this method .orElseGet(() -> mappers.map("Default Value", GenericType.STRING, GTYPE_1, "headers"))
-mappers
- common Mappers instance, must exist in the current class, name is provided as a parameter to this method -GTYPE_1
- genericTypeNameField provided as a parameter to this method (must be generated by caller)- Parameters:
contentBuilder
- content builder that we add the code todefaultCode
- as returned byfindDefault(java.util.Set, io.helidon.common.types.TypeName)
constantHandler
- handler of constantsparams
- additional parameters, needed depending on type of the default
-