fun applyDirectivesJava()

in graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/shared/DirectivesUtils.kt [65:117]


fun applyDirectivesJava(
    directives: List<Directive>,
    config: CodeGenConfig,
): Pair<MutableMap<String, MutableList<JavaAnnotationSpec>>, String?> {
    var commentFormat: String? = null
    return Pair(
        directives.fold(mutableMapOf()) { annotations, directive ->
            val argumentMap = createArgumentMap(directive)
            val siteTarget =
                if (argumentMap.containsKey(
                        ParserConstants.SITE_TARGET,
                    )
                ) {
                    (argumentMap[ParserConstants.SITE_TARGET] as StringValue).value.uppercase()
                } else {
                    SiteTarget.DEFAULT.name
                }
            if (directive.name == ParserConstants.CUSTOM_ANNOTATION && config.generateCustomAnnotations) {
                annotations[siteTarget] =
                    if (annotations.containsKey(siteTarget)) {
                        var annotationList: MutableList<JavaAnnotationSpec> = annotations[siteTarget]!!
                        annotationList.add(
                            com.netflix.graphql.dgs.codegen.generators.java.customAnnotation(
                                argumentMap,
                                config,
                            ),
                        )
                        annotationList
                    } else {
                        mutableListOf(
                            com.netflix.graphql.dgs.codegen.generators.java
                                .customAnnotation(argumentMap, config),
                        )
                    }
            }
            if (directive.name == ParserConstants.DEPRECATED && config.addDeprecatedAnnotation) {
                annotations[siteTarget] = mutableListOf(JavaAnnotationSpec.builder(java.lang.Deprecated::class.java).build())
                if (argumentMap.containsKey(ParserConstants.REASON)) {
                    val reason: String = (argumentMap[ParserConstants.REASON] as StringValue).value
                    val replace = reason.substringAfter(ParserConstants.REPLACE_WITH_STR, "")
                    commentFormat = reason.substringBefore(ParserConstants.REPLACE_WITH_STR)
                    if (replace.isNotEmpty()) {
                        commentFormat = "@deprecated ${reason.substringBefore(ParserConstants.REPLACE_WITH_STR)}. Replaced by $replace"
                    }
                } else {
                    commentFormat = ParserConstants.DEPRECATED_IN_THE_GRAPHQL_SCHEMA
                }
            }
            annotations
        },
        commentFormat,
    )
}