Use sbt-paradox-apidoc plugin (#26660)

Instead of using custom code here. Checked with 'meld' that the result
is the same, except for problems that were already there (filed #26659).
This commit is contained in:
Arnout Engelen 2019-04-03 13:14:27 +02:00 committed by GitHub
parent 76479b8770
commit abbbfb5b54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 78 additions and 135 deletions

View file

@ -32,69 +32,10 @@ object ParadoxSupport {
{ context: Writer.Context =>
new SignatureDirective(context.location.tree.label, context.properties, msg => log.warn(msg))
},
{ _: Writer.Context => new UnidocDirective(allClasses) }
)}
}.value
)
class UnidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("unidoc") {
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
if (node.label.split('[')(0).contains('.')) {
val fqcn = node.label
if (allClasses.contains(fqcn)) {
val label = fqcn.split('.').last
syntheticNode("java", javaLabel(label), fqcn, node).accept(visitor)
syntheticNode("scala", label, fqcn, node).accept(visitor)
} else {
throw new java.lang.IllegalStateException(s"fqcn not found by @unidoc[$fqcn]")
}
}
else {
renderByClassName(node.label, node, visitor, printer)
}
}
def javaLabel(label: String): String =
label.replaceAll("\\[", "<").replaceAll("\\]", ">").replace('_', '?')
def syntheticNode(group: String, label: String, fqcn: String, node: DirectiveNode): DirectiveNode = {
val syntheticSource = new DirectiveNode.Source.Direct(fqcn)
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
new DirectiveNode(DirectiveNode.Format.Inline, group, null, null, attributes, null,
new DirectiveNode(DirectiveNode.Format.Inline, group + "doc", label, syntheticSource, node.attributes, fqcn,
new TextNode(label)
))
}
def renderByClassName(label: String, node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
val label = node.label.replaceAll("\\\\_", "_")
val labelWithoutGenericParameters = label.split("\\[")(0)
val labelWithJavaGenerics = javaLabel(label)
val matches = allClasses.filter(_.endsWith('.' + labelWithoutGenericParameters))
matches.size match {
case 0 =>
throw new java.lang.IllegalStateException(s"No matches found for $label")
case 1 if matches(0).contains("adsl") =>
throw new java.lang.IllegalStateException(s"Match for $label only found in one language: ${matches(0)}")
case 1 =>
syntheticNode("scala", label, matches(0), node).accept(visitor)
syntheticNode("java", labelWithJavaGenerics, matches(0), node).accept(visitor)
case 2 if matches.forall(_.contains("adsl")) =>
matches.foreach(m => {
if (!m.contains("javadsl"))
syntheticNode("scala", label, m, node).accept(visitor)
if (!m.contains("scaladsl"))
syntheticNode("java", labelWithJavaGenerics, m, node).accept(visitor)
})
case n =>
throw new java.lang.IllegalStateException(
s"$n matches found for @unidoc[$label], but not javadsl/scaladsl: ${matches.mkString(", ")}. " +
s"You may want to use the fully qualified class name as @unidoc[fqcn] instead of @unidoc[${label}]."
)
}
}
}
class SignatureDirective(page: Page, variables: Map[String, String], logWarn: String => Unit) extends LeafBlockDirective("signature") {
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit =
try {

View file

@ -16,6 +16,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.15")
addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.1")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
addSbtPlugin("com.lightbend.akka" % "sbt-paradox-akka" % "0.18")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox-apidoc" % "0.1+9-d846d815")
addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.13")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0") // for maintenance of copyright file header