Open AlexXuChen opened 3 years ago
I think we should take care of:
CompletionStage
(without package) and add the propert import import java.util.concurrent.CompletionStage;
For instance
import org.eclipse.microprofile.faulttolerance.Asynchronous;
...
public class Foo {
@Asynchronous
public String hello() {
return "abcd";
}
}
report an error on the String result type. The CodeAction java.util.concurrent.CompletionStage
should update the method like this:
import java.util.concurrent.CompletionStage;
import org.eclipse.microprofile.faulttolerance.Asynchronous;
...
public class Foo {
@Asynchronous
public Future<String> hello() {
return CompletableFuture.supplyAsync(() -> "abcd");
}
}
or simplier:
import java.util.concurrent.CompletionStage;
import org.eclipse.microprofile.faulttolerance.Asynchronous;
public class Foo {
@Asynchronous
public Future<String> hello() {
return CompletableFuture.completableFuture("abcd");
}
}
I don't know if it will be easy to implement this quick fix. @rgrunber what do you think?
I think the simpler option is safer because we wouldn't have to additionally check the project source compliance level (source >= 1.8). As for implementing this, it should all be possible with ASTRewrite. I've written code in the past that generated new method references, and the return type in the method declaration is also possible with JDT API.
Some references : https://www.vogella.com/tutorials/EclipseJDT/article.html#adding-a-hello-world-statement-using-the-ast https://www.vogella.com/tutorials/EclipseJDT/article.html#adding-imports-with-astrewrite
Given a diagnostic for a Quarkus project containing a method tagged with the
@Asynchronous
annotation(see #168), a CodeAction should be displayed for fixing the method return type, replacing it with one of:java.util.concurrent.Future
java.util.concurrent.CompletionStage
io.smallrye.mutiny.Uni