Skip to content

Commit

Permalink
Fix warnings in 2.13 and keep scala.collection.Seq for the api
Browse files Browse the repository at this point in the history
  • Loading branch information
mlachkar committed May 25, 2020
1 parent cb0b93a commit e77b4d5
Show file tree
Hide file tree
Showing 38 changed files with 59 additions and 62 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ jobs:
with:
java-version: adopt@1.11
- run: sbt ci-213
windows_212:
name: Windows/scala_2.12 tests
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v7
- run: sbt ci-212-windows
shell: bash

windows_213:
name: Windows/scala_2.13 tests
Expand Down
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ lazy val core = project
scalameta,
googleDiff,
"com.geirsson" %% "metaconfig-typesafe-config" % metaconfigV,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
collectionCompat
)
)
.enablePlugins(BuildInfoPlugin)
Expand All @@ -73,7 +74,10 @@ lazy val rules = project
.settings(
moduleName := "scalafix-rules",
description := "Built-in Scalafix rules",
libraryDependencies += "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
libraryDependencies ++= List(
"org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full,
collectionCompat
)
)
.dependsOn(core)

Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Dependencies {
def scalatest = "org.scalatest" %% "scalatest" % "3.0.8"
def bijectionCore = "com.twitter" %% "bijection-core" % "0.9.7"
def scalacheck = "org.scalacheck" %% "scalacheck" % "1.14.3"
def collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.6"

def testsDeps = List(
// integration property tests
Expand Down
5 changes: 0 additions & 5 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
"unit/test" ::
s
},
commands += Command.command("ci-212-windows") { s =>
s"++$scala212" ::
s"unit/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
s
},
commands += Command.command("ci-213-windows") { s =>
s"++$scala213" ::
s"unit/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util
import java.util.Optional
import metaconfig.Conf
import metaconfig.Configured
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.meta.io.AbsolutePath
import scala.meta.io.Classpath
import scala.util.control.NoStackTrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.eclipse.jgit.treewalk.FileTreeIterator
import org.eclipse.jgit.util.io.NullOutputStream
import org.eclipse.jgit.lib.Constants.DOT_GIT

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import metaconfig.{ConfError, Configured}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import metaconfig.internal.ConfGet
import metaconfig.typesafeconfig.typesafeConfigMetaconfigParser
import pprint.TPrint
import scala.annotation.StaticAnnotation
import scala.language.higherKinds
import scala.meta.internal.io.PathIO
import scala.meta.internal.symtab.SymbolTable
import scala.meta.io.AbsolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object CompletionsOps {
if (setting.isHidden) Nil
else setting.name :: setting.alternativeNames.filter(_.length == 1)

private def toZshOption(setting: Setting): scala.Seq[String] = {
private def toZshOption(setting: Setting): scala.collection.Seq[String] = {
if (setting.isHidden) Nil
else {
// See https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#writing-completion-functions-using-_arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import metaconfig.generic.Settings
import metaconfig.internal.Case
import org.typelevel.paiges.{Doc => D}
import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ListBuffer
import scala.meta.Tree
import scala.meta.inputs.Input
import scala.meta.internal.semanticdb.TextDocument
import scala.meta.internal.tokenizers.PlatformTokenizerCache
import scala.meta.io.AbsolutePath
import scala.meta.parsers.ParseException
import scala.util.control.NoStackTrace
Expand Down Expand Up @@ -81,7 +79,7 @@ object MainOps {
def files(args: ValidatedArgs): collection.Seq[AbsolutePath] =
args.args.ls match {
case Ls.Find =>
val buf = ArrayBuffer.empty[AbsolutePath]
val buf = Vector.newBuilder[AbsolutePath]
val visitor = new SimpleFileVisitor[Path] {
override def visitFile(
file: Path,
Expand Down Expand Up @@ -273,7 +271,6 @@ object MainOps {

def handleFile(args: ValidatedArgs, file: AbsolutePath): ExitStatus = {
try {
PlatformTokenizerCache.megaCache.clear()
unsafeHandleFile(args, file)
} catch {
case e: ParseException =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import scala.collection.immutable.IndexedSeq
object Compat {
type View[T] = collection.SeqView[T, IndexedSeq[T]]
type SeqView[T] = collection.SeqView[T, IndexedSeq[T]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import scala.collection.immutable.IndexedSeq
object Compat {
type View[T] = collection.SeqView[T, IndexedSeq[T]]
type SeqView[T] = collection.Seq[T]

}
3 changes: 2 additions & 1 deletion scalafix-core/src/main/scala-2.13/scalafix/util/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package scalafix.util
object Compat {
type View[T] = collection.View[T]
type SeqView[T] = collection.SeqView[T]
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package scala.meta.internal

import scala.compat.Platform.EOL
import scala.meta._
import scala.meta.internal.semanticdb.Scala.Descriptor
import scala.meta.internal.semanticdb.Scala.DescriptorParser
import scala.meta.internal.trees.Origin
import scala.meta.internal.{semanticdb => s}

object ScalametaInternals {
private val EOL = System.lineSeparator()

def symbolOwnerAndDescriptor(symbol: String): (String, Descriptor) = {
val (desc, owner) = DescriptorParser(symbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scalafix.internal.diff

import difflib.{DiffUtils => DU}
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

object DiffUtils {
def unifiedDiff(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scalafix.patch.Patch.internal._
import scalafix.rule.RuleName
import scalafix.util.TreeExtractors.Mods
import scalafix.v0._
import scala.collection.compat._ // used for cross-compilation.

/** EscapeHatch is an algorithm to selectively disable rules. There
* are two mechanisms to do so: anchored comments and the
Expand Down Expand Up @@ -171,7 +172,7 @@ object EscapeHatch {
if (isEmpty) (true, None)
else {
val escapesUpToPos =
escapeTree.to(EscapeOffset(position)).valuesIterator.flatten
escapeTree.rangeTo(EscapeOffset(position)).valuesIterator.flatten
escapesUpToPos
.collectFirst {
case f @ EscapeFilter(_, _, _, Some(end))
Expand Down Expand Up @@ -316,7 +317,7 @@ object EscapeHatch {
if (disabling.isEmpty) (true, None)
else {
val disables =
disabling.to(EscapeOffset(position)).valuesIterator.flatten
disabling.rangeTo(EscapeOffset(position)).valuesIterator.flatten
loop(disables.toList, None)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ object ImportPatchOps {
.sortBy(_.ref.syntax)
.map(is => ctx.addRight(editToken, s"\nimport ${is.syntax}"))
val isRemovedImporter =
allImporters.toIterator
allImporters.iterator
.filter(_.importees.forall(isRemovedImportee))
.toSet
def removeSpaces(tokens: Iterable[Token]): Patch = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ trait LegacyPatchOps extends PatchOps {
Patch.replaceSymbols(toReplace: _*)
@deprecated(DeprecationMessage, "0.6.0")
final def replaceSymbols(
toReplace: Seq[(String, String)]
toReplace: scala.collection.Seq[(String, String)]
)(implicit noop: DummyImplicit, index: SemanticdbIndex): Patch =
Patch.replaceSymbols(toReplace: _*)
Patch.replaceSymbols(toReplace.toSeq: _*)
@deprecated(DeprecationMessage, "0.6.0")
final def renameSymbol(fromSymbol: Symbol.Global, toName: String)(
implicit index: SemanticdbIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ object PatchInternals {
val patchMap = patches
.groupBy(x => TokenOps.hash(x.tok))
.mapValues(_.reduce(merge).newTok)
ctx.tokens.toIterator
ctx.tokens.iterator
.map(tok => patchMap.getOrElse(TokenOps.hash(tok), tok.syntax))
.mkString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object ReplaceSymbolOps {
)(implicit ctx: RuleCtx, index: SemanticdbIndex): Patch = {
if (moveSymbols.isEmpty) return Patch.empty
val moves: Map[String, Symbol.Global] =
moveSymbols.toIterator.flatMap {
moveSymbols.iterator.flatMap {
case ReplaceSymbol(
term @ Symbol.Global(_, Signature.Method(_, _)),
to
Expand Down Expand Up @@ -67,7 +67,7 @@ object ReplaceSymbolOps {
}
object Move {
def unapply(name: Name): Option[Symbol.Global] = {
val result = name.symbol.toIterator
val result = name.symbol.iterator
.flatMap {
case Symbol.Multi(syms) => syms
case els => els :: Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object FileOps {
} else {
def listFilesIter(s: File): Iterable[String] = {
val (dirs, files) = Option(s.listFiles()).toIterable
.flatMap(_.toIterator)
.flatMap(_.iterator)
.partition(_.isDirectory)
files.map(_.getPath) ++ dirs.flatMap(listFilesIter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ object Pretty {
Doc.intercalate(Doc.comma, parameterList.map(prettyTermParameter))
}
val paramss = Doc.intercalate(`)` + `(`, params)

`(` + paramss + `)`
}
val returnType = pretty(t.returnType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ class LegacyCodePrinter(doc: SemanticDocument) {
case s.IntConstant(value) =>
text.append(value)
case s.LongConstant(value) =>
text.append(value + "L")
text.append(s"${value}L")
case s.FloatConstant(value) =>
text.append(value + "f")
text.append(s"${value}f")
case s.DoubleConstant(value) =>
text.append(value)
case s.StringConstant(value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object Rules {
all(Thread.currentThread.getContextClassLoader)
}
def all(classLoader: ClassLoader): List[Rule] = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
ServiceLoader
.load(classOf[Rule], classLoader)
.iterator()
Expand Down
2 changes: 1 addition & 1 deletion scalafix-core/src/main/scala/scalafix/patch/PatchOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ trait PatchOps {
* to differentiate from replaceSymbols((String, String)*) after type erasure
*/
def replaceSymbols(
toReplace: Seq[(String, String)]
toReplace: scala.collection.Seq[(String, String)]
)(implicit noop: DummyImplicit, index: SemanticdbIndex): Patch
}
6 changes: 3 additions & 3 deletions scalafix-core/src/main/scala/scalafix/syntax/package.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package scalafix

import scala.compat.Platform.EOL
import scala.meta._
import scala.meta.internal.scalafix.ScalafixScalametaHacks
import scalafix.internal.util.DenotationOps
import scalafix.internal.util.SymbolOps
import scalafix.util.SymbolMatcher
import scalafix.util.TreeOps
import scalafix.v0.Symbol
import scala.collection.compat.immutable.LazyList

package object syntax {
implicit class XtensionRefSymbolOpt(tree: Tree)(
Expand Down Expand Up @@ -40,7 +40,7 @@ package object syntax {
implicit class XtensionTreeScalafix(tree: Tree) {
def matches(matcher: SymbolMatcher): Boolean =
matcher.matches(tree)
def parents: Stream[Tree] = TreeOps.parents(tree)
def parents: LazyList[Tree] = TreeOps.parents(tree)
def input: Input = tree.tokens.headOption.map(_.input).getOrElse(Input.None)
}
implicit class XtensionInputScalafix(input: Input) {
Expand All @@ -49,7 +49,7 @@ package object syntax {
case inputs.Input.VirtualFile(label, _) => label
case _ =>
s"Input.${input.productPrefix}('<${input.chars.take(10).mkString}...>')"
.replaceAllLiterally(EOL, "")
.replace(System.lineSeparator(), "")
}
}
}
6 changes: 3 additions & 3 deletions scalafix-core/src/main/scala/scalafix/util/TokenList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import scala.meta.tokens.Tokens
/** Helper to traverse tokens as a doubly linked list. */
final class TokenList private (tokens: Tokens) {
def trailing(token: Token): View[Token] =
tokens.view(tok2idx(token) + 1, tokens.length)
tokens.view.slice(tok2idx(token) + 1, tokens.length)

def leading(token: Token): View[Token] =
tokens.view(0, tok2idx(token)).reverse
tokens.view.slice(0, tok2idx(token)).reverse

private[this] val tok2idx = {
val map = Map.newBuilder[Token, Int]
Expand All @@ -29,7 +29,7 @@ final class TokenList private (tokens: Tokens) {
tokens.drop(tok2idx(start)).find(p)

def slice(from: Token, to: Token): SeqView[Token] =
tokens.view(tok2idx(from), tok2idx(to))
tokens.view.slice(tok2idx(from), tok2idx(to))

/** Returns the next/trailing token or the original token if none exists.
*
Expand Down
7 changes: 4 additions & 3 deletions scalafix-core/src/main/scala/scalafix/util/TreeOps.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalafix.util

import scala.meta._
import scala.collection.compat.immutable.LazyList
import scalafix.v1.Symbol
import scala.meta.internal.semanticdb.Scala.Symbols
import scala.meta.internal.semanticdb.Scala.Descriptor
Expand Down Expand Up @@ -101,9 +102,9 @@ object TreeOps {
}
result.map(Symbol(_))
}
def parents(tree: Tree): Stream[Tree] =
tree #:: (tree.parent match {
def parents(tree: Tree): LazyList[Tree] =
tree +: (tree.parent match {
case Some(x) => parents(x)
case _ => Stream.empty
case _ => LazyList.empty
})
}
2 changes: 1 addition & 1 deletion scalafix-core/src/main/scala/scalafix/v0/Database.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scalafix.v0

import scala.compat.Platform.EOL
import scala.meta.internal.io.PathIO

final case class Database(documents: Seq[Document]) {
Expand All @@ -10,6 +9,7 @@ final case class Database(documents: Seq[Document]) {
lazy val synthetics: Seq[Synthetic] = documents.flatMap(_.synthetics)

def syntax: String = {
val EOL = System.lineSeparator
val s_entries = documents.map { attrs =>
val s_input = PathIO.toUnix(attrs.input.syntax)
val separator = EOL + "-" * s_input.toString.length + EOL
Expand Down
3 changes: 1 addition & 2 deletions scalafix-core/src/main/scala/scalafix/v0/Document.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scalafix.v0

import scala.compat.Platform.EOL
import scala.math.Ordering
import scala.meta.inputs._

Expand All @@ -27,7 +26,7 @@ final case class Document(
appendSection("Messages", messages.sorted.map(_.syntax))
appendSection("Symbols", symbols.sorted.map(_.syntax))
appendSection("Synthetics", synthetics.sorted.map(_.syntax))
lines.mkString(EOL)
lines.mkString(System.lineSeparator)
}

private implicit def positionOrder: Ordering[Position] =
Expand Down
Loading

0 comments on commit e77b4d5

Please sign in to comment.