-
Notifications
You must be signed in to change notification settings - Fork 3k
Handle method parameter type annotations in ClassComparisonUtil #47932
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
Merged
gastaldi
merged 1 commit into
quarkusio:main
from
VoglSebastian:methodParameterTypeHandling
May 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
core/deployment/src/test/java/io/quarkus/deployment/dev/ClassComparisonUtilTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.quarkus.deployment.dev; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.MethodParameterInfo; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ClassComparisonUtilTest { | ||
|
||
@Nested | ||
class CompareMethodAnnotations { | ||
|
||
@Test | ||
public void annotationsEqual() { | ||
AnnotationInstance instance1 = methodParameterAnnotation(AnnotationForTest1.class); | ||
AnnotationInstance instance2 = methodParameterAnnotation(AnnotationForTest1.class); | ||
|
||
List<AnnotationInstance> instances1 = List.of(instance1); | ||
List<AnnotationInstance> instances2 = List.of(instance2); | ||
|
||
Assertions.assertTrue(ClassComparisonUtil.compareMethodAnnotations(instances1, instances2)); | ||
} | ||
|
||
@Test | ||
public void annotationsNotEqual() { | ||
AnnotationInstance instance1 = methodParameterAnnotation(AnnotationForTest1.class); | ||
AnnotationInstance instance2 = methodParameterAnnotation(AnnotationForTest2.class); | ||
|
||
List<AnnotationInstance> instances1 = List.of(instance1); | ||
List<AnnotationInstance> instances2 = List.of(instance2); | ||
|
||
Assertions.assertFalse(ClassComparisonUtil.compareMethodAnnotations(instances1, instances2)); | ||
} | ||
|
||
@Test | ||
public void compareMethodAnnotationsSizeDiffer() { | ||
AnnotationInstance instance = methodParameterAnnotation(AnnotationForTest1.class); | ||
|
||
List<AnnotationInstance> instances = List.of(instance); | ||
|
||
Assertions.assertFalse(ClassComparisonUtil.compareMethodAnnotations(instances, List.of())); | ||
Assertions.assertFalse(ClassComparisonUtil.compareMethodAnnotations(List.of(), instances)); | ||
} | ||
|
||
@Test | ||
public void multipleAnnotationsAtSamePosition() { | ||
List<AnnotationInstance> instances1 = List.of( | ||
methodParameterAnnotation(AnnotationForTest1.class), | ||
methodParameterAnnotation(AnnotationForTest2.class)); | ||
List<AnnotationInstance> instances2 = List.of( | ||
methodParameterAnnotation(AnnotationForTest2.class), | ||
methodParameterAnnotation(AnnotationForTest1.class)); | ||
|
||
Assertions.assertTrue(ClassComparisonUtil.compareMethodAnnotations(instances1, instances2)); | ||
} | ||
|
||
@Test | ||
public void multipleAnnotations() { | ||
List<AnnotationInstance> instances1 = List.of( | ||
methodParameterAnnotation(AnnotationForTest1.class, 1), | ||
methodParameterAnnotation(AnnotationForTest2.class, 2)); | ||
|
||
List<AnnotationInstance> instances2 = List.of( | ||
methodParameterAnnotation(AnnotationForTest1.class, 2), | ||
methodParameterAnnotation(AnnotationForTest2.class, 1)); | ||
|
||
Assertions.assertFalse(ClassComparisonUtil.compareMethodAnnotations(instances1, instances2)); | ||
} | ||
|
||
private static AnnotationInstance methodParameterAnnotation( | ||
Class<? extends Annotation> annotation) { | ||
return methodParameterAnnotation(annotation, 1); | ||
} | ||
|
||
private static AnnotationInstance methodParameterAnnotation( | ||
Class<? extends Annotation> annotation, int position) { | ||
MethodParameterInfo target = MethodParameterInfo.create(null, (short) position); | ||
return AnnotationInstance.builder(annotation).buildWithTarget(target); | ||
} | ||
|
||
@Target({ ElementType.PARAMETER, ElementType.TYPE_USE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
private @interface AnnotationForTest1 { | ||
} | ||
|
||
@Target({ ElementType.PARAMETER, ElementType.TYPE_USE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
private @interface AnnotationForTest2 { | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm fairly sure at least
Usage.EMPTY
is quite realistic (type annotation on return type), and there's a few other kinds of usages that may legitimately occur. But I agree we can deal with those as they come.