-
Notifications
You must be signed in to change notification settings - Fork 77
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
Apache Commons File Utils Migrations #274
Conversation
|
||
@AfterTemplate | ||
void after(File file, CharSequence data, Charset cs) throws Exception { | ||
Files.write(file.toPath(), Arrays.asList(data), cs); |
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.
@knutwannheden (no rush! just interesting)
This fails compile in the generated recipe due to
java: reference to compile is ambiguous
both method compile(org.openrewrite.java.JavaVisitor<?>,java.lang.String,org.openrewrite.java.JavaTemplate.P3<?,?,?>) in org.openrewrite.java.JavaTemplate
and method compile(org.openrewrite.java.JavaVisitor<?>,java.lang.String,org.openrewrite.java.JavaTemplate.F3<?,?,?,?>) in org.openrewrite.java.JavaTemplate match
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.
Any idea what might be going on here? The generated code is:
final JavaTemplate before = JavaTemplate.compile(this, "before", (java.io.File file, CharSequence data, java.nio.charset.Charset cs) -> FileUtils.write(file, data, cs)).build();
final JavaTemplate after = JavaTemplate.compile(this, "after", (java.io.File file, CharSequence data, java.nio.charset.Charset cs) -> Files.write(file.toPath(), Arrays.asList(data), cs)).build();
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.
We can work around this with a simple cast of course. ;/
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.
Haven't looked at it yet. Possibly we need to generate an explicit cast, because the return type of the called method is not void like that of the template method.
src/test/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtilsTest.java
Show resolved
Hide resolved
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.
Let's only expand on the ubertest before we merge this first structure, and from there discuss what methods to pick up.
What's changed?
This PR adds two refaster templates to migrate
FileUtils
methods.What's your motivation?
Moving onto
FileUtils
after StringUtilsAnything in particular you'd like reviewers to focus on?
So currently it won't build because the
Write
template is a little off. I think the reason its failing with this one is thatFileUtils.write()
returns void while Java's write methodFiles.write()
returns a Path. I don't think there are any other one line method Java provides to write to a file. Will we just not be able to do migrations forFileUtils.write()
because of this?Anyone you would like to review specifically?
@timtebeek
Checklist
./gradlew licenseFormat