-
Notifications
You must be signed in to change notification settings - Fork 460
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
Import Sorter to cope with multi-line comments and misplaced imports #112
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions
14
testlib/src/test/resources/java/importsorter/JavaCodeImportComments.test
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,14 @@ | ||
import static java.lang.Exception.*; | ||
//Will be removed | ||
import org.dooda.Didoo; /* Comment removed, import stays */ | ||
import java.lang.Thread; /* Don't */ /* get */ /* confused */ | ||
import java.lang.Runnable; | ||
/* import org.comments.will | ||
import org.comments.be | ||
import org.comments.removed | ||
*/ | ||
import static java.lang.Runnable.*; | ||
/* | ||
import other.multiline.comments | ||
import will.be.removed.too */ | ||
import static com.foo.Bar |
13 changes: 13 additions & 0 deletions
13
testlib/src/test/resources/java/importsorter/JavaCodeSortedMisplacedImports.test
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,13 @@ | ||
import java.lang.Runnable; | ||
import java.lang.Thread; | ||
|
||
import org.dooda.Didoo; | ||
|
||
import static java.lang.Exception.*; | ||
import static java.lang.Runnable.*; | ||
|
||
import static com.foo.Bar; | ||
public class NotDeletedByFormatter { | ||
} | ||
import will.not; | ||
import be.sorted; |
16 changes: 16 additions & 0 deletions
16
testlib/src/test/resources/java/importsorter/JavaCodeUnsortedMisplacedImports.test
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,16 @@ | ||
import static java.lang.Exception.*; | ||
import org.dooda.Didoo; | ||
/* | ||
public class IgnoredAndRemoved { | ||
} | ||
*/ | ||
import java.lang.Thread; | ||
// Will be removed {} | ||
import java.lang.Runnable; | ||
|
||
import static java.lang.Runnable.*; | ||
import static com.foo.Bar | ||
public class NotDeletedByFormatter { | ||
} | ||
import will.not; | ||
import be.sorted; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure that this
if..continue
block is needed.AFAICT,
!next.contains("/*")
can never be true at this point. I can explain my reasoning if you wish, but it's a bit long-winded, I've not tested it with JUnit or a debugger, and there's no harm to this block staying anyway AFAICT.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have this situation in the following case:
In the old code
what.so.ever
would have been part of the refactored imports, so it was originally commented out.If I refactor it to an inner class, it becomes easier to read. But at first I wanted to assure you, that I actually did not alter much in the initial logic of the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand what this sentence is saying. Can you rephrase it for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original behavior:
Results in
New behavior detects multi-line comments. So result is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just saw my mistake. I wanted to say:
In the old code
what.so.ever would
have been part of the refactored imports, though it was originally commented out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha I see now. Thanks for the clarifications @fvgh. :)