From b9171e59ad26058157686469d925916dd44fd35a Mon Sep 17 00:00:00 2001 From: Pierre DAL-PRA Date: Sat, 1 Aug 2015 02:19:25 +0200 Subject: [PATCH 1/2] Simplify operations on collections --- compile/api/src/main/scala/sbt/ClassToAPI.scala | 2 +- compile/api/src/main/scala/xsbt/api/SameAPI.scala | 2 +- compile/inc/src/main/scala/sbt/inc/ClassfileManager.scala | 2 +- .../src/main/scala/sbt/compiler/AggressiveCompile.scala | 2 +- .../main/scala/sbt/compiler/MixedAnalyzingCompiler.scala | 8 ++++---- .../scala/sbt/compiler/javac/AnalyzingJavaCompiler.scala | 2 +- .../src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala | 4 ++-- .../scala/sbt/compiler/javac/ProcessLoggerWriter.scala | 2 +- ivy/src/main/scala/sbt/JsonUtil.scala | 6 +++--- ivy/src/main/scala/sbt/MakePom.scala | 4 ++-- .../scala/sbt/ivyint/CachedResolutionResolveEngine.scala | 2 +- main/actions/src/main/scala/sbt/TestResultLogger.scala | 2 +- main/actions/src/main/scala/sbt/Tests.scala | 4 ++-- main/src/main/scala/sbt/Aggregation.scala | 4 ++-- main/src/main/scala/sbt/Defaults.scala | 4 ++-- main/src/main/scala/sbt/EvaluateTask.scala | 2 +- main/src/main/scala/sbt/SettingCompletions.scala | 2 +- run/src/main/scala/sbt/TrapExit.scala | 2 +- .../tests/it/changes/ClassFailModuleSuccess.scala | 2 +- scripted/base/src/main/scala/xsbt/test/FileCommands.scala | 4 ++-- tasks/standard/src/test/scala/TaskRunnerFork.scala | 2 +- .../src/main/scala/sbt/classfile/ClassFile.scala | 4 ++-- util/classpath/src/main/scala/sbt/ReflectUtilities.scala | 2 +- util/collection/src/main/scala/sbt/Settings.scala | 2 +- util/complete/src/main/scala/sbt/LineReader.scala | 2 +- util/log/src/main/scala/sbt/LoggerWriter.scala | 2 +- util/relation/src/main/scala/sbt/Relation.scala | 2 +- 27 files changed, 39 insertions(+), 39 deletions(-) diff --git a/compile/api/src/main/scala/sbt/ClassToAPI.scala b/compile/api/src/main/scala/sbt/ClassToAPI.scala index 71a10ed22..acf593daf 100644 --- a/compile/api/src/main/scala/sbt/ClassToAPI.scala +++ b/compile/api/src/main/scala/sbt/ClassToAPI.scala @@ -293,7 +293,7 @@ object ClassToAPI { def referenceP(t: ParameterizedType): api.Parameterized = { val targs = t.getActualTypeArguments - val args = if (targs.length == 0) emptyTypeArray else arrayMap(targs)(t => reference(t): api.Type) + val args = if (targs.isEmpty) emptyTypeArray else arrayMap(targs)(t => reference(t): api.Type) val base = reference(t.getRawType) new api.Parameterized(base, args.toArray[api.Type]) } diff --git a/compile/api/src/main/scala/xsbt/api/SameAPI.scala b/compile/api/src/main/scala/xsbt/api/SameAPI.scala index 4cc36084c..ebf03f5cd 100644 --- a/compile/api/src/main/scala/xsbt/api/SameAPI.scala +++ b/compile/api/src/main/scala/xsbt/api/SameAPI.scala @@ -44,7 +44,7 @@ object TopLevel { /** Checks the API of two source files for equality.*/ object SameAPI { def apply(a: Source, b: Source): Boolean = - a.apiHash == b.apiHash && (a.hash.length > 0 && b.hash.length > 0) && apply(a.api, b.api) + a.apiHash == b.apiHash && (a.hash.nonEmpty && b.hash.nonEmpty) && apply(a.api, b.api) def apply(a: Def, b: Def): Boolean = (new SameAPI(false, true)).sameDefinitions(List(a), List(b), true) diff --git a/compile/inc/src/main/scala/sbt/inc/ClassfileManager.scala b/compile/inc/src/main/scala/sbt/inc/ClassfileManager.scala index 6d94295e3..20179b7bd 100644 --- a/compile/inc/src/main/scala/sbt/inc/ClassfileManager.scala +++ b/compile/inc/src/main/scala/sbt/inc/ClassfileManager.scala @@ -62,7 +62,7 @@ object ClassfileManager { logger.debug("Rolling back changes to class files.") logger.debug(s"Removing generated classes:\n${showFiles(generatedClasses)}") IO.deleteFilesEmptyDirs(generatedClasses) - logger.debug(s"Restoring class files: \n${showFiles(movedClasses.map(_._1))}") + logger.debug(s"Restoring class files: \n${showFiles(movedClasses.keys)}") for ((orig, tmp) <- movedClasses) IO.move(tmp, orig) } logger.debug(s"Removing the temporary directory used for backing up class files: $tempDir") diff --git a/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala b/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala index 201e6108d..92fb1a375 100644 --- a/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala +++ b/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala @@ -185,7 +185,7 @@ class AggressiveCompile(cacheFile: File) { def javaOnly(f: File) = f.getName.endsWith(".java") private[this] def explicitBootClasspath(options: Seq[String]): Seq[File] = - options.dropWhile(_ != CompilerArguments.BootClasspathOption).drop(1).take(1).headOption.toList.flatMap(IO.parseClasspath) + options.dropWhile(_ != CompilerArguments.BootClasspathOption).slice(1, 2).headOption.toList.flatMap(IO.parseClasspath) val store = MixedAnalyzingCompiler.staticCachedStore(cacheFile) diff --git a/compile/integration/src/main/scala/sbt/compiler/MixedAnalyzingCompiler.scala b/compile/integration/src/main/scala/sbt/compiler/MixedAnalyzingCompiler.scala index ea599b993..f3f4bf21d 100644 --- a/compile/integration/src/main/scala/sbt/compiler/MixedAnalyzingCompiler.scala +++ b/compile/integration/src/main/scala/sbt/compiler/MixedAnalyzingCompiler.scala @@ -43,7 +43,7 @@ final class MixedAnalyzingCompiler( logInputs(log, javaSrcs.size, scalaSrcs.size, outputDirs) /** compiles the scala code necessary using the analyzing compiler. */ def compileScala(): Unit = - if (!scalaSrcs.isEmpty) { + if (scalaSrcs.nonEmpty) { val sources = if (order == Mixed) incSrc else scalaSrcs val arguments = cArgs(Nil, absClasspath, None, options.options) timed("Scala compilation", log) { @@ -54,7 +54,7 @@ final class MixedAnalyzingCompiler( * Compiles the Java code necessary. All analysis code is included in this method. */ def compileJava(): Unit = - if (!javaSrcs.isEmpty) { + if (javaSrcs.nonEmpty) { // Runs the analysis portion of Javac. timed("Java compile + analysis", log) { javac.compile(javaSrcs, options.javacOptions.toArray[String], output, callback, reporter, log, progress) @@ -81,7 +81,7 @@ final class MixedAnalyzingCompiler( val scalaMsg = Analysis.counted("Scala source", "", "s", scalaCount) val javaMsg = Analysis.counted("Java source", "", "s", javaCount) val combined = scalaMsg ++ javaMsg - if (!combined.isEmpty) + if (combined.nonEmpty) log.info(combined.mkString("Compiling ", " and ", " to " + outputDirs.map(_.getAbsolutePath).mkString(",") + "...")) } @@ -187,7 +187,7 @@ object MixedAnalyzingCompiler { def withBootclasspath(args: CompilerArguments, classpath: Seq[File]): Seq[File] = args.bootClasspathFor(classpath) ++ args.extClasspath ++ args.finishClasspath(classpath) private[this] def explicitBootClasspath(options: Seq[String]): Seq[File] = - options.dropWhile(_ != CompilerArguments.BootClasspathOption).drop(1).take(1).headOption.toList.flatMap(IO.parseClasspath) + options.dropWhile(_ != CompilerArguments.BootClasspathOption).slice(1, 2).headOption.toList.flatMap(IO.parseClasspath) private[this] val cache = new collection.mutable.HashMap[File, Reference[AnalysisStore]] private def staticCache(file: File, backing: => AnalysisStore): AnalysisStore = diff --git a/compile/integration/src/main/scala/sbt/compiler/javac/AnalyzingJavaCompiler.scala b/compile/integration/src/main/scala/sbt/compiler/javac/AnalyzingJavaCompiler.scala index d49bf9515..9bae1d5af 100644 --- a/compile/integration/src/main/scala/sbt/compiler/javac/AnalyzingJavaCompiler.scala +++ b/compile/integration/src/main/scala/sbt/compiler/javac/AnalyzingJavaCompiler.scala @@ -36,7 +36,7 @@ final class AnalyzingJavaCompiler private[sbt] ( * @param progressOpt An optional compilation progress reporter. Where we can report back what files we're currently compiling. */ def compile(sources: Seq[File], options: Seq[String], output: Output, callback: AnalysisCallback, reporter: Reporter, log: Logger, progressOpt: Option[CompileProgress]): Unit = { - if (!sources.isEmpty) { + if (sources.nonEmpty) { val absClasspath = classpath.map(_.getAbsoluteFile) @annotation.tailrec def ancestor(f1: File, f2: File): Boolean = if (f2 eq null) false else if (f1 == f2) true else ancestor(f1, f2.getParentFile) diff --git a/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala b/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala index 0338d2658..1c4eee353 100644 --- a/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala +++ b/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala @@ -62,8 +62,8 @@ class ScalaCompilerForUnitTesting(nameHashing: Boolean = false) { * file system-independent way of testing dependencies between source code "files". */ def extractDependenciesFromSrcs(srcs: List[Map[Symbol, String]]): ExtractedSourceDependencies = { - val rawGroupedSrcs = srcs.map(_.values.toList).toList - val symbols = srcs.map(_.keys).flatten + val rawGroupedSrcs = srcs.map(_.values.toList) + val symbols = srcs.flatMap(_.keys) val (tempSrcFiles, testCallback) = compileSrcs(rawGroupedSrcs) val fileToSymbol = (tempSrcFiles zip symbols).toMap diff --git a/compile/src/main/scala/sbt/compiler/javac/ProcessLoggerWriter.scala b/compile/src/main/scala/sbt/compiler/javac/ProcessLoggerWriter.scala index eb64bfdae..a399f755a 100644 --- a/compile/src/main/scala/sbt/compiler/javac/ProcessLoggerWriter.scala +++ b/compile/src/main/scala/sbt/compiler/javac/ProcessLoggerWriter.scala @@ -8,7 +8,7 @@ private class ProcessLoggerWriter(delegate: ProcessLogger, level: Level.Value, n override def close() = flush() override def flush(): Unit = synchronized { - if (buffer.length > 0) { + if (buffer.nonEmpty) { log(buffer.toString) buffer.clear() } diff --git a/ivy/src/main/scala/sbt/JsonUtil.scala b/ivy/src/main/scala/sbt/JsonUtil.scala index e3983e7b4..d4db781f7 100644 --- a/ivy/src/main/scala/sbt/JsonUtil.scala +++ b/ivy/src/main/scala/sbt/JsonUtil.scala @@ -50,9 +50,9 @@ private[sbt] object JsonUtil { (c.caller.organization != sbtOrgTemp) && (c.caller.organization != fakeCallerOrganization) } - val interProj = (callers filter { c => - (c.caller.organization == sbtOrgTemp) - }).headOption.toList + val interProj = (callers find { c => + c.caller.organization == sbtOrgTemp + }).toList interProj ::: nonArtificial.toList } diff --git a/ivy/src/main/scala/sbt/MakePom.scala b/ivy/src/main/scala/sbt/MakePom.scala index 530070dda..81121bf7f 100644 --- a/ivy/src/main/scala/sbt/MakePom.scala +++ b/ivy/src/main/scala/sbt/MakePom.scala @@ -248,7 +248,7 @@ class MakePom(val log: Logger) { val includeArtifacts = artifacts.filter(d => includeTypes(d.getType)) if (artifacts.isEmpty) { val configs = dependency.getModuleConfigurations - if (configs.filterNot(Set("sources", "docs")).nonEmpty) { + if (!configs.forall(Set("sources", "docs"))) { warnIntransitve() val (scope, optional) = getScopeAndOptional(dependency.getModuleConfigurations) makeDependencyElem(dependency, scope, optional, None, None, excludes) @@ -271,7 +271,7 @@ class MakePom(val log: Logger) { case Nil | "*" :: Nil => dependency.getModuleConfigurations case x => x.toArray } - if (configs.filterNot(Set("sources", "docs")).nonEmpty) { + if (!configs.forall(Set("sources", "docs"))) { val (scope, optional) = getScopeAndOptional(configs) val classifier = artifactClassifier(artifact) val baseType = artifactType(artifact) diff --git a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala index 07a157107..5052a46ef 100644 --- a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala +++ b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala @@ -430,7 +430,7 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine { cs match { case Nil => Nil case (k, Vector()) :: rest => resolveConflicts(rest) - case (k, Vector(oa)) :: rest if (oa.modules.size == 0) => resolveConflicts(rest) + case (k, Vector(oa)) :: rest if (oa.modules.isEmpty) => resolveConflicts(rest) case (k, Vector(oa)) :: rest if (oa.modules.size == 1 && !oa.modules.head.evicted) => log.debug(s":: no conflict $rootModuleConf: ${oa.organization}:${oa.name}") oa :: resolveConflicts(rest) diff --git a/main/actions/src/main/scala/sbt/TestResultLogger.scala b/main/actions/src/main/scala/sbt/TestResultLogger.scala index 0f2e01378..01d7317a1 100644 --- a/main/actions/src/main/scala/sbt/TestResultLogger.scala +++ b/main/actions/src/main/scala/sbt/TestResultLogger.scala @@ -112,7 +112,7 @@ object TestResultLogger { val printStandard_? : Output => Boolean = results => // Print the standard one-liner statistic if no framework summary is defined, or when > 1 framework is in used. - results.summaries.size > 1 || results.summaries.headOption.forall(_.summaryText.size == 0) + results.summaries.size > 1 || results.summaries.headOption.forall(_.summaryText.isEmpty) val printStandard = TestResultLogger((log, results, _) => { val (skippedCount, errorsCount, passedCount, failuresCount, ignoredCount, canceledCount, pendingCount) = diff --git a/main/actions/src/main/scala/sbt/Tests.scala b/main/actions/src/main/scala/sbt/Tests.scala index fb8b156e6..829b50c6d 100644 --- a/main/actions/src/main/scala/sbt/Tests.scala +++ b/main/actions/src/main/scala/sbt/Tests.scala @@ -142,9 +142,9 @@ object Tests { } } - if (excludeTestsSet.size > 0) + if (excludeTestsSet.nonEmpty) log.debug(excludeTestsSet.mkString("Excluding tests: \n\t", "\n\t", "")) - if (undefinedFrameworks.size > 0) + if (undefinedFrameworks.nonEmpty) log.warn("Arguments defined for test frameworks that are not present:\n\t" + undefinedFrameworks.mkString("\n\t")) def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.name) && testFilters.forall(filter => filter(test.name)) diff --git a/main/src/main/scala/sbt/Aggregation.scala b/main/src/main/scala/sbt/Aggregation.scala index 1a9cf039c..324b3c53b 100644 --- a/main/src/main/scala/sbt/Aggregation.scala +++ b/main/src/main/scala/sbt/Aggregation.scala @@ -138,8 +138,8 @@ final object Aggregation { // tasks, and input tasks in the same call. The code below allows settings and tasks to be mixed, but not input tasks. // One problem with input tasks in `all` is that many input tasks consume all input and would need syntactic delimiters. // Once that is addressed, the tasks constructed by the input tasks would need to be combined with the explicit tasks. - if (inputTasks.size > 0) { - if (other.size > 0) { + if (inputTasks.nonEmpty) { + if (other.nonEmpty) { val inputStrings = inputTasks.map(_.key).mkString("Input task(s):\n\t", "\n\t", "\n") val otherStrings = other.map(_.key).mkString("Task(s)/setting(s):\n\t", "\n\t", "\n") failure(s"Cannot mix input tasks with plain tasks/settings. $inputStrings $otherStrings") diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 33b2ef0c0..47567034d 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1181,7 +1181,7 @@ object Classpaths { (confs ++ confs.map(internalConfigurationMap.value) ++ (if (autoCompilerPlugins.value) CompilerPlugin :: Nil else Nil)).distinct }, ivyConfigurations ++= Configurations.auxiliary, - ivyConfigurations ++= { if (managedScalaInstance.value && !scalaHome.value.isDefined) Configurations.ScalaTool :: Nil else Nil }, + ivyConfigurations ++= { if (managedScalaInstance.value && scalaHome.value.isEmpty) Configurations.ScalaTool :: Nil else Nil }, moduleSettings <<= moduleSettings0, makePomConfiguration := new MakePomConfiguration(artifactPath in makePom value, projectInfo.value, None, pomExtra.value, pomPostProcess.value, pomIncludeRepository.value, pomAllRepositories.value), deliverLocalConfiguration := deliverConfig(crossTarget.value, status = if (isSnapshot.value) "integration" else "release", logging = ivyLoggingLevel.value), @@ -1239,7 +1239,7 @@ object Classpaths { ) val jvmBaseSettings: Seq[Setting[_]] = Seq( - libraryDependencies ++= autoLibraryDependency(autoScalaLibrary.value && !scalaHome.value.isDefined && managedScalaInstance.value, sbtPlugin.value, scalaOrganization.value, scalaVersion.value), + libraryDependencies ++= autoLibraryDependency(autoScalaLibrary.value && scalaHome.value.isEmpty && managedScalaInstance.value, sbtPlugin.value, scalaOrganization.value, scalaVersion.value), // Override the default to handle mixing in the sbtPlugin + scala dependencies. allDependencies := { val base = projectDependencies.value ++ libraryDependencies.value diff --git a/main/src/main/scala/sbt/EvaluateTask.scala b/main/src/main/scala/sbt/EvaluateTask.scala index 8ced3cd4b..0bb93ec29 100644 --- a/main/src/main/scala/sbt/EvaluateTask.scala +++ b/main/src/main/scala/sbt/EvaluateTask.scala @@ -415,7 +415,7 @@ object EvaluateTask { def liftAnonymous: Incomplete => Incomplete = { case i @ Incomplete(node, tpe, None, causes, None) => - causes.find(inc => !inc.node.isDefined && (inc.message.isDefined || inc.directCause.isDefined)) match { + causes.find(inc => inc.node.isEmpty && (inc.message.isDefined || inc.directCause.isDefined)) match { case Some(lift) => i.copy(directCause = lift.directCause, message = lift.message) case None => i } diff --git a/main/src/main/scala/sbt/SettingCompletions.scala b/main/src/main/scala/sbt/SettingCompletions.scala index 6b94c4c6b..44c706785 100644 --- a/main/src/main/scala/sbt/SettingCompletions.scala +++ b/main/src/main/scala/sbt/SettingCompletions.scala @@ -27,7 +27,7 @@ private[sbt] object SettingCompletions { { import extracted._ val r = relation(extracted.structure, true) - val allDefs = Def.flattenLocals(Def.compiled(extracted.structure.settings, true)(structure.delegates, structure.scopeLocal, implicitly[Show[ScopedKey[_]]])).map(_._1) + val allDefs = Def.flattenLocals(Def.compiled(extracted.structure.settings, true)(structure.delegates, structure.scopeLocal, implicitly[Show[ScopedKey[_]]])).keys val projectScope = Load.projectScope(currentRef) def resolve(s: Setting[_]): Seq[Setting[_]] = Load.transformSettings(projectScope, currentRef.build, rootProject, s :: Nil) def rescope[T](setting: Setting[T]): Seq[Setting[_]] = diff --git a/run/src/main/scala/sbt/TrapExit.scala b/run/src/main/scala/sbt/TrapExit.scala index 7c62d809e..a5f981896 100644 --- a/run/src/main/scala/sbt/TrapExit.scala +++ b/run/src/main/scala/sbt/TrapExit.scala @@ -478,7 +478,7 @@ private final class TrapExit(delegateManager: SecurityManager) extends SecurityM private def disposeAllFrames(log: Logger) { val allFrames = java.awt.Frame.getFrames - if (allFrames.length > 0) { + if (allFrames.nonEmpty) { log.debug(s"Disposing ${allFrames.length} top-level windows...") allFrames.foreach(_.dispose) // dispose all top-level windows, which will cause the AWT-EventQueue-* threads to exit val waitSeconds = 2 diff --git a/sbt/src/sbt-test/tests/it/changes/ClassFailModuleSuccess.scala b/sbt/src/sbt-test/tests/it/changes/ClassFailModuleSuccess.scala index 47d17d531..e9d477c5d 100644 --- a/sbt/src/sbt-test/tests/it/changes/ClassFailModuleSuccess.scala +++ b/sbt/src/sbt-test/tests/it/changes/ClassFailModuleSuccess.scala @@ -3,7 +3,7 @@ import org.specs2.mutable._ class B extends Specification { "'hello world' has 11 characters" in { - "hello world".size must be equalTo(122) + "hello world".length must be equalTo(122) } } diff --git a/scripted/base/src/main/scala/xsbt/test/FileCommands.scala b/scripted/base/src/main/scala/xsbt/test/FileCommands.scala index b06cbac2c..e3af22cce 100644 --- a/scripted/base/src/main/scala/xsbt/test/FileCommands.scala +++ b/scripted/base/src/main/scala/xsbt/test/FileCommands.scala @@ -60,12 +60,12 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler { } def exists(paths: List[String]) { val notPresent = fromStrings(paths).filter(!_.exists) - if (notPresent.length > 0) + if (notPresent.nonEmpty) scriptError("File(s) did not exist: " + notPresent.mkString("[ ", " , ", " ]")) } def absent(paths: List[String]) { val present = fromStrings(paths).filter(_.exists) - if (present.length > 0) + if (present.nonEmpty) scriptError("File(s) existed: " + present.mkString("[ ", " , ", " ]")) } def execute(command: List[String]): Unit = execute0(command.head, command.tail) diff --git a/tasks/standard/src/test/scala/TaskRunnerFork.scala b/tasks/standard/src/test/scala/TaskRunnerFork.scala index ba40e4c5c..45b661dc0 100644 --- a/tasks/standard/src/test/scala/TaskRunnerFork.scala +++ b/tasks/standard/src/test/scala/TaskRunnerFork.scala @@ -28,7 +28,7 @@ object TaskRunnerForkTest extends Properties("TaskRunner Fork") { } property("fork and reduce") = forAll(TaskListGen, MaxWorkersGen) { (m: List[Int], workers: Int) => m.nonEmpty ==> { - val expected = m.reduceLeft(_ + _) + val expected = m.sum checkResult(tryRun(m.tasks.reduced(_ + _), false, workers), expected) } } diff --git a/util/classfile/src/main/scala/sbt/classfile/ClassFile.scala b/util/classfile/src/main/scala/sbt/classfile/ClassFile.scala index d230dbfe9..3f1a0d915 100644 --- a/util/classfile/src/main/scala/sbt/classfile/ClassFile.scala +++ b/util/classfile/src/main/scala/sbt/classfile/ClassFile.scala @@ -56,10 +56,10 @@ private[sbt] final case class Constant(tag: Byte, nameIndex: Int, typeIndex: Int private[sbt] final case class FieldOrMethodInfo(accessFlags: Int, name: Option[String], descriptor: Option[String], attributes: IndexedSeq[AttributeInfo]) extends NotNull { def isStatic = (accessFlags & ACC_STATIC) == ACC_STATIC def isPublic = (accessFlags & ACC_PUBLIC) == ACC_PUBLIC - def isMain = isPublic && isStatic && descriptor.filter(_ == "([Ljava/lang/String;)V").isDefined + def isMain = isPublic && isStatic && descriptor.exists(_ == "([Ljava/lang/String;)V") } private[sbt] final case class AttributeInfo(name: Option[String], value: Array[Byte]) extends NotNull { - def isNamed(s: String) = name.filter(s == _).isDefined + def isNamed(s: String) = name.exists(s == _) def isSignature = isNamed("Signature") def isSourceFile = isNamed("SourceFile") } diff --git a/util/classpath/src/main/scala/sbt/ReflectUtilities.scala b/util/classpath/src/main/scala/sbt/ReflectUtilities.scala index 0781880f9..c60772ad4 100644 --- a/util/classpath/src/main/scala/sbt/ReflectUtilities.scala +++ b/util/classpath/src/main/scala/sbt/ReflectUtilities.scala @@ -40,7 +40,7 @@ object ReflectUtilities { var mappings = new immutable.TreeMap[String, T] val correspondingFields = fields(self.getClass) for (method <- self.getClass.getMethods) { - if (method.getParameterTypes.length == 0 && clazz.isAssignableFrom(method.getReturnType)) { + if (method.getParameterTypes.isEmpty && clazz.isAssignableFrom(method.getReturnType)) { for (field <- correspondingFields.get(method.getName) if field.getType == method.getReturnType) { val value = method.invoke(self).asInstanceOf[T] if (value == null) throw new UninitializedVal(method.getName, method.getDeclaringClass.getName) diff --git a/util/collection/src/main/scala/sbt/Settings.scala b/util/collection/src/main/scala/sbt/Settings.scala index 4266af1b6..0196b0a09 100644 --- a/util/collection/src/main/scala/sbt/Settings.scala +++ b/util/collection/src/main/scala/sbt/Settings.scala @@ -296,7 +296,7 @@ trait Init[Scope] { def definedAtString(settings: Seq[Setting[_]]): String = { val posDefined = settings.flatMap(_.positionString.toList) - if (posDefined.size > 0) { + if (posDefined.nonEmpty) { val header = if (posDefined.size == settings.size) "defined at:" else "some of the defining occurrences:" header + (posDefined.distinct mkString ("\n\t", "\n\t", "\n")) diff --git a/util/complete/src/main/scala/sbt/LineReader.scala b/util/complete/src/main/scala/sbt/LineReader.scala index 8f9fc219f..b85190f92 100644 --- a/util/complete/src/main/scala/sbt/LineReader.scala +++ b/util/complete/src/main/scala/sbt/LineReader.scala @@ -45,7 +45,7 @@ abstract class JLine extends LineReader { private[this] def handleMultilinePrompt(prompt: String): String = { val lines = """\r?\n""".r.split(prompt) - lines.size match { + lines.length match { case 0 | 1 => prompt case _ => reader.print(lines.init.mkString("\n") + "\n"); lines.last; } diff --git a/util/log/src/main/scala/sbt/LoggerWriter.scala b/util/log/src/main/scala/sbt/LoggerWriter.scala index 0165676f5..bc6062563 100644 --- a/util/log/src/main/scala/sbt/LoggerWriter.scala +++ b/util/log/src/main/scala/sbt/LoggerWriter.scala @@ -17,7 +17,7 @@ class LoggerWriter(delegate: Logger, unbufferedLevel: Option[Level.Value], nl: S override def close() = flush() override def flush(): Unit = synchronized { - if (buffer.length > 0) { + if (buffer.nonEmpty) { log(buffer.toString) buffer.clear() } diff --git a/util/relation/src/main/scala/sbt/Relation.scala b/util/relation/src/main/scala/sbt/Relation.scala index 987aafb14..9a648ad64 100644 --- a/util/relation/src/main/scala/sbt/Relation.scala +++ b/util/relation/src/main/scala/sbt/Relation.scala @@ -123,7 +123,7 @@ private final class MRelation[A, B](fwd: Map[A, Set[B]], rev: Map[B, Set[A]]) ex def _1s = fwd.keySet def _2s = rev.keySet - def size = (fwd.valuesIterator map { _.size }).foldLeft(0)(_ + _) + def size = (fwd.valuesIterator map (_.size)).sum def all: Traversable[(A, B)] = fwd.iterator.flatMap { case (a, bs) => bs.iterator.map(b => (a, b)) }.toTraversable From f0bd9001e6b35d92591f7a2b1c2dc4d7dcebb43f Mon Sep 17 00:00:00 2001 From: Pierre DAL-PRA Date: Sat, 1 Aug 2015 12:05:35 +0200 Subject: [PATCH 2/2] Remove redundant collection conversions --- compile/inc/src/main/scala/sbt/inc/Compile.scala | 2 +- .../src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala | 4 ++-- ivy/src/main/scala/sbt/IvyRetrieve.scala | 8 ++++---- .../scala/sbt/ivyint/CachedResolutionResolveEngine.scala | 4 ++-- ivy/src/main/scala/sbt/ivyint/MergeDescriptors.scala | 2 +- main/actions/src/main/scala/sbt/Package.scala | 2 +- main/src/main/scala/sbt/Defaults.scala | 4 ++-- main/src/main/scala/sbt/Load.scala | 6 +++--- main/src/main/scala/sbt/Project.scala | 2 +- scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala | 2 +- util/collection/src/main/scala/sbt/PMap.scala | 2 +- util/collection/src/main/scala/sbt/Settings.scala | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compile/inc/src/main/scala/sbt/inc/Compile.scala b/compile/inc/src/main/scala/sbt/inc/Compile.scala index 6d6b616c3..a7ccb3dd2 100644 --- a/compile/inc/src/main/scala/sbt/inc/Compile.scala +++ b/compile/inc/src/main/scala/sbt/inc/Compile.scala @@ -84,7 +84,7 @@ private final class AnalysisCallback(internalMap: File => Option[File], external val outputSettings = output match { case single: SingleOutput => Array(new OutputSetting("/", single.outputDirectory.getAbsolutePath)) case multi: MultipleOutput => - multi.outputGroups.map(out => new OutputSetting(out.sourceDirectory.getAbsolutePath, out.outputDirectory.getAbsolutePath)).toArray + multi.outputGroups.map(out => new OutputSetting(out.sourceDirectory.getAbsolutePath, out.outputDirectory.getAbsolutePath)) } new Compilation(System.currentTimeMillis, outputSettings) } diff --git a/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala b/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala index 1c4eee353..019590dfc 100644 --- a/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala +++ b/compile/interface/src/test/scala/xsbt/ScalaCompilerForUnitTesting.scala @@ -33,7 +33,7 @@ class ScalaCompilerForUnitTesting(nameHashing: Boolean = false) { def extractUsedNamesFromSrc(src: String): Set[String] = { val (Seq(tempSrcFile), analysisCallback) = compileSrcs(src) - analysisCallback.usedNames(tempSrcFile).toSet + analysisCallback.usedNames(tempSrcFile) } /** @@ -46,7 +46,7 @@ class ScalaCompilerForUnitTesting(nameHashing: Boolean = false) { def extractUsedNamesFromSrc(definitionSrc: String, actualSrc: String): Set[String] = { // we drop temp src file corresponding to the definition src file val (Seq(_, tempSrcFile), analysisCallback) = compileSrcs(definitionSrc, actualSrc) - analysisCallback.usedNames(tempSrcFile).toSet + analysisCallback.usedNames(tempSrcFile) } /** diff --git a/ivy/src/main/scala/sbt/IvyRetrieve.scala b/ivy/src/main/scala/sbt/IvyRetrieve.scala index f453efb1f..14ad917fa 100644 --- a/ivy/src/main/scala/sbt/IvyRetrieve.scala +++ b/ivy/src/main/scala/sbt/IvyRetrieve.scala @@ -74,7 +74,7 @@ object IvyRetrieve { }: _*) def toCaller(caller: IvyCaller): Caller = { val m = toModuleID(caller.getModuleRevisionId) - val callerConfigurations = caller.getCallerConfigurations.toArray.toVector collect { + val callerConfigurations = caller.getCallerConfigurations.toVector collect { case x if nonEmptyString(x).isDefined => x } val ddOpt = Option(caller.getDependencyDescriptor) @@ -128,16 +128,16 @@ object IvyRetrieve { case _ => dep.getResolvedId.getExtraAttributes }) val isDefault = Option(dep.getDescriptor) map { _.isDefault } - val configurations = dep.getConfigurations(confReport.getConfiguration).toArray.toList + val configurations = dep.getConfigurations(confReport.getConfiguration).toList val licenses: Seq[(String, Option[String])] = mdOpt match { - case Some(md) => md.getLicenses.toArray.toVector collect { + case Some(md) => md.getLicenses.toVector collect { case lic: IvyLicense if Option(lic.getName).isDefined => val temporaryURL = "http://localhost" (lic.getName, nonEmptyString(lic.getUrl) orElse { Some(temporaryURL) }) } case _ => Nil } - val callers = dep.getCallers(confReport.getConfiguration).toArray.toVector map { toCaller } + val callers = dep.getCallers(confReport.getConfiguration).toVector map { toCaller } val (resolved, missing) = artifacts(moduleId, confReport getDownloadReports revId) new ModuleReport(moduleId, resolved, missing, status, publicationDate, resolver, artifactResolver, diff --git a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala index 5052a46ef..049130132 100644 --- a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala +++ b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala @@ -57,7 +57,7 @@ private[sbt] class CachedResolutionResolveCache() { { log.debug(s":: building artificial module descriptors from ${md0.getModuleRevisionId}") // val expanded = expandInternalDependencies(md0, data, prOpt, log) - val rootModuleConfigs = md0.getConfigurations.toArray.toVector + val rootModuleConfigs = md0.getConfigurations.toVector directDependencies(md0) map { dd => val arts = dd.getAllDependencyArtifacts.toVector map { x => s"""${x.getName}:${x.getType}:${x.getExt}:${x.getExtraAttributes}""" } log.debug(s"::: dd: $dd (artifacts: ${arts.mkString(",")})") @@ -599,7 +599,7 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine { case None => Vector() } // These are the configurations from the original project we want to resolve. - val rootModuleConfs = md0.getConfigurations.toArray.toVector + val rootModuleConfs = md0.getConfigurations.toVector val configurations0 = ur.configurations.toVector // This is how md looks from md0 via dd's mapping. val remappedConfigs0: Map[String, Vector[String]] = Map(rootModuleConfs map { conf0 => diff --git a/ivy/src/main/scala/sbt/ivyint/MergeDescriptors.scala b/ivy/src/main/scala/sbt/ivyint/MergeDescriptors.scala index 4e2cb1fc2..76bb4d2af 100644 --- a/ivy/src/main/scala/sbt/ivyint/MergeDescriptors.scala +++ b/ivy/src/main/scala/sbt/ivyint/MergeDescriptors.scala @@ -109,7 +109,7 @@ private final class MergedDescriptors(a: DependencyDescriptor, b: DependencyDesc private[this] def addConfigurations(dd: DefaultDependencyArtifactDescriptor, confs: Seq[String]): Unit = confs foreach dd.addConfiguration - private[this] def concat[T: reflect.ClassTag](a: Array[T], b: Array[T]): Array[T] = (a ++ b).distinct.toArray + private[this] def concat[T: reflect.ClassTag](a: Array[T], b: Array[T]): Array[T] = (a ++ b).distinct def getAllExcludeRules = concat(a.getAllExcludeRules, b.getAllExcludeRules) diff --git a/main/actions/src/main/scala/sbt/Package.scala b/main/actions/src/main/scala/sbt/Package.scala index 67a32fc82..df9af955d 100644 --- a/main/actions/src/main/scala/sbt/Package.scala +++ b/main/actions/src/main/scala/sbt/Package.scala @@ -68,7 +68,7 @@ object Package { } val map = conf.sources.toMap - val inputs = map :+: lastModified(map.keySet.toSet) :+: manifest :+: HNil + val inputs = map :+: lastModified(map.keySet) :+: manifest :+: HNil cachedMakeJar(inputs)(() => exists(conf.jar)) } def setVersion(main: Attributes) { diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 47567034d..311d87a28 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -635,12 +635,12 @@ object Defaults extends BuildCommon { // drop base directories, since there are no valid mappings for these def sourceMappings = (unmanagedSources, unmanagedSourceDirectories, baseDirectory) map { (srcs, sdirs, base) => - ((srcs --- sdirs --- base) pair (relativeTo(sdirs) | relativeTo(base) | flat)) toSeq + (srcs --- sdirs --- base) pair (relativeTo(sdirs) | relativeTo(base) | flat) } def resourceMappings = relativeMappings(unmanagedResources, unmanagedResourceDirectories) def relativeMappings(files: ScopedTaskable[Seq[File]], dirs: ScopedTaskable[Seq[File]]): Initialize[Task[Seq[(File, String)]]] = (files, dirs) map { (rs, rdirs) => - (rs --- rdirs) pair (relativeTo(rdirs) | flat) toSeq + (rs --- rdirs) pair (relativeTo(rdirs) | flat) } def collectFiles(dirs: ScopedTaskable[Seq[File]], filter: ScopedTaskable[FileFilter], excludes: ScopedTaskable[FileFilter]): Initialize[Task[Seq[File]]] = diff --git a/main/src/main/scala/sbt/Load.scala b/main/src/main/scala/sbt/Load.scala index 6c2d914c6..6d12523cd 100755 --- a/main/src/main/scala/sbt/Load.scala +++ b/main/src/main/scala/sbt/Load.scala @@ -174,7 +174,7 @@ object Load { val keys = Index.allKeys(settings) val attributeKeys = Index.attributeKeys(data) ++ keys.map(_.key) val scopedKeys = keys ++ data.allKeys((s, k) => ScopedKey(s, k)) - val projectsMap = projects.mapValues(_.defined.keySet).toMap + val projectsMap = projects.mapValues(_.defined.keySet) val keyIndex = KeyIndex(scopedKeys, projectsMap) val aggIndex = KeyIndex.aggregate(scopedKeys, extra(keyIndex), projectsMap) new sbt.StructureIndex(Index.stringToKeyMap(attributeKeys), Index.taskToKeyMap(data), Index.triggers(data), keyIndex, aggIndex) @@ -358,7 +358,7 @@ object Load { builds map { case (uri, unit) => (uri, unit.resolveRefs(ref => Scope.resolveProjectRef(uri, rootProject, ref))) - } toMap; + } } def checkAll(referenced: Map[URI, List[ProjectReference]], builds: Map[URI, sbt.PartBuildUnit]) { val rootProject = getRootProject(builds) @@ -396,7 +396,7 @@ object Load { { IO.assertAbsolute(uri) val resolve = (_: Project).resolve(ref => Scope.resolveProjectRef(uri, rootProject, ref)) - new sbt.LoadedBuildUnit(unit.unit, unit.defined mapValues resolve toMap, unit.rootProjects, unit.buildSettings) + new sbt.LoadedBuildUnit(unit.unit, unit.defined mapValues resolve, unit.rootProjects, unit.buildSettings) } def projects(unit: sbt.BuildUnit): Seq[Project] = { diff --git a/main/src/main/scala/sbt/Project.scala b/main/src/main/scala/sbt/Project.scala index c2d2bf39d..dba3c0f45 100755 --- a/main/src/main/scala/sbt/Project.scala +++ b/main/src/main/scala/sbt/Project.scala @@ -510,7 +510,7 @@ object Project extends ProjectExtra { val ProjectReturn = AttributeKey[List[File]]("project-return", "Maintains a stack of builds visited using reload.") def projectReturn(s: State): List[File] = getOrNil(s, ProjectReturn) - def inPluginProject(s: State): Boolean = projectReturn(s).toList.length > 1 + def inPluginProject(s: State): Boolean = projectReturn(s).length > 1 def setProjectReturn(s: State, pr: List[File]): State = s.copy(attributes = s.attributes.put(ProjectReturn, pr)) def loadAction(s: State, action: LoadAction.Value) = action match { case Return => diff --git a/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala b/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala index 4195846fd..5d7a776e7 100644 --- a/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala +++ b/scripted/plugin/src/main/scala/sbt/ScriptedPlugin.scala @@ -48,7 +48,7 @@ object ScriptedPlugin extends Plugin { val pairMap = pairs.groupBy(_._1).mapValues(_.map(_._2).toSet) val id = charClass(c => !c.isWhitespace && c != '/').+.string - val groupP = token(id.examples(pairMap.keySet.toSet)) <~ token('/') + val groupP = token(id.examples(pairMap.keySet)) <~ token('/') def nameP(group: String) = token("*".id | id.examples(pairMap(group))) val testID = for (group <- groupP; name <- nameP(group)) yield (group, name) (token(Space) ~> matched(testID)).* diff --git a/util/collection/src/main/scala/sbt/PMap.scala b/util/collection/src/main/scala/sbt/PMap.scala index 51c942112..cf0454fd9 100644 --- a/util/collection/src/main/scala/sbt/PMap.scala +++ b/util/collection/src/main/scala/sbt/PMap.scala @@ -52,7 +52,7 @@ object IMap { put(k, f(this get k getOrElse init)) def mapValues[V2[_]](f: V ~> V2) = - new IMap0[K, V2](backing.mapValues(x => f(x)).toMap) + new IMap0[K, V2](backing.mapValues(x => f(x))) def mapSeparate[VL[_], VR[_]](f: V ~> ({ type l[T] = Either[VL[T], VR[T]] })#l) = { diff --git a/util/collection/src/main/scala/sbt/Settings.scala b/util/collection/src/main/scala/sbt/Settings.scala index 0196b0a09..03173d6ce 100644 --- a/util/collection/src/main/scala/sbt/Settings.scala +++ b/util/collection/src/main/scala/sbt/Settings.scala @@ -17,9 +17,9 @@ sealed trait Settings[Scope] { } private final class Settings0[Scope](val data: Map[Scope, AttributeMap], val delegates: Scope => Seq[Scope]) extends Settings[Scope] { - def scopes: Set[Scope] = data.keySet.toSet + def scopes: Set[Scope] = data.keySet def keys(scope: Scope) = data(scope).keys.toSet - def allKeys[T](f: (Scope, AttributeKey[_]) => T): Seq[T] = data.flatMap { case (scope, map) => map.keys.map(k => f(scope, k)) } toSeq; + def allKeys[T](f: (Scope, AttributeKey[_]) => T): Seq[T] = data.flatMap { case (scope, map) => map.keys.map(k => f(scope, k)) } toSeq def get[T](scope: Scope, key: AttributeKey[T]): Option[T] = delegates(scope).toStream.flatMap(sc => getDirect(sc, key)).headOption