mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-09 14:56:47 +07:00
Turned 'getDeprecationAnnotation' and 'getReplacementText' to functions for reusability
This commit is contained in:
parent
ff2fc02961
commit
fe14918545
@ -375,25 +375,10 @@ class Ruleset {
|
||||
// The tests are RulesetInvariant in nature, but RulesetSpecific is called for _all_ objects, invariant is not.
|
||||
continue
|
||||
|
||||
val deprecationAnnotation = unique.type.declaringClass.getField(unique.type.name)
|
||||
.getAnnotation(Deprecated::class.java)
|
||||
|
||||
val deprecationAnnotation = unique.getDeprecationAnnotation()
|
||||
if (deprecationAnnotation != null) {
|
||||
var replacementUniqueText = deprecationAnnotation.replaceWith.expression
|
||||
val deprecatedUniquePlaceholders = unique.type.text.getPlaceholderParameters()
|
||||
|
||||
// Here, for once, we DO want the conditional placeholder parameters together with the regular ones,
|
||||
// so we cheat the conditional detector by removing the '<'
|
||||
for (parameter in replacementUniqueText.replace('<',' ').getPlaceholderParameters()) {
|
||||
val parameterNumberInDeprecatedUnique =
|
||||
deprecatedUniquePlaceholders.indexOf(parameter.removePrefix("+").removePrefix("-"))
|
||||
if (parameterNumberInDeprecatedUnique == -1) continue
|
||||
var replacementText = unique.params[parameterNumberInDeprecatedUnique]
|
||||
if (parameter.startsWith('+')) replacementText = "+$replacementText"
|
||||
else if(parameter.startsWith('-')) replacementText = "-$replacementText"
|
||||
replacementUniqueText =
|
||||
replacementUniqueText.replace("[$parameter]", "[$replacementText]")
|
||||
}
|
||||
|
||||
val replacementUniqueText = unique.getReplacementText()
|
||||
val deprecationText =
|
||||
"$name's unique \"${unique.text}\" is deprecated ${deprecationAnnotation.message}," +
|
||||
if (deprecationAnnotation.replaceWith.expression != "") " replace with \"${replacementUniqueText}\"" else ""
|
||||
|
@ -46,6 +46,28 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
|
||||
return true
|
||||
}
|
||||
|
||||
fun getDeprecationAnnotation(): Deprecated? = type?.getDeprecationAnnotation()
|
||||
|
||||
fun getReplacementText(): String {
|
||||
val deprecationAnnotation = getDeprecationAnnotation() ?: return ""
|
||||
var replacementUniqueText = deprecationAnnotation.replaceWith.expression
|
||||
val deprecatedUniquePlaceholders = type!!.text.getPlaceholderParameters()
|
||||
|
||||
// Here, for once, we DO want the conditional placeholder parameters together with the regular ones,
|
||||
// so we cheat the conditional detector by removing the '<'
|
||||
for (parameter in replacementUniqueText.replace('<',' ').getPlaceholderParameters()) {
|
||||
val parameterNumberInDeprecatedUnique =
|
||||
deprecatedUniquePlaceholders.indexOf(parameter.removePrefix("+").removePrefix("-"))
|
||||
if (parameterNumberInDeprecatedUnique == -1) continue
|
||||
var replacementText = params[parameterNumberInDeprecatedUnique]
|
||||
if (parameter.startsWith('+')) replacementText = "+$replacementText"
|
||||
else if(parameter.startsWith('-')) replacementText = "-$replacementText"
|
||||
replacementUniqueText =
|
||||
replacementUniqueText.replace("[$parameter]", "[$replacementText]")
|
||||
}
|
||||
return replacementUniqueText
|
||||
}
|
||||
|
||||
private fun conditionalApplies(
|
||||
condition: Unique,
|
||||
state: StateForConditionals
|
||||
|
@ -777,5 +777,8 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
}
|
||||
return errorList
|
||||
}
|
||||
|
||||
fun getDeprecationAnnotation(): Deprecated? = declaringClass.getField(name)
|
||||
.getAnnotation(Deprecated::class.java)
|
||||
}
|
||||
|
||||
|
@ -95,8 +95,7 @@ object TranslationFileWriter {
|
||||
|
||||
linesToTranslate.add("\n\n#################### Lines from Unique Types #######################\n")
|
||||
for (unique in UniqueType.values()) {
|
||||
val deprecationAnnotation = unique.declaringClass.getField(unique.name)
|
||||
.getAnnotation(Deprecated::class.java)
|
||||
val deprecationAnnotation = unique.getDeprecationAnnotation()
|
||||
if (deprecationAnnotation != null) continue
|
||||
if (unique.flags.contains(UniqueFlag.HiddenToUsers)) continue
|
||||
|
||||
|
@ -64,8 +64,7 @@ class UniqueDocsWriter {
|
||||
lines += "## " + targetType.key.name + " uniques"
|
||||
for (uniqueType in targetType.value) {
|
||||
|
||||
val deprecationAnnotation = uniqueType.declaringClass.getField(uniqueType.name)
|
||||
.getAnnotation(Deprecated::class.java)
|
||||
val deprecationAnnotation = uniqueType.getDeprecationAnnotation()
|
||||
if (deprecationAnnotation != null) {
|
||||
deprecatedUniques += uniqueType
|
||||
continue
|
||||
@ -83,8 +82,7 @@ class UniqueDocsWriter {
|
||||
lines += "## Deprecated uniques"
|
||||
for (deprecatedUnique in deprecatedUniques) {
|
||||
val deprecationAnnotation =
|
||||
deprecatedUnique.declaringClass.getField(deprecatedUnique.name)
|
||||
.getAnnotation(Deprecated::class.java)
|
||||
deprecatedUnique.getDeprecationAnnotation()!!
|
||||
|
||||
val deprecationText = "Deprecated ${deprecationAnnotation.message}," +
|
||||
if (deprecationAnnotation.replaceWith.expression != "") " replace with \"${deprecationAnnotation.replaceWith.expression}\"" else ""
|
||||
|
Loading…
Reference in New Issue
Block a user