Skip to content

Commit 92b81e0

Browse files
First stab at compiling under dotty
1 parent 129957e commit 92b81e0

11 files changed

+62
-148
lines changed

build.sbt

Lines changed: 44 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,60 @@
1-
import AssemblyKeys._
2-
3-
name := "scalastyle"
4-
5-
organization := "org.scalastyle"
6-
7-
scalaVersion := "2.10.5"
8-
9-
scalacOptions ++= Seq("-deprecation", "-feature")
10-
11-
crossScalaVersions := Seq("2.10.5", "2.11.6")
12-
13-
description := "Scalastyle style checker for Scala"
1+
lazy val root = (project in file(".")).
2+
settings(
3+
name := "scalastyle",
4+
description := "Example sbt project that compiles using Dotty",
5+
version := "0.1",
6+
7+
// All the settings set below this line are important to get your project
8+
// to compile with Dotty. Please read the comments carefully.
9+
10+
// Dotty version
11+
scalaVersion := "0.1-SNAPSHOT",
12+
scalaOrganization := "ch.epfl.lamp",
13+
14+
// Enable Scala 2 compatibility mode.
15+
// This will allow you to use Scala 2 features that have been removed
16+
// from Dotty, like procedure syntax.
17+
// This is not required to compile code with Dotty, but it makes it easier
18+
// to test Dotty on an existing Scala 2 code base.
19+
// The long-term plan is to have a rewriting tool that can do most of the
20+
// porting work for you.
21+
scalacOptions ++= Seq("-language:Scala2"),
22+
23+
// Note: Dotty can use Scala 2.11 libraries so we set `scalaBinaryVersion`
24+
// to `2.11` for convenience. However, if you publish an artefact compiled
25+
// with Dotty, you should set it to `0.1`, this will force you to change
26+
// your library dependencies to be of the form `"org.foo" % "bar_2.11" % "1.0"`
27+
// instead of `"org.foo" %% "bar" % "1.0"`
28+
scalaBinaryVersion := "2.11",
29+
30+
// By default, sbt will depend on the scala-library version `scalaVersion`,
31+
// so we need to override it.
32+
autoScalaLibrary := false,
33+
// 2.11.5 is the version used by Dotty itself currently, we do the same to
34+
// avoid trouble.
35+
libraryDependencies += "org.scala-lang" % "scala-library" % "2.11.5",
1436

1537
libraryDependencies ++= Seq(
1638
"org.scalariform" %% "scalariform" % "0.1.7",
1739
"com.typesafe" % "config" % "1.2.0",
1840
"junit" % "junit" % "4.11" % "test",
1941
"com.novocode" % "junit-interface" % "0.10" % "test",
2042
"com.google.guava" % "guava" % "17.0" % "test",
21-
"org.scalatest" %% "scalatest" % "2.2.2" % "test")
22-
23-
fork in Test := true
24-
25-
javaOptions in Test += "-Dfile.encoding=UTF-8"
26-
27-
coverageHighlighting := {
28-
if (scalaBinaryVersion.value == "2.10") false
29-
else true
30-
}
31-
32-
publishMavenStyle := true
33-
34-
publishTo := {
35-
val nexus = "https://oss.sonatype.org/"
36-
if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
37-
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
38-
}
43+
"org.scalatest" %% "scalatest" % "2.2.2" % "test"),
3944

40-
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html"))
45+
// Maintained at https://github.com/lampepfl/dotty/tree/master/bridge
46+
scalaCompilerBridgeSource := ("ch.epfl.lamp" % "dotty-bridge" % "0.1.1-SNAPSHOT" % "component").sources(),
4147

42-
pomIncludeRepository := { _ => false }
48+
(scalastyleConfig in Compile) := file("lib/scalastyle_config.xml"),
49+
(scalastyleFailOnError in Compile) := true,
4350

44-
pomExtra := (
45-
<url>http://www.scalastyle.org</url>
46-
<scm>
47-
<url>scm:git:git@github.com:scalastyle/scalastyle.git</url>
48-
<connection>scm:git:git@github.com:scalastyle/scalastyle.git</connection>
49-
</scm>
50-
<developers>
51-
<developer>
52-
<id>matthewfarwell</id>
53-
<name>Matthew Farwell</name>
54-
<url>http://www.farwell.co.uk</url>
55-
</developer>
56-
</developers>)
51+
buildInfoSettings,
5752

58-
assemblySettings
53+
sourceGenerators in Compile <+= buildInfo,
5954

60-
artifact in (Compile, assembly) ~= { art =>
61-
art.copy(`classifier` = Some("batch"))
62-
}
63-
64-
addArtifact(artifact in (Compile, assembly), assembly)
65-
66-
mainClass in assembly := Some("org.scalastyle.Main")
67-
68-
buildInfoSettings
69-
70-
sourceGenerators in Compile <+= buildInfo
71-
72-
buildInfoKeys := Seq[BuildInfoKey](organization, name, version, scalaVersion, sbtVersion)
55+
buildInfoKeys := Seq[BuildInfoKey](organization, name, version, scalaVersion, sbtVersion),
7356

7457
buildInfoPackage := "org.scalastyle"
7558

76-
seq(filterSettings: _*)
77-
78-
if (System.getProperty("scalastyle.publish-ivy-only") == "true") {
79-
Seq()
80-
} else {
81-
Seq(aetherPublishBothSettings: _*)
82-
}
83-
84-
aether.Aether.aetherLocalRepo := Path.userHome / "dev" / "repo"
85-
86-
EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Managed
87-
88-
releaseSettings
89-
90-
ReleaseKeys.crossBuild := true
91-
92-
val dynamicPublish = Def.taskDyn {
93-
if (version.value.trim.endsWith("SNAPSHOT")) {
94-
Def.task { publish.value }
95-
} else {
96-
Def.task { PgpKeys.publishSigned.value }
97-
}
98-
}
59+
)
9960

100-
ReleaseKeys.publishArtifactsAction := dynamicPublish.value

lib/scalastyle_config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<check class="org.scalastyle.scalariform.NoFinalizeChecker" level="warning" enabled="true"></check>
7979
<check class="org.scalastyle.scalariform.CovariantEqualsChecker" level="warning" enabled="true"></check>
8080
<check class="org.scalastyle.scalariform.StructuralTypeChecker" level="warning" enabled="true"></check>
81+
<check class="org.scalastyle.scalariform.XmlLiteralChecker" level="error" enabled="true"></check>
8182
<check class="org.scalastyle.file.RegexChecker" level="warning" enabled="true">
8283
<parameters>
8384
<parameter name="regex"><![CDATA[println]]></parameter>

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.7
1+
sbt.version=0.13.11

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
44

55
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
66

7+
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "0.8.0")
8+
79
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.1")
810

911
addSbtPlugin("com.github.sdb" % "xsbt-filter" % "0.4")

src/main/scala/org/scalastyle/Checker.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class CheckerUtils(classLoader: Option[ClassLoader] = None) {
145145
* If there is no encoding passed, we try the default, then UTF-8, then UTF-16, then ISO-8859-1
146146
*/
147147
def readFile(file: String, encoding: Option[String])(implicit codec: Codec): String = {
148-
@tailrec
149148
def readFileWithEncoding(file: String, encodings: List[String]): Option[String] = {
150149
if (encodings.isEmpty) {
151150
None
@@ -226,10 +225,10 @@ trait Checker[A] {
226225
val sErrorKey = customErrorKey.getOrElse(errorKey)
227226

228227
p2 match {
229-
case PositionError(position, args, errorKey) => StyleError(file, this.getClass(), errorKey.getOrElse(sErrorKey), level, args, customMessage = customMessage)
230-
case FileError(args, errorKey) => StyleError(file, this.getClass(), errorKey.getOrElse(sErrorKey), level, args, None, None, customMessage)
231-
case LineError(line, args, errorKey) => StyleError(file, this.getClass(), errorKey.getOrElse(sErrorKey), level, args, Some(line), None, customMessage)
232-
case ColumnError(line, column, args, errorKey) => StyleError(file, this.getClass(), errorKey.getOrElse(sErrorKey), level, args, Some(line), Some(column), customMessage)
228+
case PositionError(position, args, ek) => StyleError(file, this.getClass.asInstanceOf[Class[_ <: org.scalastyle.Checker[_]]], ek.getOrElse(sErrorKey), level, args, customMessage = customMessage)
229+
case FileError(args, ek) => StyleError(file, this.getClass.asInstanceOf[Class[_ <: org.scalastyle.Checker[_]]], ek.getOrElse(sErrorKey), level, args, None, None, customMessage)
230+
case LineError(line, args, ek) => StyleError(file, this.getClass.asInstanceOf[Class[_ <: org.scalastyle.Checker[_]]], ek.getOrElse(sErrorKey), level, args, Some(line), None, customMessage)
231+
case ColumnError(line, column, args, ek) => StyleError(file, this.getClass.asInstanceOf[Class[_ <: org.scalastyle.Checker[_]]], ek.getOrElse(sErrorKey), level, args, Some(line), Some(column), customMessage)
233232
}
234233
}
235234

src/main/scala/org/scalastyle/Output.scala

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,7 @@ object XmlOutput {
131131
case class Alert(filename: String, severity: String, message: String, source: Option[Class[_]], line: Option[Int], column: Option[Int])
132132

133133
private[this] def toCheckstyleFormat[T <: FileSpec](messageHelper: MessageHelper, messages: Iterable[Message[T]]): Elem = {
134-
<checkstyle version="5.0">
135-
{messages.collect {
136-
case StyleError(file, clazz, key, level, args, line, column, customMessage) =>
137-
Alert(file.name, messageHelper.text(level.name), Output.findMessage(messageHelper, key, args, customMessage), Some(clazz), line, column)
138-
case StyleException(file, clazz, message, stacktrace, line, column) =>
139-
Alert(file.name, "error", message, clazz, line, column)
140-
}.groupBy {
141-
_.filename
142-
}.map {
143-
case (filename, alerts) =>
144-
<file name={filename}>
145-
{alerts.map {
146-
case Alert(fn, severity, message, source, line, column) => {
147-
val s = source.collect {
148-
case x: Class[_] => x.getName
149-
}
150-
<error severity={severity} message={message}/> % attr("source", s) % attr("line", line) % attr("column", column)
151-
}
152-
}}
153-
</file>
154-
}}
155-
</checkstyle>
134+
???
156135
}
157136

158137
private[this] def attr(name: String, value: Option[Any]): xml.MetaData = value match {

src/main/scala/org/scalastyle/ScalastyleConfiguration.scala

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,7 @@ object ScalastyleConfiguration {
116116
private[this] def toCDATA(s: String) = scala.xml.Unparsed("<![CDATA[" + s + "]]>")
117117

118118
def toXml(scalastyleConfiguration: ScalastyleConfiguration): scala.xml.Elem = {
119-
val elements = scalastyleConfiguration.checks.map(c => {
120-
val parameters = if (c.parameters.size > 0) {
121-
val ps = c.parameters.map(p => {
122-
val text = toCDATA(p._2)
123-
<parameter name={p._1}>{text}</parameter>
124-
})
125-
<parameters>{ps}</parameters>
126-
} else {
127-
scala.xml.Null
128-
}
129-
val customMessage = c.customMessage match {
130-
case Some(s) => {
131-
val text = toCDATA(s)
132-
<customMessage>{text}</customMessage>
133-
}
134-
case None => scala.xml.Null
135-
}
136-
val check = <check class={c.className} level={c.level.name} enabled={if (c.enabled) True else False}>{customMessage}{parameters}</check>
137-
c.customId match {
138-
case Some(x) => check % Attribute(None, "customId", Text(x), scala.xml.Null)
139-
case None => check
140-
}
141-
})
142-
143-
<scalastyle commentFilter={if (scalastyleConfiguration.commentFilter) Enabled else Disabled}>
144-
<name>{scalastyleConfiguration.name}</name>
145-
{elements}
146-
</scalastyle>
119+
???
147120
}
148121

149122
def toXmlString(scalastyleConfiguration: ScalastyleConfiguration, width: Int, step: Int): String =

src/main/scala/org/scalastyle/scalariform/AbstractMethodChecker.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import _root_.scalariform.parser.Param
3030
import _root_.scalariform.parser.ParamClauses
3131
import _root_.scalariform.parser.TmplDef
3232
import _root_.scalariform.parser.Type
33+
import scala.reflect.ClassTag
3334

3435
object VisitorHelper {
3536
class Clazz[+T <: AstNode]()
@@ -42,19 +43,19 @@ object VisitorHelper {
4243
if (matches(t)) t :: l else l
4344
}
4445

45-
protected[scalariform] def getAllRecursive[T <: AstNode](ast: Any)(implicit manifest: Manifest[T]): List[T] = {
46+
protected[scalariform] def getAllRecursive[T <: AstNode](ast: Any)(implicit manifest: ClassTag[T]): List[T] = {
4647
def fn(t : T): List[T] = List[T](t) ++ t.immediateChildren.flatMap(child => getAllRecursive[T](child))
4748

4849
myVisit[T, T](manifest.runtimeClass.asInstanceOf[Class[T]], fn)(ast)
4950
}
5051

51-
protected[scalariform] def getAll[T <: AstNode](ast: Any)(implicit manifest: Manifest[T]): List[T] = {
52+
protected[scalariform] def getAll[T <: AstNode](ast: Any)(implicit manifest: ClassTag[T]): List[T] = {
5253
def fn(t : T): List[T] = List[T](t)
5354

5455
myVisit[T, T](manifest.runtimeClass.asInstanceOf[Class[T]], fn)(ast)
5556
}
5657

57-
protected[scalariform] def visit[T <: AstNode, X](fn: T => List[X])(ast: Any)(implicit manifest: Manifest[T]): List[X] = {
58+
protected[scalariform] def visit[T <: AstNode, X](fn: T => List[X])(ast: Any)(implicit manifest: ClassTag[T]): List[X] = {
5859
myVisit[T, X](manifest.runtimeClass.asInstanceOf[Class[T]], fn)(ast)
5960
}
6061

src/main/scala/org/scalastyle/scalariform/ClassNamesChecker.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ class PackageNamesChecker extends ScalariformChecker {
8181

8282
def isPartOfPackageName(t: Token): Boolean = (t.tokenType == DOT) || (t.tokenType == VARID)
8383

84-
@annotation.tailrec
8584
def getNextPackageName(tokens: List[Token]): (List[Token], List[Token]) = tokens match {
8685
case Nil => (Nil, Nil)
8786
case hd :: tail if hd.tokenType == PACKAGE => tail.span(isPartOfPackageName(_))
88-
case l: Any => getNextPackageName(l.dropWhile(tok => tok.tokenType != PACKAGE))
87+
case l: List[Token] => getNextPackageName(l.dropWhile(tok => tok.tokenType != PACKAGE))
8988
}
9089

91-
@annotation.tailrec
9290
def getPackageNameLoop(tokens: List[Token], myAccumulator: List[List[Token]]): List[List[Token]] =
9391
getNextPackageName(tokens) match {
9492
case (Nil, Nil) => myAccumulator.reverse // Return the result, but reverse since we gathered backward

src/main/scala/org/scalastyle/scalariform/IfBraceChecker.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.scalastyle.scalariform.VisitorHelper.visit
2727
import _root_.scalariform.parser.BlockExpr
2828
import _root_.scalariform.parser.Expr
2929
import _root_.scalariform.parser.IfExpr
30+
import _root_.scalariform.parser.ExprElement
3031

3132
class IfBraceChecker extends CombinedChecker {
3233
val DefaultSingleLineAllowed = true
@@ -95,7 +96,7 @@ class IfBraceChecker extends CombinedChecker {
9596
body.contents.head match {
9697
case e: BlockExpr => None
9798
case e: IfExpr => None
98-
case e: Any => lines.toLineColumn(e.tokens.head.offset)
99+
case e: ExprElement => lines.toLineColumn(e.tokens.head.offset)
99100
}
100101
} else {
101102
None

src/main/scala/org/scalastyle/scalariform/ScalaDocChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ object ScalaDocChecker {
346346
case TagRegex(tag, ref, rest) => Some(TagSclaDocLine(tag, ref, rest))
347347
case "/**" => None
348348
case "*/" => None
349-
case text: Any => Some(RawScalaDocLine(text))
349+
case text: String => Some(RawScalaDocLine(text))
350350
})
351351

352352
def combineScalaDocFor[A](lines: List[ScalaDocLine], tag: String, f: (String, String) => A): List[A] = lines match {

0 commit comments

Comments
 (0)