<commit_before>/*
 * Copyright (C) 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.compat.lang.annotation

import com.intellij.lang.ASTNode
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.lang.annotation.ProblemGroup
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement

@Suppress("unused")
class AnnotationBuilder(
    private val holder: AnnotationHolder,
    private val severity: HighlightSeverity,
    private val message: String?
) {
    private var textRange: TextRange? = null
    private var isAfterEndOfLine: Boolean? = null
    private var isFileLevelAnnotation: Boolean? = null
    private var gutterIconRenderer: GutterIconRenderer? = null
    private var problemGroup: ProblemGroup? = null

    fun range(range: TextRange): AnnotationBuilder {
        textRange = range
        return this
    }

    fun range(element: ASTNode): AnnotationBuilder = range(element.textRange)

    fun range(element: PsiElement): AnnotationBuilder = range(element.textRange)

    fun afterEndOfLine(): AnnotationBuilder {
        isAfterEndOfLine = true
        return this
    }

    fun fileLevel(): AnnotationBuilder {
        isFileLevelAnnotation = true
        return this
    }

    fun gutterIconRenderer(gutterIconRenderer: GutterIconRenderer): AnnotationBuilder {
        this.gutterIconRenderer = gutterIconRenderer
        return this
    }

    fun problemGroup(problemGroup: ProblemGroup): AnnotationBuilder {
        this.problemGroup = problemGroup
        return this
    }

    fun create() {
        val textRange: TextRange = textRange ?: holder.currentElement!!.textRange
        val annotation = holder.holder.createAnnotation(severity, textRange, message, null)
        isAfterEndOfLine?.let { annotation.isAfterEndOfLine = it }
        isFileLevelAnnotation?.let { annotation.isFileLevelAnnotation = it }
        gutterIconRenderer?.let { annotation.gutterIconRenderer = it }
        problemGroup?.let { annotation.problemGroup = it }
    }
}<commit_msg>Create an AnnotationBuilder#enforcedTextAttributes compatibility API.<commit_after>/*
 * Copyright (C) 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.compat.lang.annotation

import com.intellij.lang.ASTNode
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.lang.annotation.ProblemGroup
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement

@Suppress("unused")
class AnnotationBuilder(
    private val holder: AnnotationHolder,
    private val severity: HighlightSeverity,
    private val message: String?
) {
    private var textRange: TextRange? = null
    private var isAfterEndOfLine: Boolean? = null
    private var isFileLevelAnnotation: Boolean? = null
    private var gutterIconRenderer: GutterIconRenderer? = null
    private var problemGroup: ProblemGroup? = null
    private var enforcedTextAttributes: TextAttributes? = null

    fun range(range: TextRange): AnnotationBuilder {
        textRange = range
        return this
    }

    fun range(element: ASTNode): AnnotationBuilder = range(element.textRange)

    fun range(element: PsiElement): AnnotationBuilder = range(element.textRange)

    fun afterEndOfLine(): AnnotationBuilder {
        isAfterEndOfLine = true
        return this
    }

    fun fileLevel(): AnnotationBuilder {
        isFileLevelAnnotation = true
        return this
    }

    fun gutterIconRenderer(gutterIconRenderer: GutterIconRenderer): AnnotationBuilder {
        this.gutterIconRenderer = gutterIconRenderer
        return this
    }

    fun problemGroup(problemGroup: ProblemGroup): AnnotationBuilder {
        this.problemGroup = problemGroup
        return this
    }

    fun enforcedTextAttributes(enforcedAttributes: TextAttributes): AnnotationBuilder {
        enforcedTextAttributes = enforcedAttributes
        return this
    }

    fun create() {
        val textRange: TextRange = textRange ?: holder.currentElement!!.textRange
        val annotation = holder.holder.createAnnotation(severity, textRange, message, null)
        isAfterEndOfLine?.let { annotation.isAfterEndOfLine = it }
        isFileLevelAnnotation?.let { annotation.isFileLevelAnnotation = it }
        gutterIconRenderer?.let { annotation.gutterIconRenderer = it }
        problemGroup?.let { annotation.problemGroup = it }
        enforcedTextAttributes?.let { annotation.enforcedTextAttributes = it }
    }
}
{'fraction_non_alphanumeric': 0.07447183098591549, 'fraction_numerical': 0.0028169014084507044, 'mean_word_length': 3.738115095913261, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22305', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1473, 'n_words': 442}