mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
properly handle generic types
This commit is contained in:
parent
04b748979e
commit
2f19a95437
@ -12,6 +12,7 @@ import org.gradle.api.plugins.JavaPluginExtension
|
|||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.objectweb.asm.ClassReader
|
import org.objectweb.asm.ClassReader
|
||||||
import org.objectweb.asm.tree.ClassNode
|
import org.objectweb.asm.tree.ClassNode
|
||||||
|
import org.objectweb.asm.tree.FieldNode
|
||||||
|
|
||||||
|
|
||||||
abstract class GenerateDocsTask : DefaultTask() {
|
abstract class GenerateDocsTask : DefaultTask() {
|
||||||
@ -68,7 +69,7 @@ abstract class GenerateDocsTask : DefaultTask() {
|
|||||||
keyName.append("final ")
|
keyName.append("final ")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyName.append(descriptorToHumanReadable(field.desc).substringAfterLast("."))
|
keyName.append(getType(field))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
|
|
||||||
annotations.stream().filter {
|
annotations.stream().filter {
|
||||||
@ -93,6 +94,24 @@ abstract class GenerateDocsTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getType(node: FieldNode): String {
|
||||||
|
if(node.signature != null) {
|
||||||
|
return generic(node.signature)
|
||||||
|
}
|
||||||
|
return descriptorToHumanReadable(node.desc).substringAfterLast('.')
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generic(type: String): String {
|
||||||
|
val clean = descriptorToHumanReadable(type)
|
||||||
|
|
||||||
|
if(clean.contains('<')) {
|
||||||
|
val typeIndex = clean.indexOf('<')
|
||||||
|
return clean.substring(0, typeIndex+1).substringAfterLast('.') + generic(clean.substring(typeIndex+1)) + "\\>"
|
||||||
|
}
|
||||||
|
|
||||||
|
return clean.substringAfterLast('.')
|
||||||
|
}
|
||||||
|
|
||||||
private fun createClassNode(input: InputStream): ClassNode {
|
private fun createClassNode(input: InputStream): ClassNode {
|
||||||
val reader = ClassReader(input)
|
val reader = ClassReader(input)
|
||||||
val node = ClassNode()
|
val node = ClassNode()
|
||||||
@ -120,7 +139,7 @@ abstract class GenerateDocsTask : DefaultTask() {
|
|||||||
"J" -> "long"
|
"J" -> "long"
|
||||||
"S" -> "short"
|
"S" -> "short"
|
||||||
"Z" -> "boolean"
|
"Z" -> "boolean"
|
||||||
else -> throw IllegalArgumentException("Invalid descriptor: $descriptor")
|
else -> descriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user