Skip to content

Commit 42ca0eb

Browse files
committed
Add withAnnotationArray method in AnnotationCreator
1 parent 6459953 commit 42ca0eb

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/main/java/pelemenguin/classjs/content/AnnotationCreator.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,31 @@ public AnnotationCreator<AnnotationCreator<P>> withAnnotation(String name, Class
431431
return nested;
432432
}
433433

434+
@Info(
435+
"""
436+
Adds an array of nested annotations as a value to the current annotation.
437+
438+
@param name - The name of the nested annotation array value.
439+
@param className - The class of the nested annotations.
440+
@param annotations - The consumers to build each nested annotation. You don't have to call `build()` on them.
441+
@returns The current `AnnotationCreator` instance.
442+
"""
443+
)
444+
public AnnotationCreator<P> withAnnotationArray(String name, ClassNameWrapper className, Consumer<AnnotationCreator<AnnotationCreator<P>>>[] annotations) {
445+
this.toBuild = this.toBuild.andThen(av -> {
446+
AnnotationVisitor arrayAv = av.visitArray(name);
447+
for (Consumer<AnnotationCreator<AnnotationCreator<P>>> annotationConsumer : annotations) {
448+
AnnotationVisitor nestedAv = arrayAv.visitAnnotation(null, DescriptorUtils.toFieldDescriptor(className));
449+
AnnotationCreator<AnnotationCreator<P>> nested = new AnnotationCreator<>(this, className);
450+
annotationConsumer.accept(nested);
451+
nested.toBuild.accept(nestedAv);
452+
nestedAv.visitEnd();
453+
}
454+
arrayAv.visitEnd();
455+
});
456+
return this;
457+
}
458+
434459
@Info(
435460
"""
436461
Finalizes the annotation and returns to the parent creator.

0 commit comments

Comments
 (0)