This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not depend on tree transformations for the add import refactoring
This is a similar change to the rename refactoring. The overall idea is to not depend on any tree transformations when an import is added to a file. Theoretically, doing any transformations on the tree is the optimal solution but only if the tree is a concrete syntax tree. The scalac trees however are abstract syntax trees and therefore don't do what we want. For the add import refactoring, they remove all the formatting of the imports, especially removed new lines are a concern. This commit therefore replaces the tree transformations by generating textual code changes. This way, the refactoring is only doing a minimal change, which in our case is to add one or multiple imports. A side effect is that some functionality is lost but I consider that as a good change. Formerly, the add import refactoring also did some minor cleanups to the regions around imports. It added newlines, which means that an import that got added to a code snippet like the following class A { val f = new File } did result in this: import java.io.File class A { val f = new File } Whereas after the refactorings of this commit the extra newline is no longer printed: import java.io.File class A { val f = new File } This may not look better but it makes the implementation easier because we don't have to check if a newline already exists. Also, conceptually it is the job of the organize imports refactoring to take care of such a cleanup. The add import refactoring should only do a minimal change and that is exactly what it is doing right now. Fix #1002514
- Loading branch information
Showing
5 changed files
with
146 additions
and
86 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
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.