Class FormatCodeBlocks
java.lang.Object
no.sikt.graphitron.generators.codebuilding.FormatCodeBlocks
Class containing various helper methods for constructing code with javapoet.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull CodeBlockaddStringIfNotEmpty(String target, String addition) static @NotNull CodeBlockstatic @NotNull CodeBlockstatic @NotNull CodeBlockstatic CodeBlockapplyGlobalTransforms(String recordName, TypeName recordTypeName, TransformScope scope) static CodeBlockapplyTransform(String recordName, TypeName recordTypeName, Method transform) static CodeBlockstatic CodeBlockstatic CodeBlockasMethodCall(String method) static CodeBlockasMethodCall(String source, String method) static CodeBlockasMethodCall(TypeName source, String method) static @NotNull CodeBlockstatic CodeBlockconnectionFunction(ConnectionObjectDefinition connectionType, ObjectDefinition pageInfoType) static @NotNull CodeBlockcontinueCheck(String value) static @NotNull CodeBlockcountFunction(String queryLocation, String queryMethodName, String inputList, boolean isService) static CodeBlockcreateNodeIdBlock(ObjectDefinition obj, String targetAlias) static CodeBlockstatic CodeBlockstatic CodeBlockstatic CodeBlockdeclareArgs(ObjectField target) static @NotNull CodeBlockdeclarePageSize(int defaultFirst) static CodeBlockdeclareRecord(String name, RecordObjectSpecification<?> input, boolean isIterable, boolean isResolver) static @NotNull CodeBlockstatic CodeBlockempty()static CodeBlockfetchMapping(boolean iterable) static @NotNull CodeBlockstatic CodeBlockgetIDMappingCode(MapperContext context, ObjectField field, ProcessedSchema schema, InputParser parser) static @NotNull CodeBlockgetNodeQueryCallBlock(GenerationField field, String variableName, CodeBlock path, boolean atResolver) static CodeBlockgetPrimaryKeyFieldsBlock(String targetAlias) static ClassNamegetQueryClassName(String queryLocation) static @NotNull CodeBlockgetValue(String container, MethodMapping mapping) static CodeBlockhasIdBlock(String id, ObjectDefinition obj, String targetAlias) static CodeBlockhasIdsBlock(String idParamName, ObjectDefinition obj, String targetAlias) static CodeBlockhasIdsBlock(String idParamName, ObjectDefinition obj, String targetAlias, boolean isIterableWrapped) static CodeBlockhasIdsBlock(ObjectDefinition obj, String targetAlias) static @NotNull CodeBlockstatic @NotNull CodeBlockindentIfMultiline(CodeBlock code) static @NotNull CodeBlockstatic CodeBlockstatic @NotNull CodeBlocklistedNullCheck(String variable, CodeBlock code) static @NotNull CodeBlocklistOf()static @NotNull CodeBlockstatic @NotNull CodeBlockstatic @NotNull CodeBlockstatic CodeBlockmakeEnumMapBlock(String inputVariable, CodeBlock valueLists) static CodeBlockmakeEnumMapBlock(CodeBlock inputVariable, CodeBlock valueLists) static CodeBlockmakeResponses(MapperContext context, ObjectField field, ProcessedSchema schema, InputParser parser) static @NotNull CodeBlockmapOf()static @NotNull CodeBlockstatic @NotNull CodeBlockstatic @NotNull CodeBlocknullIfNullElse(CodeBlock code) static @NotNull CodeBlocknullIfNullElseThis(CodeBlock code) static @NotNull CodeBlockqueryFunction(String queryLocation, String queryMethodName, String inputList, boolean hasIds, boolean usesIds, boolean isService) static CodeBlockrecordTransformPart(String transformerName, String varName, String typeName, boolean isJava, boolean isInput) static @NotNull CodeBlockreturnCompletedFuture(String variable) static @NotNull CodeBlockstatic @NotNull CodeBlockreturnWrap(String variable) static @NotNull CodeBlockreturnWrap(CodeBlock code) static @NotNull CodeBlockselectionSetLookup(String path, boolean atResolver, boolean useArguments) static @NotNull CodeBlocksetOf()static @NotNull CodeBlockstatic @NotNull CodeBlockstatic @NotNull CodeBlocksetValue(String container, MethodMapping mapping, String value) static @NotNull CodeBlocksetValue(String container, MethodMapping mapping, CodeBlock value) static CodeBlocktoGraphEnumConverter(String enumType, CodeBlock field, boolean toRecord, ProcessedSchema schema) static CodeBlocktoJOOQEnumConverter(String enumType, ProcessedSchema schema) static @NotNull CodeBlockwrapCoalesce(CodeBlock code) static @NotNull CodeBlockstatic @NotNull CodeBlockwrapForIndexed(String variable, CodeBlock code) static @NotNull CodeBlockwrapNotNull(String valueToCheck, CodeBlock code) static @NotNull CodeBlockwrapObjectRow(CodeBlock code) static @NotNull CodeBlock
-
Constructor Details
-
FormatCodeBlocks
public FormatCodeBlocks()
-
-
Method Details
-
declareRecord
public static CodeBlock declareRecord(String name, RecordObjectSpecification<?> input, boolean isIterable, boolean isResolver) - Parameters:
name- Name of a field that should be declared as a record. This will be the name of the variable.input- Input type that should be declared as a record.isIterable- Is this record wrapped in a list?isResolver- Is this declaration to be used in a resolver?- Returns:
- CodeBlock that declares a new record variable and that attaches context configuration if needed.
-
recordTransformPart
-
declare
- Parameters:
name- Name of the variable.typeName- The type of the variable to declare.asList- Declare this type as an ArrayList?- Returns:
- CodeBlock that declares a simple variable.
-
declare
- Parameters:
name- Name of the variable.block- The statement result to declare.- Returns:
- CodeBlock that declares a simple variable.
-
declare
- Parameters:
name- Name of the variable.type- The type to declare.- Returns:
- CodeBlock that declares a simple variable.
-
ifNotNull
- Returns:
- CodeBlock that contains an if statement with a null check on the provided name.
-
empty
- Returns:
- empty CodeBlock
-
addToList
- Parameters:
addTarget- Name of updatable collection to add something to.addition- The name of the content that should be added.- Returns:
- CodeBlock that adds something to an updatable collection.
-
addToList
- Parameters:
addTarget- Name of updatable collection to add something to, as well as what is added. For the collection a "List" suffix is assumed.- Returns:
- CodeBlock that adds something to an updatable collection.
-
addToList
- Parameters:
addTarget- Name of updatable collection to add something to.codeAddition- The CodeBlock that provides something that should be added.- Returns:
- CodeBlock that adds something to an updatable collection.
-
listOf
- Returns:
- CodeBlock that creates an empty List.
-
listOf
- Returns:
- CodeBlock that wraps the supplied CodeBlock in a List.
-
listOf
- Returns:
- CodeBlock that wraps the supplied variable name in a List.
-
listOfIf
- Returns:
- CodeBlock that wraps the provided CodeBlock in a Java list provided the condition is true.
-
setOf
- Returns:
- CodeBlock that creates an empty Set.
-
setOf
- Returns:
- CodeBlock that wraps the supplied CodeBlock in a Set.
-
setOf
- Returns:
- CodeBlock that wraps the supplied variable name in a Set.
-
mapOf
- Returns:
- CodeBlock that creates an empty Map.
-
asMethodCall
- Returns:
- CodeBlock that wraps this method name in a method call format.
-
asMethodCall
- Returns:
- CodeBlock that wraps this method name in a method call format after the specified source.
-
asMethodCall
- Returns:
- CodeBlock that wraps this method name in a static method call format after the specified source.
-
asCast
- Returns:
- CodeBlock that wraps this variable in a Java cast.
-
asCast
- Returns:
- CodeBlock that wraps this code in a Java cast.
-
collectToList
- Returns:
- CodeBlock that adds a collect to List call to be used on a Stream.
-
findFirst
- Returns:
- CodeBlock that adds a findFirst call to be used on a collection.
-
nullIfNullElse
- Returns:
- CodeBlock that wraps the provided CodeBlock name in a simple null check.
-
nullIfNullElseThis
- Returns:
- CodeBlock that wraps the provided CodeBlock name in a simple null check.
-
listedNullCheck
- Returns:
- CodeBlock that wraps the provided CodeBlock name in a mapping null check.
-
addStringIfNotEmpty
- Returns:
- CodeBlock that adds something to a String if it is not empty.
-
selectionSetLookup
@NotNull public static @NotNull CodeBlock selectionSetLookup(String path, boolean atResolver, boolean useArguments) - Returns:
- CodeBlock that checks whether a path is in use.
-
setValue
@NotNull public static @NotNull CodeBlock setValue(String container, MethodMapping mapping, CodeBlock value) - Returns:
- CodeBlock that sets a value through a mapping.
-
setValue
@NotNull public static @NotNull CodeBlock setValue(String container, MethodMapping mapping, String value) - Returns:
- CodeBlock that sets a value through a mapping.
-
getValue
- Returns:
- CodeBlock that gets a value through a mapping.
-
newDataFetcher
- Returns:
- CodeBlock that creates a data fetcher object.
-
newServiceDataFetcherWithTransform
- Returns:
- CodeBlock that creates a service data fetcher through a transform object.
-
declareTransform
- Returns:
- CodeBlock that declares a resolver transformer.
-
continueCheck
- Returns:
- CodeBlock does a null check on the variable and runs continue if it is.
-
countFunction
@NotNull public static @NotNull CodeBlock countFunction(String queryLocation, String queryMethodName, String inputList, boolean isService) - Returns:
- CodeBlock consisting of a function for a count DB call.
-
getQueryClassName
-
queryFunction
@NotNull public static @NotNull CodeBlock queryFunction(String queryLocation, String queryMethodName, String inputList, boolean hasIds, boolean usesIds, boolean isService) - Returns:
- CodeBlock consisting of a function for a generic DB call.
-
connectionFunction
public static CodeBlock connectionFunction(ConnectionObjectDefinition connectionType, ObjectDefinition pageInfoType) - Returns:
- CodeBlock for a function that maps relay connection types.
-
getNodeQueryCallBlock
@NotNull public static @NotNull CodeBlock getNodeQueryCallBlock(GenerationField field, String variableName, CodeBlock path, boolean atResolver) - Returns:
- CodeBlock consisting of a function for an ID fetch DB call.
-
declarePageSize
- Returns:
- CodeBlock consisting of a declaration of the page size variable through a method call.
-
wrapNotNull
- Returns:
- CodeBlock that wraps the provided CodeBlock in an if not null check.
-
wrapFor
- Returns:
- CodeBlock that wraps the provided CodeBlock in a for loop.
-
wrapForIndexed
- Returns:
- CodeBlock that wraps the provided CodeBlock in an indexed for loop.
-
wrapRow
- Returns:
- CodeBlock that wraps the provided CodeBlock in a jOOQ row.
-
wrapObjectRow
- Returns:
- CodeBlock that wraps the provided CodeBlock in a jOOQ row.
-
wrapCoalesce
- Returns:
- CodeBlock that wraps the provided CodeBlock in a jOOQ coalesce.
-
inline
- Returns:
- CodeBlock that wraps the provided CodeBlock in a jOOQ inline.
-
indentIfMultiline
- Returns:
- Add appropriate indentation if this code has multiple lines.
-
join
- Returns:
- Join several CodeBlocks.
-
makeEnumMapBlock
- Returns:
- CodeBlock that sends this variable through an enum mapping.
-
makeEnumMapBlock
- Returns:
- CodeBlock that sends this variable through an enum mapping.
-
toJOOQEnumConverter
- Returns:
- Code block containing the enum conversion method call with anonymous function declarations.
-
toGraphEnumConverter
public static CodeBlock toGraphEnumConverter(String enumType, CodeBlock field, boolean toRecord, ProcessedSchema schema) - Returns:
- Code block containing the enum conversion method call.
-
applyGlobalTransforms
public static CodeBlock applyGlobalTransforms(String recordName, TypeName recordTypeName, TransformScope scope) - Parameters:
recordName- Name of the record to transform.scope- The scope of transforms that should be applied. Currently onlyTransformScope.ALL_MUTATIONSis supported.- Returns:
- CodeBlock where all defined global transforms are applied to the record.
-
applyTransform
public static CodeBlock applyTransform(String recordName, TypeName recordTypeName, Method transform) - Parameters:
recordName- Name of the record to transform.transform- The method that should transform the record.- Returns:
- CodeBlock where the transform is applied to the record.
-
makeResponses
public static CodeBlock makeResponses(MapperContext context, ObjectField field, ProcessedSchema schema, InputParser parser) - Returns:
- Code for constructing any structure of response types.
-
getIDMappingCode
public static CodeBlock getIDMappingCode(MapperContext context, ObjectField field, ProcessedSchema schema, InputParser parser) -
fetchMapping
-
declareArgs
-
returnWrap
- Returns:
- CodeBlock that returns the provided name.
-
returnWrap
- Returns:
- CodeBlock that returns the provided code.
-
returnCompletedFuture
- Returns:
- CodeBlock that wraps and returns the provided variable in a CompletableFuture.
-
returnCompletedFuture
- Returns:
- CodeBlock that wraps and returns the provided CodeBlock in a CompletableFuture.
-
createNodeIdBlock
-
hasIdsBlock
public static CodeBlock hasIdsBlock(String idParamName, ObjectDefinition obj, String targetAlias, boolean isIterableWrapped) -
hasIdBlock
-
hasIdsBlock
-
hasIdsBlock
-
getPrimaryKeyFieldsBlock
-