Skip to content
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

Allow tests to be written with Java 17 or 21 for access to text blocks #73

Open
timtebeek opened this issue Feb 2, 2024 · 2 comments
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@timtebeek
Copy link
Contributor

What problem are you trying to solve?

Right now our tests use resource files for in and outputs, but these mean there's a disconnect between a test method and what it actually verifies.

Describe the solution you'd like

With text blocks and JavaFileObjects.forSourceString we can instead adopt a test style similar to what we use elsewhere in OpenRewrite. That should help familiarity, and seeing at a glance what a test verifies.

static Compilation compileSource(String fqn, @Language("java") String source, TypeAwareProcessor processor) {
    return compileResource(JavaFileObjects.forSourceString(fqn, source), processor);
}

Additional context

The compileSource method above as already been added in

@timtebeek timtebeek added the enhancement New feature or request label Feb 2, 2024
@timtebeek
Copy link
Contributor Author

My quick attempts so far have failed to produce a working setup with Gradle; something to do with toolchains that I think I'm close to, but some help would be appreciated to get this in.

@timtebeek timtebeek added the help wanted Extra attention is needed label Feb 5, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Feb 5, 2024
@timtebeek
Copy link
Contributor Author

Through #57 there's now already two methods that can take a String input.

@SuppressWarnings("unused") // use when text blocks are available
static Compilation compileSource(String fqn, @Language("java") String source) {
return compile(JavaFileObjects.forSourceString(fqn, source), new RefasterTemplateProcessor());
}
static Compilation compileSource(String fqn, @Language("java") String source, TypeAwareProcessor processor) {
return compile(JavaFileObjects.forSourceString(fqn, source), processor);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

1 participant