Skip to content

Commit 0084849

Browse files
committed
Merge commit 'f784fbfbce' into merge-210
* commit 'f784fbfbce': Add a request to presentation compiler to fetch doc comment information. Refactor scaladoc base functionality to allow it to be mixed in with Global in the IDE. Conflicts: src/compiler/scala/tools/nsc/interactive/Doc.scala
2 parents 7dfbf07 + f784fbf commit 0084849

File tree

8 files changed

+191
-149
lines changed

8 files changed

+191
-149
lines changed

src/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,26 @@ trait CommentFactoryBase { this: MemberLookupBase =>
9797

9898
}
9999

100-
protected val endOfText = '\u0003'
101-
protected val endOfLine = '\u000A'
100+
private val endOfText = '\u0003'
101+
private val endOfLine = '\u000A'
102102

103103
/** Something that should not have happened, happened, and Scaladoc should exit. */
104-
protected def oops(msg: String): Nothing =
104+
private def oops(msg: String): Nothing =
105105
throw FatalError("program logic: " + msg)
106106

107107
/** The body of a line, dropping the (optional) start star-marker,
108108
* one leading whitespace and all trailing whitespace. */
109-
protected val CleanCommentLine =
109+
private val CleanCommentLine =
110110
new Regex("""(?:\s*\*\s?)?(.*)""")
111111

112112
/** Dangerous HTML tags that should be replaced by something safer,
113113
* such as wiki syntax, or that should be dropped. */
114-
protected val DangerousTags =
114+
private val DangerousTags =
115115
new Regex("""<(/?(div|ol|ul|li|h[1-6]|p))( [^>]*)?/?>|<!--.*-->""")
116116

117117
/** Maps a dangerous HTML tag to a safe wiki replacement, or an empty string
118118
* if it cannot be salvaged. */
119-
protected def htmlReplacement(mtch: Regex.Match): String = mtch.group(1) match {
119+
private def htmlReplacement(mtch: Regex.Match): String = mtch.group(1) match {
120120
case "p" | "div" => "\n\n"
121121
case "h1" => "\n= "
122122
case "/h1" => " =\n"
@@ -132,11 +132,11 @@ trait CommentFactoryBase { this: MemberLookupBase =>
132132

133133
/** Javadoc tags that should be replaced by something useful, such as wiki
134134
* syntax, or that should be dropped. */
135-
protected val JavadocTags =
135+
private val JavadocTags =
136136
new Regex("""\{\@(code|docRoot|inheritDoc|link|linkplain|literal|value)([^}]*)\}""")
137137

138138
/** Maps a javadoc tag to a useful wiki replacement, or an empty string if it cannot be salvaged. */
139-
protected def javadocReplacement(mtch: Regex.Match): String = mtch.group(1) match {
139+
private def javadocReplacement(mtch: Regex.Match): String = mtch.group(1) match {
140140
case "code" => "`" + mtch.group(2) + "`"
141141
case "docRoot" => ""
142142
case "inheritDoc" => ""
@@ -148,41 +148,41 @@ trait CommentFactoryBase { this: MemberLookupBase =>
148148
}
149149

150150
/** Safe HTML tags that can be kept. */
151-
protected val SafeTags =
151+
private val SafeTags =
152152
new Regex("""((&\w+;)|(&#\d+;)|(</?(abbr|acronym|address|area|a|bdo|big|blockquote|br|button|b|caption|cite|code|col|colgroup|dd|del|dfn|em|fieldset|form|hr|img|input|ins|i|kbd|label|legend|link|map|object|optgroup|option|param|pre|q|samp|select|small|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|tr|tt|var)( [^>]*)?/?>))""")
153153

154-
protected val safeTagMarker = '\u000E'
154+
private val safeTagMarker = '\u000E'
155155

156156
/** A Scaladoc tag not linked to a symbol and not followed by text */
157-
protected val SingleTag =
157+
private val SingleTagRegex =
158158
new Regex("""\s*@(\S+)\s*""")
159159

160160
/** A Scaladoc tag not linked to a symbol. Returns the name of the tag, and the rest of the line. */
161-
protected val SimpleTag =
161+
private val SimpleTagRegex =
162162
new Regex("""\s*@(\S+)\s+(.*)""")
163163

164164
/** A Scaladoc tag linked to a symbol. Returns the name of the tag, the name
165165
* of the symbol, and the rest of the line. */
166-
protected val SymbolTag =
166+
private val SymbolTagRegex =
167167
new Regex("""\s*@(param|tparam|throws|groupdesc|groupname|groupprio)\s+(\S*)\s*(.*)""")
168168

169169
/** The start of a scaladoc code block */
170-
protected val CodeBlockStart =
170+
private val CodeBlockStartRegex =
171171
new Regex("""(.*?)((?:\{\{\{)|(?:\u000E<pre(?: [^>]*)?>\u000E))(.*)""")
172172

173173
/** The end of a scaladoc code block */
174-
protected val CodeBlockEnd =
174+
private val CodeBlockEndRegex =
175175
new Regex("""(.*?)((?:\}\}\})|(?:\u000E</pre>\u000E))(.*)""")
176176

177177
/** A key used for a tag map. The key is built from the name of the tag and
178178
* from the linked symbol if the tag has one.
179179
* Equality on tag keys is structural. */
180-
protected sealed abstract class TagKey {
180+
private sealed abstract class TagKey {
181181
def name: String
182182
}
183183

184-
protected final case class SimpleTagKey(name: String) extends TagKey
185-
protected final case class SymbolTagKey(name: String, symbol: String) extends TagKey
184+
private final case class SimpleTagKey(name: String) extends TagKey
185+
private final case class SymbolTagKey(name: String, symbol: String) extends TagKey
186186

187187
/** Parses a raw comment string into a `Comment` object.
188188
* @param comment The expanded comment string (including start and end markers) to be parsed.
@@ -228,7 +228,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
228228
inCodeBlock: Boolean
229229
): Comment = remaining match {
230230

231-
case CodeBlockStart(before, marker, after) :: ls if (!inCodeBlock) =>
231+
case CodeBlockStartRegex(before, marker, after) :: ls if (!inCodeBlock) =>
232232
if (!before.trim.isEmpty && !after.trim.isEmpty)
233233
parse0(docBody, tags, lastTagKey, before :: marker :: after :: ls, false)
234234
else if (!before.trim.isEmpty)
@@ -247,7 +247,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
247247
parse0(docBody append endOfLine append marker, tags, lastTagKey, ls, true)
248248
}
249249

250-
case CodeBlockEnd(before, marker, after) :: ls =>
250+
case CodeBlockEndRegex(before, marker, after) :: ls =>
251251
if (!before.trim.isEmpty && !after.trim.isEmpty)
252252
parse0(docBody, tags, lastTagKey, before :: marker :: after :: ls, true)
253253
if (!before.trim.isEmpty)
@@ -266,17 +266,17 @@ trait CommentFactoryBase { this: MemberLookupBase =>
266266
parse0(docBody append endOfLine append marker, tags, lastTagKey, ls, false)
267267
}
268268

269-
case SymbolTag(name, sym, body) :: ls if (!inCodeBlock) =>
269+
case SymbolTagRegex(name, sym, body) :: ls if (!inCodeBlock) =>
270270
val key = SymbolTagKey(name, sym)
271271
val value = body :: tags.getOrElse(key, Nil)
272272
parse0(docBody, tags + (key -> value), Some(key), ls, inCodeBlock)
273273

274-
case SimpleTag(name, body) :: ls if (!inCodeBlock) =>
274+
case SimpleTagRegex(name, body) :: ls if (!inCodeBlock) =>
275275
val key = SimpleTagKey(name)
276276
val value = body :: tags.getOrElse(key, Nil)
277277
parse0(docBody, tags + (key -> value), Some(key), ls, inCodeBlock)
278278

279-
case SingleTag(name) :: ls if (!inCodeBlock) =>
279+
case SingleTagRegex(name) :: ls if (!inCodeBlock) =>
280280
val key = SimpleTagKey(name)
281281
val value = "" :: tags.getOrElse(key, Nil)
282282
parse0(docBody, tags + (key -> value), Some(key), ls, inCodeBlock)

src/compiler/scala/tools/nsc/interactive/CompilerControl.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ trait CompilerControl { self: Global =>
159159
def askLinkPos(sym: Symbol, source: SourceFile, response: Response[Position]) =
160160
postWorkItem(new AskLinkPosItem(sym, source, response))
161161

162+
/** Sets sync var `response` to doc comment information for a given symbol.
163+
*
164+
* @param sym The symbol whose doc comment should be retrieved (might come from a classfile)
165+
* @param site The place where sym is observed.
166+
* @param source The source file that's supposed to contain the definition
167+
* @param response A response that will be set to the following:
168+
* If `source` contains a definition of a given symbol that has a doc comment,
169+
* the (expanded, raw, position) triplet for a comment, otherwise ("", "", NoPosition).
170+
* Note: This operation does not automatically load `source`. If `source`
171+
* is unloaded, it stays that way.
172+
*/
173+
def askDocComment(sym: Symbol, site: Symbol, source: SourceFile, response: Response[(String, String, Position)]) =
174+
postWorkItem(new AskDocCommentItem(sym, site, source, response))
175+
162176
/** Sets sync var `response` to list of members that are visible
163177
* as members of the tree enclosing `pos`, possibly reachable by an implicit.
164178
* @pre source is loaded
@@ -376,6 +390,14 @@ trait CompilerControl { self: Global =>
376390
response raise new MissingResponse
377391
}
378392

393+
case class AskDocCommentItem(val sym: Symbol, val site: Symbol, val source: SourceFile, response: Response[(String, String, Position)]) extends WorkItem {
394+
def apply() = self.getDocComment(sym, site, source, response)
395+
override def toString = "doc comment "+sym+" in "+source
396+
397+
def raiseMissing() =
398+
response raise new MissingResponse
399+
}
400+
379401
case class AskLoadedTypedItem(val source: SourceFile, response: Response[Tree]) extends WorkItem {
380402
def apply() = self.waitLoadedTyped(source, response, this.onCompilerThread)
381403
override def toString = "wait loaded & typed "+source

src/compiler/scala/tools/nsc/interactive/Doc.scala

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)