aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternGroup.kt
blob: 860cf379ebd674443f226d7476b5986a9aabe3c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package at.hannibal2.skyhanni.utils.repopatterns

import org.intellij.lang.annotations.Language

/**
 * A utility class for allowing easier definitions of [RepoPattern]s with a common prefix.
 */
open class RepoPatternGroup internal constructor(
    val prefix: String,
    protected var parentGiver: RepoPatternKeyOwner? = null,
) {

    init {
        RepoPatternManager.verifyKeyShape(prefix)
    }

    /**
     * Shortcut to [RepoPattern.pattern] prefixed with [prefix].
     */
    fun pattern(key: String, @Language("RegExp") fallback: String): RepoPattern {
        return RepoPatternManager.of("$prefix.$key", fallback, parentGiver)
    }

    /**
     * Shortcut to [RepoPattern.list] prefixed with [prefix].
     */
    fun list(key: String, @Language("RegExp") vararg fallbacks: String): RepoPatternList {
        return RepoPatternManager.ofList("$prefix.$key", fallbacks, parentGiver)
    }

    /**
     * Shortcut to [RepoPattern.group] prefixed with [prefix].
     */
    fun group(subgroup: String): RepoPatternGroup {
        return RepoPatternGroup("$prefix.$subgroup", parentGiver)
    }

    /**
     * Shortcut to [RepoPattern.exclusiveGroup] prefixed with [prefix].
     */
    fun exclusiveGroup(subgroup: String): RepoPatternExclusiveGroupInfo {
        return RepoPatternExclusiveGroupInfo("$prefix.$subgroup", parentGiver)
    }
}