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

Properly add @CheckReturnValue #36038

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
Expand All @@ -41,18 +38,12 @@
import io.quarkus.panache.common.deployment.PanacheMethodCustomizerBuildItem;
import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;
import io.quarkus.panache.common.deployment.TypeBundle;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public class HibernateReactivePanacheKotlinProcessor {

private static final String META_INF_PANACHE_ARCHIVE_MARKER = "META-INF/panache-archive.marker";
private static final DotName DOTNAME_REACTIVE_SESSION = DotName.createSimple(Mutiny.Session.class.getName());
private static final DotName DOTNAME_ID = DotName.createSimple(Id.class.getName());
private static final DotName DOTNAME_UNI = DotName.createSimple(Uni.class.getName());
private static final DotName DOTNAME_MULTI = DotName.createSimple(Multi.class.getName());
private static final String CHECK_RETURN_VALUE_BINARY_NAME = "io/smallrye/common/annotation/CheckReturnValue";
private static final String CHECK_RETURN_VALUE_SIGNATURE = "L" + CHECK_RETURN_VALUE_BINARY_NAME + ";";
private static final TypeBundle TYPE_BUNDLE = ReactiveKotlinJpaTypeBundle.BUNDLE;

@BuildStep
Expand Down Expand Up @@ -171,17 +162,4 @@ public ValidationPhaseBuildItem.ValidationErrorBuildItem validate(ValidationPhas
}
return null;
}

@BuildStep
PanacheMethodCustomizerBuildItem mutinyReturnTypes() {
return new PanacheMethodCustomizerBuildItem(new PanacheMethodCustomizer() {
@Override
public void customize(Type entityClassSignature, MethodInfo method, MethodVisitor mv) {
DotName returnType = method.returnType().name();
if (returnType.equals(DOTNAME_UNI) || returnType.equals(DOTNAME_MULTI)) {
mv.visitAnnotation(CHECK_RETURN_VALUE_SIGNATURE, true);
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.quarkus.panache.common.deployment.PanacheJpaEntityOperationsEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizerBuildItem;
import io.smallrye.common.annotation.CheckReturnValue;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

Expand Down Expand Up @@ -145,7 +146,8 @@ ValidationPhaseBuildItem.ValidationErrorBuildItem validate(ValidationPhaseBuildI
return null;
}

private static final String CHECK_RETURN_VALUE_BINARY_NAME = "io/smallrye/common/annotation/CheckReturnValue";
private static final DotName DOTNAME_CHECK_RETURN_VALUE_CLASS = DotName.createSimple(CheckReturnValue.class);
private static final String CHECK_RETURN_VALUE_BINARY_NAME = CheckReturnValue.class.getName().replace('.', '/');
private static final String CHECK_RETURN_VALUE_SIGNATURE = "L" + CHECK_RETURN_VALUE_BINARY_NAME + ";";

@BuildStep
Expand All @@ -154,7 +156,8 @@ PanacheMethodCustomizerBuildItem mutinyReturnTypes() {
@Override
public void customize(Type entityClassSignature, MethodInfo method, MethodVisitor mv) {
DotName returnType = method.returnType().name();
if (returnType.equals(DOTNAME_UNI) || returnType.equals(DOTNAME_MULTI)) {
if ((returnType.equals(DOTNAME_UNI) || returnType.equals(DOTNAME_MULTI))
&& !method.hasDeclaredAnnotation(DOTNAME_CHECK_RETURN_VALUE_CLASS)) {
mv.visitAnnotation(CHECK_RETURN_VALUE_SIGNATURE, true);
}
}
Expand Down