Skip to content

Commit 86ddd97

Browse files
authored
Merge pull request #164 from SethTisue/post-m5
support 2.13.0-RC1
2 parents 95ada5b + 7e6fe6c commit 86ddd97

File tree

16 files changed

+452
-316
lines changed

16 files changed

+452
-316
lines changed

.travis.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
sudo: false
2-
3-
cache:
4-
directories:
5-
- $HOME/.ivy2
6-
- $HOME/.sbt/boot
7-
- $HOME/.sbt/launchers
8-
91
language: scala
102

113
jdk:
@@ -23,25 +15,11 @@ env:
2315
- SCALA_VERSION=2.12.6
2416
- SCALA_VERSION=2.12.7
2517
- SCALA_VERSION=2.12.8
26-
- SCALA_VERSION=2.13.0-M5
18+
- SCALA_VERSION=2.13.0-RC1
2719

28-
# there's no better way it seems.. https://github.com/travis-ci/travis-ci/issues/1519
20+
# 2.11.12 was the first Scala 2.11.x version to work on jdk11
2921
matrix:
3022
exclude:
31-
# scala 2.12+ requires jdk8
32-
- jdk: openjdk6
33-
env: SCALA_VERSION=2.12.3
34-
- jdk: openjdk6
35-
env: SCALA_VERSION=2.12.4
36-
- jdk: openjdk6
37-
env: SCALA_VERSION=2.12.6
38-
- jdk: openjdk6
39-
env: SCALA_VERSION=2.12.7
40-
- jdk: openjdk6
41-
env: SCALA_VERSION=2.12.8
42-
- jdk: openjdk6
43-
env: SCALA_VERSION=2.13.0-M5
44-
# 2.11.12 was the first Scala 2.11.x version to work on jdk11
4523
- jdk: openjdk11
4624
env: SCALA_VERSION=2.11.6
4725
- jdk: openjdk11
@@ -58,3 +36,8 @@ script:
5836
before_cache:
5937
- find $HOME/.sbt -name "*.lock" | xargs rm
6038
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm
39+
cache:
40+
directories:
41+
- $HOME/.ivy2
42+
- $HOME/.sbt/boot
43+
- $HOME/.sbt/launchers

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ lazy val `genjavadoc-plugin` = (project in file("plugin"))
4040
val default = (unmanagedSourceDirectories in Compile).value
4141
def r(from: String, to: String) = default.map(f => new java.io.File(f.getPath.replaceAll(from, to)))
4242
if (scalaVersion.value == "2.12.0") r("""/scala-2\.12$""", "/scala-2.11")
43-
else if (scalaMajorVersion.value == 13) r("""/scala-2\.13[^/]*$""", "/scala-2.12")
43+
else if (scalaMajorVersion.value == 13) r("""/scala-2\.13[^/]*$""", "/scala-2.13")
4444
else default
4545
},
4646
crossVersion := CrossVersion.full,
@@ -58,7 +58,7 @@ lazy val defaults = Seq(
5858
val earliest211 = 6
5959
val latest211 = 12
6060
val latest212 = 8
61-
val pre213 = List("M5")
61+
val pre213 = List("RC1")
6262
val skipVersions = Set("2.11.9", "2.11.10")
6363
val scala211Versions =
6464
(earliest211 to latest211)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.typesafe.genjavadoc
2+
3+
trait NeedsJavaSig { this: TransformCake =>
4+
5+
import global._
6+
import definitions._
7+
8+
def needsJavaSig(tp: Type): Boolean =
9+
!settings.Ynogenericsig.value && NeedsSigCollector.collect(tp)
10+
11+
private object NeedsSigCollector extends TypeCollector(false) {
12+
private def rebindInnerClass(pre: Type, cls: Symbol): Type =
13+
if (cls.owner.isClass) cls.owner.tpe else pre // why not cls.isNestedClass?
14+
override def traverse(tp: Type): Unit = {
15+
if (!result) {
16+
tp match {
17+
case st: SubType =>
18+
traverse(st.supertype)
19+
case TypeRef(pre, sym, args) =>
20+
if (sym == ArrayClass) args foreach traverse
21+
else if (sym.isTypeParameterOrSkolem || sym.isExistentiallyBound || !args.isEmpty) result = true
22+
else if (sym.isClass) traverse(rebindInnerClass(pre, sym)) // #2585
23+
else if (!sym.owner.isPackageClass) traverse(pre)
24+
case PolyType(_, _) | ExistentialType(_, _) =>
25+
result = true
26+
case RefinedType(parents, _) =>
27+
parents foreach traverse
28+
case ClassInfoType(parents, _, _) =>
29+
parents foreach traverse
30+
case at: AnnotatedType =>
31+
traverse(at.underlying)
32+
case _ =>
33+
mapOver(tp)
34+
}
35+
}
36+
}
37+
}
38+
39+
}
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.typesafe.genjavadoc
2+
3+
trait NeedsJavaSig { this: TransformCake =>
4+
5+
import global._
6+
import definitions._
7+
8+
def needsJavaSig(tp: Type): Boolean =
9+
!settings.Ynogenericsig.value && NeedsSigCollector.collect(tp)
10+
11+
private object NeedsSigCollector extends TypeCollector(false) {
12+
private def rebindInnerClass(pre: Type, cls: Symbol): Type =
13+
if (cls.owner.isClass) cls.owner.tpe else pre // why not cls.isNestedClass?
14+
override def traverse(tp: Type): Unit = {
15+
if (!result) {
16+
tp match {
17+
case st: SubType =>
18+
traverse(st.supertype)
19+
case TypeRef(pre, sym, args) =>
20+
if (sym == ArrayClass) args foreach traverse
21+
else if (sym.isTypeParameterOrSkolem || sym.isExistentiallyBound || !args.isEmpty) result = true
22+
else if (sym.isClass) traverse(rebindInnerClass(pre, sym)) // #2585
23+
else if (!sym.owner.isPackageClass) traverse(pre)
24+
case PolyType(_, _) | ExistentialType(_, _) =>
25+
result = true
26+
case RefinedType(parents, _) =>
27+
parents foreach traverse
28+
case ClassInfoType(parents, _, _) =>
29+
parents foreach traverse
30+
case at: AnnotatedType =>
31+
traverse(at.underlying)
32+
case _ =>
33+
mapOver(tp)
34+
}
35+
}
36+
}
37+
}
38+
39+
}
40+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.typesafe.genjavadoc
2+
3+
import scala.reflect.internal.util.Position
4+
import scala.tools.nsc.doc.ScaladocSyntaxAnalyzer
5+
6+
trait Comments extends BaseComments { this: TransformCake =>
7+
lazy val parser = new ScaladocSyntaxAnalyzer[global.type](global) {
8+
val runsAfter = List[String]()
9+
val runsRightAfter = None
10+
}
11+
override def parseComments(): Unit =
12+
new parser.ScaladocUnitParser(unit, Nil) {
13+
override def newScanner = new parser.ScaladocUnitScanner(unit, Nil) {
14+
override def registerDocComment(str: String, pos: Position) = {
15+
super.registerDocComment(str, pos)
16+
comments += pos -> Comment(pos, str)
17+
}
18+
}
19+
}.parse()
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.typesafe.genjavadoc
2+
3+
trait NeedsJavaSig { this: TransformCake =>
4+
5+
import global._
6+
import definitions._
7+
8+
def needsJavaSig(tp: Type): Boolean =
9+
!settings.Ynogenericsig.value && NeedsSigCollector.collect(tp)
10+
11+
private object NeedsSigCollector extends TypeCollector(false) {
12+
private def rebindInnerClass(pre: Type, cls: Symbol): Type =
13+
if (cls.owner.isClass) cls.owner.tpe else pre // why not cls.isNestedClass?
14+
// the rest is mostly copy and paste from NeedsSigCollector in nsc/transform/Erasure.scala
15+
@annotation.tailrec
16+
private[this] def untilApply(ts: List[Type]): Unit =
17+
if (! ts.isEmpty && ! result) { apply(ts.head) ; untilApply(ts.tail) }
18+
override def apply(tp: Type): Unit = {
19+
if (!result) {
20+
tp match {
21+
case st: SubType =>
22+
apply(st.supertype)
23+
case TypeRef(pre, sym, args) =>
24+
if (sym == ArrayClass) untilApply(args)
25+
else if (sym.isTypeParameterOrSkolem || sym.isExistentiallyBound || !args.isEmpty) result = true
26+
else if (sym.isClass) apply(rebindInnerClass(pre, sym)) // #2585
27+
else if (!sym.owner.isPackageClass) apply(pre)
28+
case PolyType(_, _) | ExistentialType(_, _) =>
29+
result = true
30+
case RefinedType(parents, _) =>
31+
untilApply(parents)
32+
case ClassInfoType(parents, _, _) =>
33+
untilApply(parents)
34+
case at: AnnotatedType =>
35+
apply(at.underlying)
36+
case _ =>
37+
tp.foldOver(this)
38+
}
39+
}
40+
}
41+
}
42+
43+
}
44+

plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.typesafe.genjavadoc
22

33
import scala.annotation.tailrec
44

5-
trait AST { this: TransformCake
5+
trait AST { this: TransformCake =>
66

77
import global._
88

@@ -18,11 +18,11 @@ trait AST { this: TransformCake ⇒
1818
sym: Symbol,
1919
name: String,
2020
access: String,
21-
pattern: (String, String) String,
21+
pattern: (String, String) => String,
2222
module: Boolean,
2323
comment: Seq[String],
2424
pckg: String,
25-
filepattern: String String,
25+
filepattern: String => String,
2626
members: Vector[Templ],
2727
interface: Boolean,
2828
static: Boolean,
@@ -49,14 +49,14 @@ trait AST { this: TransformCake ⇒
4949
object ClassInfo {
5050
def apply(c: ImplDef, comment: Seq[String], topLevel: Boolean): ClassInfo = {
5151
c match {
52-
case ClassDef(mods, _, tparams, impl)
52+
case ClassDef(mods, _, tparams, impl) =>
5353
val name = c.name.toString
5454
val acc = access(mods, topLevel)
5555
val fl = flags(mods)
5656
val kind = if (mods.isInterface || mods.isTrait) "interface" else "class"
5757
val tp = c.symbol.owner.thisType.memberInfo(c.symbol) match {
58-
case p @ PolyType(params, _) js(c.symbol, p)
59-
case _ ""
58+
case p @ PolyType(params, _) => js(c.symbol, p)
59+
case _ => ""
6060
}
6161
val parent = {
6262
val p = impl.parents.head
@@ -65,13 +65,13 @@ trait AST { this: TransformCake ⇒
6565
s" extends ${js(c.symbol, p.tpe)}"
6666
}
6767
}
68-
val intf = impl.parents.tail map (i js(c.symbol, i.tpe)) mkString (", ")
68+
val intf = impl.parents.tail map (i => js(c.symbol, i.tpe)) mkString (", ")
6969
val interfaces = if (!intf.isEmpty) (if (mods.isInterface || mods.isTrait) " extends " else " implements ") + intf else ""
70-
val sig = (n: String, a: String) s"$a $fl $kind $n$tp$parent$interfaces"
70+
val sig = (n: String, a: String) => s"$a $fl $kind $n$tp$parent$interfaces"
7171
val packageName = c.symbol.enclosingPackage.fullName('/')
7272
val file =
7373
if (packageName == "<empty>") (n: String) => s"$n.java"
74-
else (n: String) s"$packageName/$n.java"
74+
else (n: String) => s"$packageName/$n.java"
7575
val pckg = c.symbol.enclosingPackage.fullName
7676
ClassInfo(c.symbol, name, acc, sig, mods.hasModuleFlag, comment, pckg, file, Vector.empty, kind == "interface", false, true)
7777
}
@@ -93,7 +93,7 @@ trait AST { this: TransformCake ⇒
9393
}
9494
}
9595

96-
case class MethodInfo(access: String, pattern: String String, ret: String, name: String, comment: Seq[String]) extends Templ {
96+
case class MethodInfo(access: String, pattern: String => String, ret: String, name: String, comment: Seq[String]) extends Templ {
9797
def sig = pattern(s"$ret $name")
9898
}
9999
object MethodInfo {
@@ -104,13 +104,13 @@ trait AST { this: TransformCake ⇒
104104
("", d.symbol.enclClass.name.toString)
105105
} else (js(d.symbol, d.tpt.tpe), d.name.toString)
106106
val tp = d.symbol.owner.thisType.memberInfo(d.symbol) match {
107-
case p @ PolyType(params, _) js(d.symbol, p)
108-
case _ ""
107+
case p @ PolyType(params, _) => js(d.symbol, p)
108+
case _ => ""
109109
}
110110
@tailrec def rec(l: List[ValDef], acc: Vector[String] = Vector.empty): Seq[String] = l match {
111-
case x :: Nil if hasVararg acc :+ s"${js(d.symbol, x.tpt.tpe, voidOK = false).dropRight(2)}... ${mangleMethodName(x)}"
112-
case x :: xs rec(xs, acc :+ s"${js(d.symbol, x.tpt.tpe, voidOK = false)} ${mangleMethodName(x)}")
113-
case Nil acc
111+
case x :: Nil if hasVararg => acc :+ s"${js(d.symbol, x.tpt.tpe, voidOK = false).dropRight(2)}... ${mangleMethodName(x)}"
112+
case x :: xs => rec(xs, acc :+ s"${js(d.symbol, x.tpt.tpe, voidOK = false)} ${mangleMethodName(x)}")
113+
case Nil => acc
114114
}
115115
val args = rec(d.vparamss.head) mkString ("(", ", ", ")")
116116

@@ -123,7 +123,7 @@ trait AST { this: TransformCake ⇒
123123
val throws = if (throwsAnnotations.isEmpty) "" else "throws " + throwsAnnotations.mkString(", ")
124124

125125
val impl = if (d.mods.isDeferred || interface) ";" else "{ throw new RuntimeException(); }"
126-
val pattern = (n: String) s"$acc $tp $n $args $throws $impl"
126+
val pattern = (n: String) => s"$acc $tp $n $args $throws $impl"
127127
def hasParam(n: String) = comment.find(_.contains(s"@param $n")).isDefined
128128

129129
val commentWithParams =
@@ -154,7 +154,7 @@ trait AST { this: TransformCake ⇒
154154
}
155155
val d = DefDef(sym, EmptyTree)
156156
val m = MethodInfo(d, false, Nil, varargs, None)
157-
m.copy(pattern = n "static " + m.pattern(n))
157+
m.copy(pattern = n => "static " + m.pattern(n))
158158
}
159159
}
160160

plugin/src/main/scala/com/typesafe/genjavadoc/BaseComments.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.typesafe.genjavadoc
33
import scala.collection.immutable.TreeMap
44
import scala.annotation.tailrec
55

6-
trait BaseComments { this: TransformCake
6+
trait BaseComments { this: TransformCake =>
77
import global._
88

99
def unit: CompilationUnit
@@ -29,23 +29,23 @@ trait BaseComments { this: TransformCake ⇒
2929
def apply(pos: Position, text: String) = {
3030
val ll = text.replaceAll("\n[ \t]*", "\n ").split("\n")
3131
.map {
32-
case See(prefix, link)
32+
case See(prefix, link) =>
3333
if (HttpLink.findFirstIn(link).isDefined)
3434
s"""$prefix<a href="$link"/>"""
3535
else
3636
s"$prefix$link"
37-
case x x
37+
case x => x
3838
}
39-
.map(line replacements.foldLeft(line) { case (l, (from, to)) l.replace(from, to) })
39+
.map(line => replacements.foldLeft(line) { case (l, (from, to)) => l.replace(from, to) })
4040
val (_, _, _, l2) = ll.foldLeft((false, false, true, List.empty[String])) {
4141
// insert <p> line upon transition to empty, collapse contiguous empty lines
42-
case ((pre, code, empty, lines), line @ EmptyLine())
42+
case ((pre, code, empty, lines), line @ EmptyLine()) =>
4343
val nl =
4444
if (pre || line.contains("/**") || line.contains("*/")) line :: lines
4545
else if (!pre && !empty) " * <p>" :: (lines.head + (if (code) "</code>" else "")) :: lines.tail
4646
else lines
4747
(pre, false, true, nl)
48-
case ((pre, code, empty, lines), line)
48+
case ((pre, code, empty, lines), line) =>
4949
val (nc, nl) = if (pre) (code, line) else codeLine(code, line)
5050
val np = if (line contains "<pre>") true else if (line contains "</pre>") false else pre
5151
val nl2 = if (pre && np) preLine(nl) else nl
@@ -62,12 +62,12 @@ trait BaseComments { this: TransformCake ⇒
6262
}
6363
private def replace(str: String, from: String, to: String): String = {
6464
str.indexOf(from) match {
65-
case -1 str
66-
case n str.substring(0, n) + to + str.substring(n + from.length)
65+
case -1 => str
66+
case n => str.substring(0, n) + to + str.substring(n + from.length)
6767
}
6868
}
6969
private def htmlEntity(str: String): String = {
70-
str flatMap (ch if (ch > 127) f"&#x${ch}%04x;" else "" + ch)
70+
str flatMap (ch => if (ch > 127) f"&#x${ch}%04x;" else "" + ch)
7171
}
7272
}
7373

@@ -88,7 +88,7 @@ trait BaseComments { this: TransformCake ⇒
8888

8989
def between(p1: Position, p2: Position) = unit.source.content.slice(p1.start, p2.start).filterNot(_ == '\n').mkString
9090

91-
object Scaladoc extends (Comment Boolean) {
91+
object Scaladoc extends (Comment => Boolean) {
9292
def apply(c: Comment): Boolean = c.text.head.startsWith("/**")
9393
}
9494

0 commit comments

Comments
 (0)