mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 07:16:54 +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.
|
// The tests are RulesetInvariant in nature, but RulesetSpecific is called for _all_ objects, invariant is not.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val deprecationAnnotation = unique.type.declaringClass.getField(unique.type.name)
|
|
||||||
.getAnnotation(Deprecated::class.java)
|
val deprecationAnnotation = unique.getDeprecationAnnotation()
|
||||||
if (deprecationAnnotation != null) {
|
if (deprecationAnnotation != null) {
|
||||||
var replacementUniqueText = deprecationAnnotation.replaceWith.expression
|
val replacementUniqueText = unique.getReplacementText()
|
||||||
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 deprecationText =
|
val deprecationText =
|
||||||
"$name's unique \"${unique.text}\" is deprecated ${deprecationAnnotation.message}," +
|
"$name's unique \"${unique.text}\" is deprecated ${deprecationAnnotation.message}," +
|
||||||
if (deprecationAnnotation.replaceWith.expression != "") " replace with \"${replacementUniqueText}\"" else ""
|
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
|
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(
|
private fun conditionalApplies(
|
||||||
condition: Unique,
|
condition: Unique,
|
||||||
state: StateForConditionals
|
state: StateForConditionals
|
||||||
|
@ -777,5 +777,8 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
|||||||
}
|
}
|
||||||
return errorList
|
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")
|
linesToTranslate.add("\n\n#################### Lines from Unique Types #######################\n")
|
||||||
for (unique in UniqueType.values()) {
|
for (unique in UniqueType.values()) {
|
||||||
val deprecationAnnotation = unique.declaringClass.getField(unique.name)
|
val deprecationAnnotation = unique.getDeprecationAnnotation()
|
||||||
.getAnnotation(Deprecated::class.java)
|
|
||||||
if (deprecationAnnotation != null) continue
|
if (deprecationAnnotation != null) continue
|
||||||
if (unique.flags.contains(UniqueFlag.HiddenToUsers)) continue
|
if (unique.flags.contains(UniqueFlag.HiddenToUsers)) continue
|
||||||
|
|
||||||
|
@ -64,8 +64,7 @@ class UniqueDocsWriter {
|
|||||||
lines += "## " + targetType.key.name + " uniques"
|
lines += "## " + targetType.key.name + " uniques"
|
||||||
for (uniqueType in targetType.value) {
|
for (uniqueType in targetType.value) {
|
||||||
|
|
||||||
val deprecationAnnotation = uniqueType.declaringClass.getField(uniqueType.name)
|
val deprecationAnnotation = uniqueType.getDeprecationAnnotation()
|
||||||
.getAnnotation(Deprecated::class.java)
|
|
||||||
if (deprecationAnnotation != null) {
|
if (deprecationAnnotation != null) {
|
||||||
deprecatedUniques += uniqueType
|
deprecatedUniques += uniqueType
|
||||||
continue
|
continue
|
||||||
@ -83,8 +82,7 @@ class UniqueDocsWriter {
|
|||||||
lines += "## Deprecated uniques"
|
lines += "## Deprecated uniques"
|
||||||
for (deprecatedUnique in deprecatedUniques) {
|
for (deprecatedUnique in deprecatedUniques) {
|
||||||
val deprecationAnnotation =
|
val deprecationAnnotation =
|
||||||
deprecatedUnique.declaringClass.getField(deprecatedUnique.name)
|
deprecatedUnique.getDeprecationAnnotation()!!
|
||||||
.getAnnotation(Deprecated::class.java)
|
|
||||||
|
|
||||||
val deprecationText = "Deprecated ${deprecationAnnotation.message}," +
|
val deprecationText = "Deprecated ${deprecationAnnotation.message}," +
|
||||||
if (deprecationAnnotation.replaceWith.expression != "") " replace with \"${deprecationAnnotation.replaceWith.expression}\"" else ""
|
if (deprecationAnnotation.replaceWith.expression != "") " replace with \"${deprecationAnnotation.replaceWith.expression}\"" else ""
|
||||||
|
Loading…
Reference in New Issue
Block a user