Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
feat: add ignore config
Browse files Browse the repository at this point in the history
  • Loading branch information
RimuruChan committed Dec 31, 2023
1 parent 0ea85b3 commit 4dced22
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ regex = [
"^.*VariantBuilder", # for mc
]

[ignore]

regex = []

[sort]
parent = [
# { parent = "Actor", dst = "Actor" },
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/liteldev/headeroutput/HeaderOutput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ object HeaderOutput {
val notIdentifiedTypes = mutableSetOf<String>()
logger.info { "Loading types..." }
typeDataMap
.filterNot { (k, _) -> GeneratorConfig.isExcludedFromGeneration(k) }
.filterNot { (k, _) -> GeneratorConfig.isExcluded(k) }
.filterNot { (k, _) -> GeneratorConfig.isIgnored(k) }
.forEach { (typeName, type) ->
TypeManager.addType(
typeName,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/liteldev/headeroutput/TypeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ object TypeManager {
private fun createDummyClass(name: String, type: TypeKind? = null): BaseType? {
require(!hasType(name)) { "type $name already exists" }

if (GeneratorConfig.isExcludedFromGeneration(name)) {
if (GeneratorConfig.isExcluded(name)) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object GeneratorConfig {
lateinit var replacementRegex: List<Pair<Regex, String>>

private lateinit var excludeRegexList: List<Regex>
private lateinit var ignoreRegexList: List<Regex>
private lateinit var generatorConfigData: OutputConfig


Expand All @@ -45,13 +46,20 @@ object GeneratorConfig {
enableRelativePath = generatorConfigData.config.enableRelativePath
rootPath = generatorConfigData.config.rootPath
excludeRegexList = generatorConfigData.exclusion.regex.map { it.toRegex() }
ignoreRegexList = generatorConfigData.ignore.regex.map { it.toRegex() }
replacementRegex = generatorConfigData.replacement.regex.map { it.regex.toRegex() to it.to }
}

fun isExcludedFromGeneration(name: String): Boolean {
// Exclude means exclude from the origin data, and do not generate the dummy type
fun isExcluded(name: String): Boolean {
return excludeRegexList.any { name.matches(it) }
}

// Ignore means ignore from the origin data, and generate the dummy type
fun isIgnored(name: String): Boolean {
return ignoreRegexList.any { name.matches(it) }
}

fun getSortRules() = generatorConfigData.sort

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class OutputConfig(
val config: Config,
val exclusion: Exclusion,
val sort: Sort,
val ignore: Ignore,
val replacement: Replacement
) {
@Serializable
Expand Down Expand Up @@ -36,6 +37,11 @@ data class OutputConfig(
val regex: List<String>
)

@Serializable
data class Ignore(
val regex: List<String>
)

@Serializable
data class Replacement(
val regex: List<Regex>
Expand Down

0 comments on commit 4dced22

Please sign in to comment.