mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
check and warn about dead links
This commit is contained in:
parent
e08a105d27
commit
c87d0446d3
@ -108,12 +108,17 @@ tasks.create<SourceTask>("tectonicDocs") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val linksAll = HashMap<String, Set<String>>()
|
||||||
|
|
||||||
sources.forEach { (name, unit) ->
|
sources.forEach { (name, unit) ->
|
||||||
val doc = StringBuilder()
|
val doc = StringBuilder()
|
||||||
doc.append("# ${generify(name, refactor)}\n")
|
doc.append("# ${generify(name, refactor)}\n")
|
||||||
|
|
||||||
var applicable = false
|
var applicable = false
|
||||||
|
|
||||||
|
val links = HashSet<String>()
|
||||||
|
|
||||||
unit.getClassByName(name).ifPresent { declaration ->
|
unit.getClassByName(name).ifPresent { declaration ->
|
||||||
applicable = scanForParent(sources, declaration, "ConfigTemplate", "ValidatedConfigTemplate", "ObjectTemplate")
|
applicable = scanForParent(sources, declaration, "ConfigTemplate", "ValidatedConfigTemplate", "ObjectTemplate")
|
||||||
if(applicable) println("Validated $name")
|
if(applicable) println("Validated $name")
|
||||||
@ -122,13 +127,13 @@ tasks.create<SourceTask>("tectonicDocs") {
|
|||||||
}
|
}
|
||||||
declaration.extendedTypes.forEach {
|
declaration.extendedTypes.forEach {
|
||||||
if (!it.name.asString().equals("AbstractableTemplate")) {
|
if (!it.name.asString().equals("AbstractableTemplate")) {
|
||||||
doc.append("Inherits from ${parseTypeLink(it, refactor, false)} \n \n")
|
doc.append("Inherits from ${parseTypeLink(it, refactor, links, false)} \n \n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (children.containsKey(name)) {
|
if (children.containsKey(name)) {
|
||||||
doc.append("Children:\n")
|
doc.append("Children:\n")
|
||||||
children[name]!!.forEach {
|
children[name]!!.forEach {
|
||||||
doc.append("* ${parseTypeLink(it.name, refactor)}\n")
|
doc.append("* ${parseTypeLink(it.name, refactor, links)}\n")
|
||||||
}
|
}
|
||||||
doc.append(" \n\n")
|
doc.append(" \n\n")
|
||||||
}
|
}
|
||||||
@ -143,7 +148,7 @@ tasks.create<SourceTask>("tectonicDocs") {
|
|||||||
doc.append("* Default value: ${fieldDeclaration.variables[0]} \n")
|
doc.append("* Default value: ${fieldDeclaration.variables[0]} \n")
|
||||||
}
|
}
|
||||||
val type = fieldDeclaration.commonType
|
val type = fieldDeclaration.commonType
|
||||||
doc.append("* Type: ${parseTypeLink(type, refactor)} \n")
|
doc.append("* Type: ${parseTypeLink(type, refactor, links)} \n")
|
||||||
doc.append("\n")
|
doc.append("\n")
|
||||||
|
|
||||||
fieldDeclaration.javadoc.ifPresent {
|
fieldDeclaration.javadoc.ifPresent {
|
||||||
@ -155,22 +160,33 @@ tasks.create<SourceTask>("tectonicDocs") {
|
|||||||
val s = doc.toString()
|
val s = doc.toString()
|
||||||
if (s.isNotEmpty() && applicable) {
|
if (s.isNotEmpty() && applicable) {
|
||||||
docs[generify(name, refactor)] = s
|
docs[generify(name, refactor)] = s
|
||||||
|
linksAll[name] = links
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("Done. Generated ${docs.size} files")
|
println("Done. Generated ${docs.size} files")
|
||||||
|
|
||||||
val docsDir = File(buildDir, "tectonic")
|
val docsDir = File(buildDir, "tectonic")
|
||||||
docsDir.mkdirs()
|
docsDir.mkdirs()
|
||||||
|
val files = HashSet<String>()
|
||||||
|
|
||||||
docs.forEach {
|
docs.forEach {
|
||||||
val save = File(docsDir, "${it.key}.md")
|
val save = File(docsDir, "${it.key}.md")
|
||||||
|
files.add(it.key)
|
||||||
if (save.exists()) save.delete()
|
if (save.exists()) save.delete()
|
||||||
save.createNewFile()
|
save.createNewFile()
|
||||||
save.writeText(it.value)
|
save.writeText(it.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets["tectonic"].resources.forEach {
|
sourceSets["tectonic"].resources.forEach {
|
||||||
|
files.add(it.name.substringBefore('.'))
|
||||||
it.copyTo(File(docsDir, it.name), true)
|
it.copyTo(File(docsDir, it.name), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linksAll.forEach { (file, links) ->
|
||||||
|
links.forEach {
|
||||||
|
if(!files.contains(it)) println("WARNING: Dead link to \"$it\" in file \"$file\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scanForParent(map: HashMap<String, CompilationUnit>, current: ClassOrInterfaceDeclaration, vararg parent: String): Boolean {
|
fun scanForParent(map: HashMap<String, CompilationUnit>, current: ClassOrInterfaceDeclaration, vararg parent: String): Boolean {
|
||||||
@ -189,7 +205,7 @@ fun scanForParent(map: HashMap<String, CompilationUnit>, current: ClassOrInterfa
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseTypeLink(type: Node, refactor: Map<String, String>, generic: Boolean = true): String {
|
fun parseTypeLink(type: Node, refactor: Map<String, String>, links: MutableSet<String>, generic: Boolean = true): String {
|
||||||
val st = parseType(type, refactor)
|
val st = parseType(type, refactor)
|
||||||
|
|
||||||
if (type is Type && type.childNodes.size > 1 && generic) {
|
if (type is Type && type.childNodes.size > 1 && generic) {
|
||||||
@ -197,9 +213,10 @@ fun parseTypeLink(type: Node, refactor: Map<String, String>, generic: Boolean =
|
|||||||
|
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
builder.append("[$outer](./$outer)\\<")
|
builder.append("[$outer](./$outer)\\<")
|
||||||
|
links.add(outer)
|
||||||
|
|
||||||
for (i in 1 until type.childNodes.size) {
|
for (i in 1 until type.childNodes.size) {
|
||||||
builder.append(parseTypeLink(type.childNodes[i], refactor))
|
builder.append(parseTypeLink(type.childNodes[i], refactor, links, generic))
|
||||||
if (i != type.childNodes.size - 1) builder.append(", ")
|
if (i != type.childNodes.size - 1) builder.append(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +224,7 @@ fun parseTypeLink(type: Node, refactor: Map<String, String>, generic: Boolean =
|
|||||||
|
|
||||||
return builder.toString()
|
return builder.toString()
|
||||||
}
|
}
|
||||||
|
links.add(st)
|
||||||
return "[$st](./$st)"
|
return "[$st](./$st)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user