-
Notifications
You must be signed in to change notification settings - Fork 359
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
fix: Dont generate the same file multiple times & fix CreateTextFile #4356
Conversation
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
@@ -86,7 +86,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor(AtomicBoolean created) { | |||
@Override | |||
public SourceFile visit(@Nullable Tree tree, ExecutionContext ctx) { | |||
SourceFile sourceFile = (SourceFile) requireNonNull(tree); | |||
if ((created.get() || Boolean.TRUE.equals(overwriteExisting)) && path.equals(sourceFile.getSourcePath())) { |
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.
Weird how we were overwriting the content again, even after already initializing with file contents.
for (SourceFile source : generated) { | ||
if (acc.stream().noneMatch(s -> s.getSourcePath().equals(source.getSourcePath()))) { | ||
acc.add(source); | ||
} | ||
} |
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.
Gave me a bit of pause to loop over all generated files in a list before adding a new entry, but I think it's tolerable given the expected low volume of generated files.
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.
Change the reduction operation to use a Set
generated from a TreeMap
whose comparator is the source path.
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 updated to using TreeSet
. This does mean that the insertion order is no longer guaranteed to be the resulting order, although I can imagine that the LST order is also similarly ordered anyway?
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
What's changed?
generate no longer creates files at the same path multiple times
What's your motivation?
Currently the same file can be created multiple times, causing instabilities in recipe execution. For instance
running
CreateTextFile
twice in the same run causes multiple cycles changing back and forth from 1 text to the other, even ifoverwriteExisting
is falseAnything in particular you'd like reviewers to focus on?
This is a change in the core recipe running and might have unwanted side-effects
Anyone you would like to review specifically?
@sambsnyd @timtebeek
Have you considered any alternatives or workarounds?
Fixing it on the recipe level alone, but this would require "rescanning" during the edit phase.
Checklist