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(RecordObjectSpecification<?> obj, String targetAlias) static CodeBlockcreateNodeIdBlockForRecord(RecordObjectSpecification<?> obj, String recordVariableName) static @NotNull CodeBlockdeclarePageSize(int defaultFirst) static CodeBlockdeclareRecord(String name, RecordObjectSpecification<?> input, boolean isIterable, boolean isResolver) static @NotNull CodeBlockstatic 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 CodeBlockgetPrimaryKeyFieldsWithTableAliasBlock(String targetAlias) static ClassNamegetQueryClassName(String queryLocation) static CodeBlockgetSelectKeyColumn(FetchContext context) static CodeBlockgetSelectKeyColumn(org.jooq.Key<?> key, String tableName, String aliasVariableName) static CodeBlockgetSelectKeyColumnRow(FetchContext context) Returns codeblock for selecting key columns for the resolver keystatic CodeBlockgetSelectKeyColumnRow(org.jooq.Key<?> key, String tableName, String aliasVariableName) Returns the select code for the columns of a key.static @NotNull CodeBlockgetValue(String container, MethodMapping mapping) static CodeBlockhasIdBlock(CodeBlock id, RecordObjectSpecification<?> obj, String targetAlias) static CodeBlockhasIdOrIdsBlock(CodeBlock idOrRecordParamName, RecordObjectSpecification<?> obj, String targetAlias, CodeBlock mappedFkFields, boolean isMultiple) static CodeBlockhasIdsBlock(RecordObjectSpecification<?> obj, String targetAlias) static @NotNull CodeBlockstatic @NotNull CodeBlockindentIfMultiline(CodeBlock code) static @NotNull CodeBlockstatic CodeBlockinResolverKeysBlock(String resolverKeyParamName, FetchContext context) static @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 CodeBlockstatic CodeBlocknodeIdColumnsWithAliasBlock(String targetAlias, RecordObjectSpecification<?> obj) static @NotNull CodeBlocknullIfNullElse(CodeBlock code) static @NotNull CodeBlocknullIfNullElseThis(CodeBlock code) static @NotNull CodeBlockqueryFunction(String queryLocation, String queryMethodName, String inputList, boolean hasKeyValues, boolean usesKeyValues, boolean isService) static CodeBlockrecordTransformPart(String transformerName, String varName, String typeName, boolean isJava, boolean isInput) static CodeBlockreferenceNodeIdColumnsBlock(RecordObjectSpecification<?> container, RecordObjectSpecification<?> target, org.jooq.ForeignKey<?, ?> fk) static CodeBlockreferenceNodeIdColumnsBlock(RecordObjectSpecification<?> container, RecordObjectSpecification<?> target, org.jooq.ForeignKey<?, ?> fk, CodeBlock tableReference) 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, CodeBlock value) static @NotNull CodeBlocksetValue(String container, MethodMapping mapping, CodeBlock value, boolean isResolverKey) 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
-
ifNotNull
- Returns:
- CodeBlock that contains an if statement with a null check on the provided name.
-
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, boolean isResolverKey) - Returns:
- CodeBlock that sets a value through a mapping.
-
setValue
@NotNull public static @NotNull CodeBlock setValue(String container, MethodMapping mapping, CodeBlock 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 hasKeyValues, boolean usesKeyValues, 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.
-
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
-
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.
-
inResolverKeysBlock
-
getSelectKeyColumnRow
public static CodeBlock getSelectKeyColumnRow(org.jooq.Key<?> key, String tableName, String aliasVariableName) Returns the select code for the columns of a key.- Parameters:
key- The keyaliasVariableName- The variable name for the table alias- Returns:
- Select code for the columns in the key
-
getSelectKeyColumnRow
Returns codeblock for selecting key columns for the resolver key- Parameters:
context- The fetching context- Returns:
- Select code for the columns in the resolver key
-
getSelectKeyColumn
-
getSelectKeyColumn
-
createNodeIdBlock
-
createNodeIdBlockForRecord
public static CodeBlock createNodeIdBlockForRecord(RecordObjectSpecification<?> obj, String recordVariableName) -
hasIdBlock
public static CodeBlock hasIdBlock(CodeBlock id, RecordObjectSpecification<?> obj, String targetAlias) -
hasIdsBlock
-
hasIdOrIdsBlock
public static CodeBlock hasIdOrIdsBlock(CodeBlock idOrRecordParamName, RecordObjectSpecification<?> obj, String targetAlias, CodeBlock mappedFkFields, boolean isMultiple) -
nodeIdColumnsBlock
-
referenceNodeIdColumnsBlock
public static CodeBlock referenceNodeIdColumnsBlock(RecordObjectSpecification<?> container, RecordObjectSpecification<?> target, org.jooq.ForeignKey<?, ?> fk) -
referenceNodeIdColumnsBlock
public static CodeBlock referenceNodeIdColumnsBlock(RecordObjectSpecification<?> container, RecordObjectSpecification<?> target, org.jooq.ForeignKey<?, ?> fk, CodeBlock tableReference) -
nodeIdColumnsWithAliasBlock
public static CodeBlock nodeIdColumnsWithAliasBlock(String targetAlias, RecordObjectSpecification<?> obj) -
getPrimaryKeyFieldsWithTableAliasBlock
-