-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from olafurpg/intellij-buidl
Simplifify api for import patches
- Loading branch information
Showing
11 changed files
with
85 additions
and
31 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
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,11 +1,29 @@ | ||
package scalafix.rewrite | ||
import scala.meta.Tree | ||
import scala.meta.tokens.Tokens | ||
import scalafix.ScalafixConfig | ||
import scalafix.util.AssociatedComments | ||
import scalafix.util.TokenList | ||
|
||
case class RewriteCtx( | ||
config: ScalafixConfig, | ||
tokens: Tokens, | ||
tokenList: TokenList, | ||
comments: AssociatedComments, | ||
semantic: Option[SemanticApi] | ||
) | ||
|
||
object RewriteCtx { | ||
def fromCode(ast: Tree, | ||
config: ScalafixConfig = ScalafixConfig(), | ||
semanticApi: Option[SemanticApi] = None): RewriteCtx = { | ||
val tokens = ast.tokens(config.dialect) | ||
RewriteCtx( | ||
config, | ||
tokens, | ||
new TokenList(tokens), | ||
AssociatedComments(tokens), | ||
semanticApi | ||
) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -85,3 +85,4 @@ object logger { | |
s"$line\n=> $t\n$line" | ||
} | ||
} | ||
|
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,23 @@ | ||
// Small worksheet to demonstrate usage of import patches | ||
import scala.collection.immutable.Seq | ||
import scala.meta._ | ||
import scalafix.rewrite.RewriteCtx | ||
import scalafix.util.Patch | ||
import scalafix.util.TreePatch.AddGlobalImport | ||
import scalafix.util.TreePatch.RemoveGlobalImport | ||
import scala.meta._ | ||
import scalafix.util.logger | ||
val code = | ||
"""import scala.language.higherKinds | ||
|import java.{util => ju} | ||
|import scala.collection.mutable._ | ||
| | ||
|object a | ||
""".stripMargin.parse[Source].get | ||
implicit val ctx: RewriteCtx = RewriteCtx.fromCode(code) | ||
val add = AddGlobalImport(importer"cats.data.EitherT") | ||
val addRedundant = AddGlobalImport(importer"scala.collection.mutable._") | ||
val remove = RemoveGlobalImport(importer"scala.language.higherKinds") | ||
|
||
val x = Patch.apply(code, Seq(add, addRedundant, remove)) | ||
logger.elem(x) |
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