Skip to content

Commit a647011

Browse files
committed
Split up some methods that became more complex due to streams to loops
Signed-off-by: Michael Edgar <[email protected]>
1 parent d805bd8 commit a647011

File tree

2 files changed

+76
-45
lines changed

2 files changed

+76
-45
lines changed

core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import io.smallrye.openapi.runtime.scanner.dataobject.AnnotationTargetProcessor;
3535
import io.smallrye.openapi.runtime.scanner.dataobject.AugmentedIndexView;
3636
import io.smallrye.openapi.runtime.scanner.dataobject.DataObjectDeque;
37+
import io.smallrye.openapi.runtime.scanner.dataobject.DataObjectDeque.PathEntry;
3738
import io.smallrye.openapi.runtime.scanner.dataobject.IgnoreResolver;
3839
import io.smallrye.openapi.runtime.scanner.dataobject.TypeResolver;
3940
import io.smallrye.openapi.runtime.scanner.spi.AnnotationScannerContext;
@@ -281,15 +282,7 @@ private void depthFirstGraphSearch() {
281282
reference);
282283

283284
processClassAnnotations(currentSchema, currentClass);
284-
285-
// Handle fields
286-
for (TypeResolver resolver : properties.values()) {
287-
if (!resolver.isIgnored()) {
288-
AnnotationTargetProcessor.process(context, objectStack, resolver,
289-
currentPathEntry);
290-
}
291-
}
292-
285+
processProperties(currentPathEntry, properties);
293286
processInheritance(currentPathEntry);
294287
}
295288
}
@@ -328,6 +321,14 @@ private void processClassAnnotations(Schema schema, ClassInfo classInfo) {
328321
}
329322
}
330323

324+
private void processProperties(PathEntry currentPathEntry, Map<String, TypeResolver> properties) {
325+
for (TypeResolver resolver : properties.values()) {
326+
if (!resolver.isIgnored()) {
327+
AnnotationTargetProcessor.process(context, objectStack, resolver, currentPathEntry);
328+
}
329+
}
330+
}
331+
331332
private void processInheritance(DataObjectDeque.PathEntry currentPathEntry) {
332333
ClassInfo currentClass = currentPathEntry.getClazz();
333334
Schema currentSchema = currentPathEntry.getSchema();

core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeResolver.java

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.LinkedHashMap;
1616
import java.util.List;
1717
import java.util.Map;
18+
import java.util.Objects;
1819
import java.util.Optional;
1920
import java.util.PriorityQueue;
2021
import java.util.Queue;
@@ -538,51 +539,23 @@ public static Map<String, TypeResolver> getAllFields(AnnotationScannerContext co
538539
Map<ClassInfo, Type> chain = index.inheritanceChain(leafKlazz, leaf);
539540
Map<String, TypeResolver> properties = new LinkedHashMap<>();
540541
Deque<Map<String, Type>> stack = new ArrayDeque<>();
541-
boolean skipPropertyScan = false;
542+
boolean skipScan = false;
542543
List<ClassInfo> descendants = new ArrayList<>(chain.size());
543544

544545
for (Map.Entry<ClassInfo, Type> entry : chain.entrySet()) {
545546
ClassInfo currentClass = entry.getKey();
546547
Type currentType = entry.getValue();
547-
maybeAddResolutionParams(stack, currentType, currentClass);
548548

549-
if (skipPropertyScan || (!currentType.equals(leaf) && TypeUtil.isAllOf(context, leafKlazz, currentType))
550-
|| TypeUtil.knownJavaType(currentClass.name())) {
551-
/*
552-
* Do not attempt to introspect fields of Java/JDK types or if the @Schema
553-
* annotation indicates the use of a `ref` for superclass fields.
554-
*/
555-
skipPropertyScan = true;
556-
continue;
557-
}
549+
skipScan = skipCheck(skipScan, context, leaf, leafKlazz, currentType, currentClass);
558550

559-
// Store all field properties
560-
for (FieldInfo field : JandexUtil.fields(context, currentClass)) {
561-
if (acceptField(field) && field.name().chars().allMatch(Character::isJavaIdentifierPart)) {
562-
scanField(context, properties, field, stack, reference, descendants);
563-
}
564-
}
565-
566-
for (MethodInfo method : methods(context, currentClass)) {
567-
if (acceptMethod(method) && method.name().chars().allMatch(Character::isJavaIdentifierPart)) {
568-
scanMethod(context, properties, method, stack, reference, descendants);
569-
}
551+
if (skipScan) {
552+
continue;
570553
}
571554

572-
for (Type type : index.interfaces(currentClass)) {
573-
if (!TypeUtil.knownJavaType(type.name())) {
574-
ClassInfo clazz = index.getClass(type);
575-
maybeAddResolutionParams(stack, type, clazz);
576-
577-
if (clazz != null) {
578-
for (MethodInfo method : methods(context, clazz)) {
579-
if (method.name().chars().allMatch(Character::isJavaIdentifierPart)) {
580-
scanMethod(context, properties, method, stack, reference, descendants);
581-
}
582-
}
583-
}
584-
}
585-
}
555+
maybeAddResolutionParams(stack, currentType, currentClass);
556+
scanFields(context, currentClass, properties, stack, reference, descendants);
557+
scanMethods(context, currentClass, properties, stack, reference, descendants);
558+
scanInterfaces(context, currentClass, properties, stack, reference, descendants);
586559

587560
descendants.add(currentClass);
588561
}
@@ -606,6 +579,63 @@ private static void maybeAddResolutionParams(Deque<Map<String, Type>> stack, Typ
606579
}
607580
}
608581

582+
private static boolean skipCheck(boolean skip, AnnotationScannerContext context, Type leafType,
583+
ClassInfo leafKlazz,
584+
Type currentType,
585+
ClassInfo currentClass) {
586+
if (skip || (!currentType.equals(leafType) && TypeUtil.isAllOf(context, leafKlazz, currentType))
587+
|| TypeUtil.knownJavaType(currentClass.name())) {
588+
/*
589+
* Do not attempt to introspect fields of Java/JDK types or if the @Schema
590+
* annotation indicates the use of a `ref` for superclass fields.
591+
*/
592+
skip = true;
593+
}
594+
595+
return skip;
596+
}
597+
598+
private static void scanFields(AnnotationScannerContext context, ClassInfo currentClass,
599+
Map<String, TypeResolver> properties, Deque<Map<String, Type>> stack, AnnotationTarget reference,
600+
List<ClassInfo> descendants) {
601+
for (FieldInfo field : JandexUtil.fields(context, currentClass)) {
602+
if (acceptField(field) && field.name().chars().allMatch(Character::isJavaIdentifierPart)) {
603+
scanField(context, properties, field, stack, reference, descendants);
604+
}
605+
}
606+
}
607+
608+
private static void scanMethods(AnnotationScannerContext context, ClassInfo currentClass,
609+
Map<String, TypeResolver> properties, Deque<Map<String, Type>> stack, AnnotationTarget reference,
610+
List<ClassInfo> descendants) {
611+
for (MethodInfo method : methods(context, currentClass)) {
612+
if (acceptMethod(method) && method.name().chars().allMatch(Character::isJavaIdentifierPart)) {
613+
scanMethod(context, properties, method, stack, reference, descendants);
614+
}
615+
}
616+
}
617+
618+
private static void scanInterfaces(AnnotationScannerContext context, ClassInfo currentClass,
619+
Map<String, TypeResolver> properties, Deque<Map<String, Type>> stack, AnnotationTarget reference,
620+
List<ClassInfo> descendants) {
621+
AugmentedIndexView index = context.getAugmentedIndex();
622+
623+
for (Type type : index.interfaces(currentClass)) {
624+
if (!TypeUtil.knownJavaType(type.name())) {
625+
ClassInfo clazz = index.getClass(type);
626+
maybeAddResolutionParams(stack, type, clazz);
627+
628+
if (clazz != null) {
629+
for (MethodInfo method : methods(context, clazz)) {
630+
if (method.name().chars().allMatch(Character::isJavaIdentifierPart)) {
631+
scanMethod(context, properties, method, stack, reference, descendants);
632+
}
633+
}
634+
}
635+
}
636+
}
637+
}
638+
609639
private static List<MethodInfo> methods(AnnotationScannerContext context, ClassInfo currentClass) {
610640
if (context.getConfig().sortedPropertiesEnable()) {
611641
return currentClass.methods();

0 commit comments

Comments
 (0)