Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move patch operations into RewriteCtx, fixes #193. #235

Merged
merged 3 commits into from
Jun 30, 2017

Conversation

olafurpg
Copy link
Contributor

This avoid the need for extension methods. The implementations of the
patch operations are now abstract to make it easier to read.

This avoid the need for extension methods. The implementations of the
patch operations are now abstract to make it easier to read.
@olafurpg olafurpg requested a review from gabro June 30, 2017 09:30
@olafurpg
Copy link
Contributor Author

Quite nice to see no changes were necessary on the rewrites. I was tempted to mix the operations into Rewrite but then I remembered that we may need the input/ctx in order to implement some particular patches. One idea that I have flirted with is to add extension methods on Tree/Token so it's possible to write

tree.replaceWith(newTree)

The RewriteCtx would need to be implicit in that case. However, I personally prefer the ctx.* approach since it makes it easy to discover what operations are available.

The distinction is no longer buying us anything now that semantic patch
ops take an implicit mirror as arguments.
@gabro
Copy link
Collaborator

gabro commented Jun 30, 2017

Nice! I'll review it soon, in the meantime the CI is failing because there's a faulty reference in the readme.

@olafurpg
Copy link
Contributor Author

I'm about to finish #192 soon, which follows up on this PR.

Copy link
Collaborator

@gabro gabro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

case class RewriteCtx(tree: Tree, config: ScalafixConfig) {
def syntax =
case class RewriteCtx(tree: Tree, config: ScalafixConfig) extends PatchOps {
ctx =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just an alias for this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I like the convention of calling it ctx. The ctx is not much used to implement the patches at the moment but I suspect that later we may need it to support configuration etc.

def addGlobalImport(importer: Importer): Patch = AddGlobalImport(importer)
// Semantic patch ops.
def removeGlobalImport(symbol: Symbol)(implicit mirror: Mirror): Patch
def addGlobalImport(importer: Importer)(implicit mirror: Mirror): Patch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a lot of sense 👍

@olafurpg olafurpg merged commit 9d35eb9 into scalacenter:master Jun 30, 2017
@olafurpg olafurpg deleted the 193 branch June 30, 2017 13:04
@olafurpg
Copy link
Contributor Author

Thank you for the review!

@olafurpg olafurpg modified the milestone: v0.5 Jun 30, 2017
bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants