-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rudimentary ExplicitImplicit semantic rewrite.
- Use (super experimental) 2.0 version of scalameta - Use (super experimental) 4.0 version of scala.meta paradise - SBT plugin injects the 4.0 paradise compiler plugin and compiles with -Dpersist.enable - ExplicitImplicit inserts the fully qualified type name, no fancy imports yet - Everything is tested, including the SBT plugin interaction! - Fixed tiny bug in VolatileLazyVal because I couldn't help myself
- Loading branch information
Showing
28 changed files
with
375 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
assumeStandardLibraryStripMargin = true | ||
align.tokens = [ | ||
{ code = "%", owner = "Infix" } | ||
{ code = "%%", owner = "Infix" } | ||
{ code = "%%%", owner = "Infix" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
set -e | ||
|
||
echo "Running nailgun integration test..." | ||
ng ng-stop || true | ||
|
||
cwd=$(pwd) | ||
cd cli/target/pack | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package scala.meta | ||
|
||
object Mirror { | ||
def apply(artifacts: Artifact*)(implicit resolver: Resolver): Mirror = { | ||
new Mirror { | ||
lazy val domain = Domain(artifacts: _*)(resolver) | ||
override def toString = | ||
s"""Context(${artifacts.mkString(", ")})($resolver)""" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package scalafix | ||
|
||
object Versions { | ||
val nightly = "0.1.0" | ||
val nightly = "0.1.0-SNAPSHOT" | ||
val stable = nightly | ||
val scala = "2.11.8" | ||
val paradiseVersion = "4.0.0-M3" | ||
val paradiseOrg = "com.geirsson" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package scalafix.config | ||
|
||
import java.io.File | ||
|
||
case class ProjectFiles( | ||
targetFiles: Seq[File] = Nil, | ||
files: Seq[File] = Nil | ||
) |
7 changes: 5 additions & 2 deletions
7
.../main/scala/scalafix/ScalafixConfig.scala → ...cala/scalafix/config/ScalafixConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package scalafix | ||
package scalafix.config | ||
|
||
import scala.meta.Dialect | ||
import scala.meta.Tree | ||
import scala.meta.dialects.Scala211 | ||
import scala.meta.parsers.Parse | ||
import scalafix.rewrite.Rewrite | ||
|
||
import java.io.File | ||
|
||
case class ScalafixConfig( | ||
rewrites: Seq[Rewrite] = Rewrite.default, | ||
parser: Parse[_ <: Tree] = Parse.parseSource, | ||
dialect: Dialect = Scala211 | ||
dialect: Dialect = Scala211, | ||
project: ProjectFiles = ProjectFiles() | ||
) |
29 changes: 29 additions & 0 deletions
29
core/src/main/scala/scalafix/rewrite/ExplicitImplicit.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package scalafix.rewrite | ||
|
||
import scala.meta._ | ||
import scala.meta.internal.prettyprinters.Attributes | ||
import scala.meta.tokens.Token.Comment | ||
import scala.meta.tokens.Token.LeftBrace | ||
import scala.meta.tokens.Token.RightBrace | ||
import scala.meta.tokens.Token.RightParen | ||
import scala.meta.tokens.Token.Space | ||
import scalafix.util.Patch | ||
import scalafix.util.SemanticOracle | ||
import scalafix.util.logger | ||
|
||
case object ExplicitImplicit extends Rewrite { | ||
|
||
override def rewrite(ast: Tree, ctx: RewriteCtx): Seq[Patch] = { | ||
val builder = Seq.newBuilder[Patch] | ||
val oracle = new SemanticOracle(ctx.mirror.get) | ||
ast.collect { | ||
case Defn.Val(mods, Seq(Pat.Var.Term(t: Term.Name)), decltpe, _) | ||
if decltpe.isEmpty && mods.exists(_.syntax == "implicit") => | ||
oracle.getType(t).foreach { typ => | ||
val toks = t.tokens | ||
builder += Patch(toks.head, toks.last, s"${t.syntax}: $typ") | ||
} | ||
} | ||
builder.result() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
package scalafix.rewrite | ||
|
||
import scalafix.ScalafixConfig | ||
import scala.meta.Tree | ||
import scala.meta.inputs.Input | ||
import scala.meta.semantic.Mirror | ||
import scalafix.config.ScalafixConfig | ||
import scalafix.util.TokenList | ||
|
||
case class RewriteInput( | ||
input: Input, | ||
ast: Tree | ||
) | ||
|
||
case class RewriteCtx( | ||
config: ScalafixConfig, | ||
tokenList: TokenList | ||
tokenList: TokenList, | ||
mirror: Option[Mirror] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.