summaryrefslogtreecommitdiff
path: root/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala')
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala90
1 files changed, 73 insertions, 17 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala
index b048d96405..530a20fc3a 100644
--- a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala
+++ b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala
@@ -16,7 +16,66 @@ trait ScaladocAnalyzer extends Analyzer {
val global : Global // generally, a ScaladocGlobal
import global._
- override def newTyper(context: Context): ScaladocTyper = new Typer(context) with ScaladocTyper
+ override def newTyper(context: Context): Typer = if (context.unit.isJava) {
+ new Typer(context) with ScaladocJavaTyper //super hack
+ } else {
+ new Typer(context) with ScaladocTyper
+ }
+
+ //super hack
+ trait ScaladocJavaTyper extends Typer {
+ private def unit = context.unit
+
+ val docCollector = new Traverser {
+ override def traverse(tree: Tree): Unit = tree match {
+ case dd: DocDef if dd.symbol != null && dd.symbol != NoSymbol =>
+ println("got a docdef: " + dd.comment)
+ docComments(dd.symbol) = dd.comment
+ dd.comment.defineVariables(dd.symbol)
+ case dd: DocDef =>
+ println("Argh!!! No sym in doc comment")
+ case t =>
+ println("Unknown tree: " + t.getClass.getSimpleName)
+ super.traverse(t)
+ }
+ }
+
+
+ override def typed(tree: Tree): Tree = {
+ println("The java typer says hi! From source file: " + unit.source.file.name)
+ docCollector.traverse(tree)
+ tree
+ }
+
+ override protected def macroImplementationNotFoundMessage(name: Name): String = (
+ super.macroImplementationNotFoundMessage(name)
+ + "\nWhen generating scaladocs for multiple projects at once, consider using -Ymacro-no-expand to disable macro expansions altogether."
+ )
+
+ override def typedDocDef(docDef: DocDef, mode: Mode, pt: Type): Tree = {
+ val sym = docDef.symbol
+
+ if ((sym ne null) && (sym ne NoSymbol)) {
+ val comment = docDef.comment
+ docComments(sym) = comment
+ comment.defineVariables(sym)
+ val typer1 = newTyper(context.makeNewScope(docDef, context.owner))
+ for (useCase <- comment.useCases) {
+ typer1.silent(_.asInstanceOf[ScaladocTyper].defineUseCases(useCase)) match {
+ case SilentTypeError(err) =>
+ reporter.warning(useCase.pos, err.errMsg)
+ case _ =>
+ }
+ for (useCaseSym <- useCase.defined) {
+ if (sym.name != useCaseSym.name)
+ reporter.warning(useCase.pos, "@usecase " + useCaseSym.name.decode + " does not match commented symbol: " + sym.name.decode)
+ }
+ }
+ }
+
+ super.typedDocDef(docDef, mode, pt)
+ }
+ }
trait ScaladocTyper extends Typer {
private def unit = context.unit
@@ -110,27 +169,24 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax
if ((doc ne null) && doc.raw.length > 0) {
log(s"joinComment(doc=$doc)")
- val joined = trees map {
- t =>
- DocDef(doc, t) setPos {
- if (t.pos.isDefined) {
- val pos = doc.pos.withEnd(t.pos.end)
- pos.makeTransparent
- } else {
- t.pos
- }
+ val joined = trees map { t =>
+ DocDef(doc, t) setPos {
+ if (t.pos.isDefined) {
+ val pos = doc.pos.withEnd(t.pos.end)
+ pos.makeTransparent
+ } else {
+ t.pos
}
+ }
}
- joined.find(_.pos.isOpaqueRange) foreach {
- main =>
- val mains = List(main)
- joined foreach { t => if (t ne main) ensureNonOverlapping(t, mains) }
+ joined.find(_.pos.isOpaqueRange) foreach { main =>
+ val mains = List(main)
+ joined foreach { t => if (t ne main) ensureNonOverlapping(t, mains) }
}
joined
+ } else {
+ trees
}
- else trees
-
- // trees
}