Skip to content

Commit

Permalink
don't have multiple of the same docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Oct 24, 2024
1 parent b287e2f commit 415253a
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ object MCPv1FieldReader : FormatReader {
nameMap[dstNs] = fData.first to ns.second
val visitor = default.visitField(delegate, nameMap)
if (fData.second != null) {
visitor?.visitJavadoc(fData.second!!, dstNs, emptySet())?.visitEnd()
visitor?.visitJavadoc(fData.second!!, setOf(dstNs))?.visitEnd()
}
return visitor
}

override fun visitFieldJavadoc(
delegate: FieldVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
return default.visitFieldJavadoc(delegate, value, baseNs, namespaces)
return default.visitFieldJavadoc(delegate, value, namespaces)
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,17 @@ object MCPv1MethodReader : FormatReader {
nameMap[dstNs] = mData.first to ns.second
val visitor = default.visitMethod(delegate, nameMap)
if (mData.second != null) {
visitor?.visitJavadoc(mData.second!!, dstNs, emptySet())?.visitEnd()
visitor?.visitJavadoc(mData.second!!, setOf(dstNs))?.visitEnd()
}
return visitor
}

override fun visitMethodJavadoc(
delegate: MethodVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
return default.visitMethodJavadoc(delegate, value, baseNs, namespaces)
return default.visitMethodJavadoc(delegate, value, namespaces)
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,17 @@ object MCPv6FieldReader : FormatReader {
nameMap[dstNs] = fdata.first to ns.second
val visitor = default.visitField(delegate, nameMap)
if (fdata.second != null) {
visitor?.visitJavadoc(fdata.second!!, dstNs, emptySet())?.visitEnd()
visitor?.visitJavadoc(fdata.second!!, setOf(dstNs))?.visitEnd()
}
return visitor
}

override fun visitFieldJavadoc(
delegate: FieldVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
return default.visitFieldJavadoc(delegate, value, baseNs, namespaces)
return default.visitFieldJavadoc(delegate, value, namespaces)
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ object MCPv6FieldWriter : FormatWriter {
override fun visitFieldJavadoc(
delegate: FieldVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
if (!writeComments) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ object MCPv6MethodReader : FormatReader {
nameMap[dstNs] = mData.first to ns.second
val visitor = default.visitMethod(delegate, nameMap)
if (mData.second != null) {
visitor?.visitJavadoc(mData.second!!, dstNs, emptySet())?.visitEnd()
visitor?.visitJavadoc(mData.second!!, setOf(dstNs))?.visitEnd()
}
return visitor
}

override fun visitMethodJavadoc(
delegate: MethodVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
return default.visitMethodJavadoc(delegate, value, baseNs, namespaces)
return default.visitMethodJavadoc(delegate, value, namespaces)
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ object MCPv6MethodWriter : FormatWriter {
override fun visitMethodJavadoc(
delegate: MethodVisitor,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
if (!writeComments) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object ParchmentReader : FormatReader {
}
if (content != null) {
visitPackage(mapOf(srcNs to PackageName.read("$pkgName/")))?.use {
visitJavadoc(content, srcNs, emptySet())?.visitEnd()
visitJavadoc(content, setOf(srcNs))?.visitEnd()
}
}
}
Expand All @@ -72,7 +72,7 @@ object ParchmentReader : FormatReader {
}
visitMethod(mapOf(srcNs to (methodName to MethodDescriptor.read(methodDesc))))?.use {
if (content != null) {
visitJavadoc(content, srcNs, emptySet())?.visitEnd()
visitJavadoc(content, setOf(srcNs))?.visitEnd()
}

val params = methodObj["parameters"]?.jsonArray ?: emptyList()
Expand All @@ -88,7 +88,7 @@ object ParchmentReader : FormatReader {
}
visitParameter(null, paramLvOrd, mapOf(srcNs to paramName))?.use {
if (paramContent != null) {
visitJavadoc(paramContent, srcNs, emptySet())?.visitEnd()
visitJavadoc(paramContent, setOf(srcNs))?.visitEnd()
}
}
}
Expand All @@ -109,7 +109,7 @@ object ParchmentReader : FormatReader {
}
visitField(mapOf(srcNs to (fieldName to FieldDescriptor.read(fieldDesc))))?.use {
if (content != null) {
visitJavadoc(content, srcNs, emptySet())?.visitEnd()
visitJavadoc(content, setOf(srcNs))?.visitEnd()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object TinyV2Reader : FormatReader {
// comment
val comment = input.takeLine().removePrefix("\t").translateEscapes()
last as JavadocParentNode?
last?.visitJavadoc(comment, namespaces.first(), namespaces.drop(1).toSet())
last?.visitJavadoc(comment, namespaces.toSet())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import xyz.wagyourtail.unimined.mapping.visitor.delegate.Delegator
import xyz.wagyourtail.unimined.mapping.visitor.delegate.NullDelegator
import xyz.wagyourtail.unimined.mapping.visitor.delegate.delegator

@Suppress("UNUSED_PARAMETER")
object TinyV2Writer : FormatWriter {

private fun String.escape(): String {
Expand Down Expand Up @@ -115,7 +114,6 @@ object TinyV2Writer : FormatWriter {
override fun visitJavadoc(
delegate: JavadocParentNode<*>,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
if (indent.isEmpty()) throw IllegalStateException("Top level javadoc?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ object UMFReader : FormatReader {
}
EntryType.JAVADOC -> {
val comment = input.takeNextFixed()!!
val names = input.takeRemainingFixedOnLine().filterNotNull().map { Namespace(it) }.iterator()
val names = input.takeRemainingFixedOnLine().filterNotNull().map { Namespace(it) }
last as MemberVisitor<*>?
last?.visitJavadoc(comment, names.next(), names.asSequence().toSet())
last?.visitJavadoc(comment, names.toSet())
}
EntryType.ANNOTATION -> {
val type = input.takeNextFixed()!!.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,11 @@ object UMFWriter : FormatWriter {
override fun visitJavadoc(
delegate: JavadocParentNode<*>,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): JavadocVisitor? {
into(indent)
into("${UMFReader.EntryType.JAVADOC.key}\t")
into(value.maybeEscape())
into("\t")
into(baseNs.name.maybeEscape())
for (ns in this.namespaces) {
if (ns in namespaces) {
into("\t")
Expand All @@ -379,7 +376,7 @@ object UMFWriter : FormatWriter {
}
into("\n")
indent += "\t"
return super.visitJavadoc(delegate, value, baseNs, namespaces)
return super.visitJavadoc(delegate, value, namespaces)
}

override fun visitSignature(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import xyz.wagyourtail.unimined.mapping.visitor.EmptyJavadocParentVisitor
import xyz.wagyourtail.unimined.mapping.visitor.JavadocParentNode
import xyz.wagyourtail.unimined.mapping.visitor.JavadocVisitor

class JavadocNode<T: JavadocParentNode<T>>(parent: BaseNode<T, *>, val value: String, val baseNs: Namespace) : BaseNode<JavadocVisitor, T>(parent), JavadocVisitor {
class JavadocNode<T: JavadocParentNode<T>>(parent: BaseNode<T, *>, val value: String) : BaseNode<JavadocVisitor, T>(parent), JavadocVisitor {
val _namespaces: MutableSet<Namespace> = mutableSetOf()
val namespaces: Set<Namespace> get() = _namespaces

Expand All @@ -16,20 +16,13 @@ class JavadocNode<T: JavadocParentNode<T>>(parent: BaseNode<T, *>, val value: St
}

override fun acceptOuter(visitor: T, nsFilter: Collection<Namespace>): JavadocVisitor? {
if (baseNs !in nsFilter) {
val ns = nsFilter.filter { it in namespaces }.toSet()
if (ns.isEmpty()) return null
val first = ns.first()
return visitor.visitJavadoc(value, first, ns - first)
} else {
return visitor.visitJavadoc(value, baseNs, nsFilter.filter { it in namespaces }.toSet() - baseNs)
}
return visitor.visitJavadoc(value, nsFilter.filter { it in namespaces }.toSet())
}

override fun toString() = buildString {
val delegator = UMFWriter.UMFWriterDelegator(::append, true)
delegator.namespaces = root.namespaces
delegator.visitJavadoc(EmptyJavadocParentVisitor(), value, baseNs, namespaces)
delegator.visitJavadoc(EmptyJavadocParentVisitor(), value, namespaces)
// acceptInner(DelegateCommentVisitor(EmptyCommentVisitor(), delegator), root.namespaces)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import xyz.wagyourtail.unimined.mapping.tree.node.JavadocNode
import xyz.wagyourtail.unimined.mapping.visitor.*

abstract class MemberNode<T: MemberVisitor<T>, U: BaseVisitor<U>>(parent: BaseNode<U, *>) : AccessParentNode<T, U>(parent), MemberVisitor<T> {
private var _comments: MutableSet<JavadocNode<T>> = mutableSetOf()
private var _comments: MutableMap<String, JavadocNode<T>> = mutableMapOf()
private val _annotations: MutableSet<AnnotationNode<T>> = mutableSetOf()

val comments: Set<JavadocNode<T>> get() = _comments
val comments: Set<JavadocNode<T>> get() = _comments.values.toSet()
val annotations: Set<AnnotationNode<T>> get() = _annotations

override fun visitJavadoc(value: String, baseNs: Namespace, namespaces: Set<Namespace>): JavadocVisitor? {
val node = JavadocNode(this, value, baseNs)
override fun visitJavadoc(value: String, namespaces: Set<Namespace>): JavadocVisitor? {
val node = _comments.getOrPut(value) { JavadocNode(this, value) }
node.addNamespaces(namespaces)
_comments.add(node)
root.mergeNs(namespaces)
return node
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import xyz.wagyourtail.unimined.mapping.visitor.*
class PackageNode(parent: AbstractMappingTree) : BaseNode<PackageVisitor, MappingVisitor>(parent), PackageVisitor {
private val _names: MutableMap<Namespace, PackageName> = mutableMapOf()
private val _annotations: MutableSet<AnnotationNode<PackageVisitor>> = mutableSetOf()
private var _comments: MutableSet<JavadocNode<PackageVisitor>> = mutableSetOf()
private var _comments: MutableMap<String, JavadocNode<PackageVisitor>> = mutableMapOf()

val names: Map<Namespace, PackageName> get() = _names
val annotations: Set<AnnotationNode<PackageVisitor>> get() = _annotations
val comments: Set<JavadocNode<PackageVisitor>> get() = _comments
val comments: Set<JavadocNode<PackageVisitor>> get() = _comments.values.toSet()

fun getName(namespace: Namespace) = names[namespace]

Expand Down Expand Up @@ -52,11 +52,10 @@ class PackageNode(parent: AbstractMappingTree) : BaseNode<PackageVisitor, Mappin
return node
}

override fun visitJavadoc(value: String, baseNs: Namespace, namespaces: Set<Namespace>): JavadocVisitor {
val node = JavadocNode(this, value, baseNs)
override fun visitJavadoc(value: String, namespaces: Set<Namespace>): JavadocVisitor {
val node = _comments.getOrPut(value) { JavadocNode(this, value) }
node.addNamespaces(namespaces)
_comments.add(node)
root.mergeNs(namespaces + baseNs)
root.mergeNs(namespaces)
return node
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ open class EmptySignatureParentVisitor<T: SignatureParentVisitor<T>> : EmptyBas

open class EmptyJavadocParentVisitor<T: JavadocParentNode<T>> : EmptyBaseVisitor<T>(), JavadocParentNode<T> {

override fun visitJavadoc(value: String, baseNs: Namespace, namespaces: Set<Namespace>): JavadocVisitor? {
override fun visitJavadoc(value: String, namespaces: Set<Namespace>): JavadocVisitor? {
return EmptyJavadocVisitor()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface SignatureParentVisitor<T: SignatureParentVisitor<T>> : BaseVisitor<T>

interface JavadocParentNode<T: JavadocParentNode<T>> : BaseVisitor<T> {

fun visitJavadoc(value: String, baseNs: Namespace, namespaces: Set<Namespace>): JavadocVisitor?
fun visitJavadoc(value: String, namespaces: Set<Namespace>): JavadocVisitor?

}

Expand Down
Loading

0 comments on commit 415253a

Please sign in to comment.