Skip to content

Commit

Permalink
Properly add @CheckReturnValue
Browse files Browse the repository at this point in the history
* We don't add it if it's already there
* We don't run the transformation twice

Fixes: quarkusio#35715
  • Loading branch information
geoand committed Sep 20, 2023
1 parent c19faac commit e9194a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
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

0 comments on commit e9194a5

Please sign in to comment.