rewrite
rewrite copied to clipboard
Extend error message "Call reset() on JavaParser before parsing another..."
What problem are you trying to solve?
I was writing a test and encountered an error message that I did not expect:
Error: Call reset() on JavaParser before parsing another set of source files that have some of the same fully qualified names. Source file [A.java]
At first I thought it had to do with the complexity of the generics, but it turned out I was just doing something wrong:
void formatBraces() {
rewriteRun(
//language=java
java("""
import java.util.Collection;
class A<T extends Collection<U>, U>{
}
"""),
//language=java
java("""
import java.util.Collection;
class A<T extends Collection<U>, U> {
}
""")
);
}
should have been ( only 1 java(..)
not 2)
void formatBraces() {
rewriteRun(
//language=java
java("""
import java.util.Collection;
class A<T extends Collection<U>, U>{
}
""","""
import java.util.Collection;
class A<T extends Collection<U>, U> {
}
""")
);
}
This was a result of a copy past mistake.
Describe the solution you'd like
The error message is already hinting at one likely case what is going wrong. Perhaps we can add this test case to the error message.
Have you considered any alternatives or workarounds?
Not making this mistake would be the best workaround
Additional context
When talking to @timtebeek about this issue spotted my mistake an mentioned he had done this before too.
Are you interested in [contributing this feature to OpenRewrite]
I would love to make the PR if this idea is accepted.
Still up for debate whether we extend the message, but I expect the addition to be something along these lines:
Are you passing two before SourceSpecs into a rewiteRun test where you intended one SourceSpec with before and after?