2020import io .quarkus .arc .runtime .SuppressConditions ;
2121import io .quarkus .deployment .annotations .BuildProducer ;
2222import io .quarkus .deployment .annotations .BuildStep ;
23- import io .quarkus .gizmo .BytecodeCreator ;
24- import io .quarkus .gizmo .MethodDescriptor ;
25- import io .quarkus .gizmo .ResultHandle ;
23+ import io .quarkus .gizmo2 .Const ;
24+ import io .quarkus .gizmo2 .Expr ;
25+ import io .quarkus .gizmo2 .creator .BlockCreator ;
26+ import io .quarkus .gizmo2 .desc .MethodDesc ;
2627
2728public class LookupConditionsProcessor {
2829
@@ -39,22 +40,20 @@ public class LookupConditionsProcessor {
3940 private static final String STRING_VALUE = "stringValue" ;
4041 private static final String LOOKUP_IF_MISSING = "lookupIfMissing" ;
4142
42- private static final MethodDescriptor SUPPRESS_IF_PROPERTY = MethodDescriptor .ofMethod (
43- SuppressConditions .class ,
44- "suppressIfProperty" , boolean .class , String .class , String .class , boolean .class );
45- private static final MethodDescriptor SUPPRESS_UNLESS_PROPERTY = MethodDescriptor .ofMethod (
46- SuppressConditions .class ,
47- "suppressUnlessProperty" , boolean .class , String .class , String .class , boolean .class );
43+ private static final MethodDesc SUPPRESS_IF_PROPERTY = MethodDesc .of (SuppressConditions .class , "suppressIfProperty" ,
44+ boolean .class , String .class , String .class , boolean .class );
45+ private static final MethodDesc SUPPRESS_UNLESS_PROPERTY = MethodDesc .of (SuppressConditions .class , "suppressUnlessProperty" ,
46+ boolean .class , String .class , String .class , boolean .class );
4847
4948 @ BuildStep
5049 void suppressConditionsGenerators (BuildProducer <SuppressConditionGeneratorBuildItem > generators ,
5150 BeanArchiveIndexBuildItem beanArchiveIndex ) {
5251 IndexView index = beanArchiveIndex .getIndex ();
5352
54- generators .produce (new SuppressConditionGeneratorBuildItem (new Function <BeanInfo , Consumer <BytecodeCreator >>() {
53+ generators .produce (new SuppressConditionGeneratorBuildItem (new Function <BeanInfo , Consumer <BlockCreator >>() {
5554
5655 @ Override
57- public Consumer <BytecodeCreator > apply (BeanInfo bean ) {
56+ public Consumer <BlockCreator > apply (BeanInfo bean ) {
5857 Optional <AnnotationTarget > maybeTarget = bean .getTarget ();
5958 if (maybeTarget .isPresent ()) {
6059 AnnotationTarget target = maybeTarget .get ();
@@ -63,30 +62,28 @@ public Consumer<BytecodeCreator> apply(BeanInfo bean) {
6362 List <AnnotationInstance > unlessPropertyList = findAnnotations (target , LOOK_UP_UNLESS_PROPERTY ,
6463 LOOK_UP_UNLESS_PROPERTY_CONTAINER , index );
6564 if (!ifPropertyList .isEmpty () || !unlessPropertyList .isEmpty ()) {
66- return new Consumer <BytecodeCreator >() {
65+ return new Consumer <BlockCreator >() {
6766 @ Override
68- public void accept (BytecodeCreator suppressed ) {
67+ public void accept (BlockCreator suppressed ) {
6968 for (AnnotationInstance ifProperty : ifPropertyList ) {
7069 String propertyName = ifProperty .value (NAME ).asString ();
7170 String expectedStringValue = ifProperty .value (STRING_VALUE ).asString ();
7271 AnnotationValue lookupIfMissingValue = ifProperty .value (LOOKUP_IF_MISSING );
7372 boolean lookupIfMissing = lookupIfMissingValue != null
7473 && lookupIfMissingValue .asBoolean ();
75- ResultHandle result = suppressed .invokeStaticMethod (
76- SUPPRESS_IF_PROPERTY , suppressed .load (propertyName ),
77- suppressed .load (expectedStringValue ), suppressed .load (lookupIfMissing ));
78- suppressed .ifTrue (result ).trueBranch ().returnValue (suppressed .load (true ));
74+ Expr result = suppressed .invokeStatic (SUPPRESS_IF_PROPERTY , Const .of (propertyName ),
75+ Const .of (expectedStringValue ), Const .of (lookupIfMissing ));
76+ suppressed .if_ (result , BlockCreator ::returnTrue );
7977 }
8078 for (AnnotationInstance unlessProperty : unlessPropertyList ) {
8179 String propertyName = unlessProperty .value (NAME ).asString ();
8280 String expectedStringValue = unlessProperty .value (STRING_VALUE ).asString ();
8381 AnnotationValue lookupIfMissingValue = unlessProperty .value (LOOKUP_IF_MISSING );
8482 boolean lookupIfMissing = lookupIfMissingValue != null
8583 && lookupIfMissingValue .asBoolean ();
86- ResultHandle result = suppressed .invokeStaticMethod (
87- SUPPRESS_UNLESS_PROPERTY , suppressed .load (propertyName ),
88- suppressed .load (expectedStringValue ), suppressed .load (lookupIfMissing ));
89- suppressed .ifTrue (result ).trueBranch ().returnValue (suppressed .load (true ));
84+ Expr result = suppressed .invokeStatic (SUPPRESS_UNLESS_PROPERTY , Const .of (propertyName ),
85+ Const .of (expectedStringValue ), Const .of (lookupIfMissing ));
86+ suppressed .if_ (result , BlockCreator ::returnTrue );
9087 }
9188 }
9289 };
@@ -102,20 +99,19 @@ List<AnnotationInstance> findAnnotations(AnnotationTarget target, DotName annota
10299 AnnotationInstance annotation ;
103100 AnnotationInstance container ;
104101 switch (target .kind ()) {
105- case CLASS :
102+ case CLASS -> {
106103 annotation = target .asClass ().declaredAnnotation (annotationName );
107104 container = target .asClass ().declaredAnnotation (containingAnnotationName );
108- break ;
109- case FIELD :
105+ }
106+ case FIELD -> {
110107 annotation = target .asField ().annotation (annotationName );
111108 container = target .asField ().annotation (containingAnnotationName );
112- break ;
113- case METHOD :
109+ }
110+ case METHOD -> {
114111 annotation = target .asMethod ().annotation (annotationName );
115112 container = target .asMethod ().annotation (containingAnnotationName );
116- break ;
117- default :
118- throw new IllegalStateException ("Invalid bean target: " + target );
113+ }
114+ default -> throw new IllegalStateException ("Invalid bean target: " + target );
119115 }
120116 if (annotation == null && container == null ) {
121117 return Collections .emptyList ();
0 commit comments