Skip to content

Commit

Permalink
refactor: add some missing types for implicits
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed May 13, 2024
1 parent 1742220 commit 167e256
Show file tree
Hide file tree
Showing 40 changed files with 186 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait DependencyBaseMatchers extends LayersAnalysis {

trait DependencyBeHaveMatchers extends BeHaveMatchers { outer: DependencyBaseMatchers =>

implicit def toLayersResultMatcher(result: MatchResult[Layers]) = new LayersResultMatcher(result)
implicit def toLayersResultMatcher(result: MatchResult[Layers]): DependencyBeHaveMatchers.this.LayersResultMatcher = new LayersResultMatcher(result)
class LayersResultMatcher(result: MatchResult[Layers]) {
def beRespected = result(outer.beRespected)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.specs2
package concurrent

import java.util.concurrent._
import scala.concurrent._

import org.specs2.control.Logger
import org.specs2.main.Arguments

import scala.concurrent.ExecutionContext

case class ExecutionEnv(executorServices: ExecutorServices,
timeFactor: Int,
Expand All @@ -18,9 +20,9 @@ case class ExecutionEnv(executorServices: ExecutorServices,
lazy val scheduledExecutorService = executorServices.scheduledExecutorService
lazy val scheduler = executorServices.scheduler

implicit lazy val es = executorService
implicit lazy val ses = scheduledExecutorService
implicit lazy val ec = executionContext
implicit lazy val es: ExecutorService = executorService
implicit lazy val ses: ScheduledExecutorService = scheduledExecutorService
implicit lazy val ec: ExecutionContext = executionContext

def setTimeFactor(tf: Int): ExecutionEnv =
copy(timeFactor = tf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object BiMap {
def k = key
}

implicit def fromSeq[K, V](s: Seq[BiMapEntry[K, V]]) = new BiMap[K, V] {
implicit def fromSeq[K, V](s: Seq[BiMapEntry[K, V]]): BiMap[K,V] = new BiMap[K, V] {
lazy val keys: Seq[K] = s.map(_.key)
lazy val values: Seq[V] = s.map(_.value)

Expand All @@ -45,4 +45,3 @@ trait SemiEntry[K] {
def k: K
def <->[V](v: V): BiMapEntry[K, V] = new BiMapEntry[K, V]() { val key = k; val value = v}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.specs2.fp._
object FutureInstances {

/** Applicative instance running futures in parallel for Scalaz */
implicit def parallelApplicative(implicit ec: ExecutionContext) = new Applicative[Future] {
implicit def parallelApplicative(implicit ec: ExecutionContext): Applicative[Future] = new Applicative[Future] {
def point[A](a: => A): Future[A] = Future(a)

def ap[A,B](ffa: => Future[A])(ff: => Future[A => B]): Future[B] =
Expand All @@ -18,4 +18,3 @@ object FutureInstances {
}

}

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.specs2
package control

import languageFeature._

/**
* implicits and postfix ops are automatically mixed in specs2 specifications
* for convenience. If you *really* don't want that you can override this behaviour by using the NoLanguageFeatures trait
*/
trait LanguageFeatures {
implicit lazy val implicitsAreAllowed = language.implicitConversions
implicit lazy val postfixOpsAreAllowed = language.postfixOps
implicit lazy val implicitsAreAllowed: implicitConversions = language.implicitConversions
implicit lazy val postfixOpsAreAllowed: postfixOps = language.postfixOps
}

trait NoLanguageFeatures extends LanguageFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Exceptions._

/**
* This class represents values which are evaluated lazily and which may even be missing.
*
*
* It has Option-like function and can be also converted to an Either object
*/
case class Property[T](value: () => Option[T], evaluated: Boolean = false, evaluatedValue: Option[T] = None) {
Expand Down Expand Up @@ -45,7 +45,7 @@ case class Property[T](value: () => Option[T], evaluated: Boolean = false, evalu
def toRight[L](left: L): Either[L, T] = optionalValue.toRight(left)
/** to a list */
def toList = optionalValue.toList

/** @return execute the property */
private def execute: Property[T] =
if (!evaluated) copy(value, evaluated = true, evaluatedValue = value())
Expand All @@ -69,7 +69,7 @@ object Property {
}

trait Properties {
implicit def aProperty[T](t: T) = Property(t)
implicit def aProperty[T](t: T): Property[T] = Property(t)
}

object Properties extends Properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait Throwablex {
/**
* Implicit method to add additional methods to Throwable objects
*/
implicit def extend[T <: Throwable](t: T) = new ExtendedThrowable(t)
implicit def extend[T <: Throwable](t: T): ExtendedThrowable[T] = new ExtendedThrowable(t)

/**
* See the ExtendedExceptions object description
Expand Down
3 changes: 1 addition & 2 deletions common/shared/src/main/scala/org/specs2/data/NamedTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ object NamedTag {
* define a very coarse Monoid for NamedTags where appending 2 NamedTags returns a Tag object
* with both list of tags
*/
implicit val NamedTagsAreMonoid = new Monoid[NamedTag] {
implicit val NamedTagsAreMonoid: org.specs2.fp.Monoid[NamedTag]{val zero: NamedTag} = new Monoid[NamedTag] {
val zero: NamedTag = AlwaysWhenNoIncludeTag
def append(t1: NamedTag, t2: =>NamedTag): NamedTag =
if (t1 == zero) t2
else if (t2 == zero) t1
else t1 overrideWith t2
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Snippet._
*/
trait Snippets {
/** implicit parameters selected for the creation of Snippets */
implicit def defaultSnippetParameters[T] = Snippet.defaultParams[T]
implicit def defaultSnippetParameters[T]: SnippetParams[T] = Snippet.defaultParams[T]

/** implicit function modify the Snippet parameters */
implicit class SettableSnippet[T](s: Snippet[T]) {
Expand Down Expand Up @@ -118,7 +118,7 @@ case class Snippet[T](code: () => T,
* - the `eval` boolean indicating if a snippet must be evaluated
* - the `verify` function checking the result
*/
case class SnippetParams[T](
case class SnippetParams[T](
trimExpression: String => String = trimApproximatedSnippet,
cutter: String => String = ScissorsCutter(),
asCode: (String, String) => String = markdownCode(offset = 0),
Expand Down Expand Up @@ -203,4 +203,3 @@ object Snippet {
lazy val ls = "[ \t\\x0B\f]"
lazy val parameters = "(\\([^\\)]+\\))*"
}

2 changes: 1 addition & 1 deletion common/shared/src/main/scala/org/specs2/text/Quote.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait Quote {
/** @return an object.toString() without quotes (used in messages creation) */
def unq(a: Any) = a.notNull

implicit def prefixed(s: String) = new Prefixed(s)
implicit def prefixed(s: String): Prefixed = new Prefixed(s)
class Prefixed(s: String) {
def prefix(separator: String, other: String) = Seq(s, other).filter(_.nonEmpty).mkString(separator)
}
Expand Down
2 changes: 1 addition & 1 deletion common/shared/src/main/scala/org/specs2/time/Timer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object SimpleTimer {
}

def timerFold[T] = new Fold[Id, T, SimpleTimer] {
implicit val monad = Monad.idMonad
implicit val monad: org.specs2.fp.Monad[org.specs2.fp.Id] = Monad.idMonad
type S = SimpleTimer
def start = (new SimpleTimer).start
def fold = (s, t) => s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ContextSpec extends script.Spec with ResultMatchers with Groups { def is =
the around method must rethrow failed results as exceptions ${g6().e4}
"""

implicit val arguments = main.Arguments()
implicit val arguments: main.Arguments = main.Arguments()

"before" - new g1 with FragmentsExecution {
e1 := executing(ex1Before).prints("before", "e1")
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/org/specs2/runner/SbtRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.specs2.data.NamedTag
import java.util.regex.Pattern

import scala.concurrent.duration.Duration
import scala.concurrent.{Future}
import scala.concurrent.{Future, ExecutionContext}

/**
* Runner for Sbt
Expand Down Expand Up @@ -130,7 +130,7 @@ case class SbtTask(aTaskDef: TaskDef, env: Env, loader: ClassLoader) extends sbt

private val arguments = env.arguments

private implicit lazy val ec = env.specs2ExecutionContext
private implicit lazy val ec: ExecutionContext = env.specs2ExecutionContext

/** @return the specification tags */
def tags(): Array[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import control.ImplicitParameters.ImplicitParam
*/
trait ExampleDsl extends FragmentsFactory { outer =>

implicit def bangExample(d: String) = new BangExample(d)
implicit def bangExample(d: String): BangExample = new BangExample(d)

class BangExample(d: String) {
def !(execution: Execution): Fragment = fragmentFactory.example(Text(d), execution)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import core.SpecHeader
*/
trait TitleDsl { outer =>

implicit def title(s: String) = new TitleOps(s)
implicit def title(s: String): TitleOps = new TitleOps(s)
class TitleOps(s: String) {
def title: SpecHeader = SpecHeader(outer.getClass, Some(s))
}
Expand All @@ -21,4 +21,3 @@ trait NoTitleDsl extends TitleDsl {
override def title(s: String) =
super.title(s)
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ExampleDsl1 extends BlockDsl with ExampleDsl0 {
// deactivate block0
override def blockExample0(d: String) = super.blockExample0(d)

implicit def blockExample(d: String) = new BlockExample(d)
implicit def blockExample(d: String): ExampleDsl1.this.BlockExample = new BlockExample(d)

class BlockExample(d: String) extends BlockExample0(d) {
def >>[R](f: String => R)(implicit asExecution: AsExecution[R]): Fragment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import specification.core.SpecHeader
* Dsl for creating a title in a mutable specification
*/
trait TitleDsl extends MutableHeaderBuilder with specification.dsl.TitleDsl {
override implicit def title(s: String) = new MutableTitleOps(s)
override implicit def title(s: String): MutableTitleOps = new MutableTitleOps(s)
class MutableTitleOps(s: String) extends TitleOps(s) {
override def title: SpecHeader = setTitle(s)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import specification.create.S2StringContext
* ForEachWithCommandLine trait, adapted for mutable specifications
*/
trait ForEachWithCommandLine[T] extends specification.ForEachWithCommandLineArguments[T] with ExampleDsl { outer: S2StringContext =>
override implicit def blockExample(d: String) = new BlockExample1(d)
override implicit def blockExample(d: String): BlockExample1 = new BlockExample1(d)

class BlockExample1(d: String) extends BlockExample(d) {
def >>[R : AsResult](f: T => R): Fragment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.specs2
package specification
package script

import scala.util.matching.Regex

import util.matching.Regex
import control.{ImplicitParameters, Use}
import control.Exceptions._
Expand All @@ -12,7 +14,7 @@ import text.RegexExtractor
* and possibly strip it from delimiters if necessary
*/
trait StepParsers extends ImplicitParameters {
implicit lazy val stepParserRegex = """\{([^}]+)\}""".r
implicit lazy val stepParserRegex: Regex = """\{([^}]+)\}""".r

def apply[T](f: String => T)(implicit fpr: Regex = stepParserRegex): DelimitedStepParser[T] = new DelimitedStepParser1[T](f).withRegex(fpr)
def apply[T](f: (String, String) => T)(implicit fpr: Regex): DelimitedStepParser[T] = new DelimitedStepParser2[T](f).withRegex(fpr)
Expand Down Expand Up @@ -139,5 +141,3 @@ trait StandardRegexStepParsers {
def threeStrings = groupAs(string).and((s1:String, s2: String, s3: String) => (s1, s2, s3))
}
object StandardRegexStepParsers extends StandardRegexStepParsers


2 changes: 1 addition & 1 deletion core/shared/src/main/scala/specs2/run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ object run extends ClassRunner {

/** main method for the command line */
def main(args: Array[String]) =
run(args, exit = true)
this.run(args, exit = true)
}
4 changes: 2 additions & 2 deletions form/src/main/scala/org/specs2/form/DecoratedProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package form
*/
private[specs2]
trait DecoratedProperties {
implicit def toDecorated[T <: DecoratedProperty[T]](d: T) = new Decorated(d)
implicit def toDecorated[T <: DecoratedProperty[T]](d: T): Decorated[T] = new Decorated(d)
class Decorated[T <: DecoratedProperty[T]](d: T) {

def code = d.decoratorIs(d.decorator.code)
Expand Down Expand Up @@ -87,4 +87,4 @@ trait DecoratedProperties {
}
}
private[specs2]
object DecoratedProperties extends DecoratedProperties
object DecoratedProperties extends DecoratedProperties
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ class Parser extends StdTokenParsers with ImplicitConversions {
def jsonObj = "{" ~> repsep(objEntry, ",") <~ "}" ^^ { case vals : List[_] => JSONObject(Map(vals : _*)) }
def jsonArray = "[" ~> repsep(value, ",") <~ "]" ^^ { case vals : List[_] => JSONArray(vals) }
def objEntry = stringVal ~ (":" ~> value) ^^ { case x ~ y => (x, y) }
def value: Parser[Any] = (jsonObj | jsonArray | number | "true" ^^^ true | "false" ^^^ false | "null" ^^^ null | stringVal)
def value: this.Parser[Any] = (jsonObj | jsonArray | number | "true" ^^^ true | "false" ^^^ false | "null" ^^^ null | stringVal)
def stringVal = accept("string", { case lexical.StringLit(n) => n} )
def number = accept("number", { case lexical.NumericLit(n) => numberParser.get.apply(n)} )
}

private[specs2]
class Lexer extends StdLexical with ImplicitConversions {

override def token: Parser[Token] =
override def token: this.Parser[Token] =
//( '\"' ~ rep(charSeq | letter) ~ '\"' ^^ lift(StringLit)
( string ^^ StringLit
| number ~ letter ^^ { case n ~ l => ErrorToken("Invalid number format : " + n + l) }
Expand Down Expand Up @@ -185,12 +185,12 @@ class Lexer extends StdLexical with ImplicitConversions {
case None => ""
}

def zero: Parser[String] = '0' ^^^ "0"
def zero: this.Parser[String] = '0' ^^^ "0"
def nonzero = elem("nonzero digit", d => d.isDigit && d != '0')
def exponent = elem("exponent character", d => d == 'e' || d == 'E')
def sign = elem("sign character", d => d == '-' || d == '+')

def charSeq: Parser[String] =
def charSeq: this.Parser[String] =
('\\' ~ '\"' ^^^ "\""
|'\\' ~ '\\' ^^^ "\\"
|'\\' ~ '/' ^^^ "/"
Expand Down
Loading

0 comments on commit 167e256

Please sign in to comment.