Repository navigation
Move methods between files and update their imports - #33
Merged
Merged
Conversation
The cross-file move condition is one bool per file, but the two directions need different import rules. A source file can lose the only use of an import when a declaration leaves it, while a target file can need an import that the moved declaration uses. Extract the file-level rule and give each direction its own predicate that still returns the current result. The next commits relax the two predicates separately. Change-Id: I44f874490aa5f7b37b69dcfd0765c85c95a02159
A target file with any import used to refuse the move, which excluded almost every real type definition file. A moved declaration only needs the imports it actually references, so compare those references with the names the target file already imports. A cgo target stays excluded because its preamble sits in the import block. The source file still has no imports, so this only lets a target file carry imports it already uses. Change-Id: I4a3325a9e633dfdd80b7d27da4354e274ea4de2d
A source file with any import used to refuse the move, even when the method leaves every import in use. Compare the imports with the uses that stay behind, and judge a file by all of the declarations that leave it at once, because no single method can orphan an import that another method still uses. The move still needs the target file to provide the imports, and a method that is the only use of an import keeps its diagnostic. Change-Id: Id44cdafcd6cd798a1124c09bcd2c2ae71f39a169
A moved method can need an import that its new file does not have. Add the import with the name that the method already uses, in the group that holds the imports it sorts among, so gofmt leaves the result alone. A file that already binds the name to another package keeps its diagnostic, and an import block with comments gets no new import because the comment would no longer sit beside the import it describes. Judge the source file before adding anything: a method that is the only use of an import still keeps its diagnostic, because removing imports is not part of this fix. Change-Id: I79b66d5e6fd565a36421e9f21e73f838e45cbf62
A method that was the only use of an import could not move, which left most real methods in place. Give the source file the edit that removes the import instead, so the move keeps both files compiling. Remove a whole import declaration when it loses every import, and one line otherwise, with the blank line that set the import apart from its group so that gofmt leaves the file alone. Skip an import block that holds comments, because a comment can describe the import that goes. A removal can still end a file, so the rule that keeps a blank line from ending a file now looks at every removal rather than only at removed methods. Change-Id: Ie2c72e33393da32335aa2ac46700c77482e40e9e
The README showed the checks but never the -fix option, so the rules that decide whether a method can move were only in the code. Record what a fix does, which imports it adds and removes, which cases it skips, and that it only writes files that Git can restore. Change-Id: I64853d59311a3b1a7512ac1702e2da6bc8057836
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.