32
32
import java .util .Optional ;
33
33
import java .util .Set ;
34
34
import java .util .function .Predicate ;
35
- import java .util .stream .Collectors ;
36
35
import java .util .stream .Stream ;
37
36
38
37
import org .springframework .data .repository .core .RepositoryMetadata ;
@@ -81,7 +80,7 @@ public static ArchitecturallyEvidentType of(JavaClass type, Classes beanTypes) {
81
80
delegates .add (new SpringDataAwareArchitecturallyEvidentType (type , beanTypes ));
82
81
}
83
82
84
- delegates .add (new SpringAwareArchitecturallyEvidentType (type ));
83
+ delegates .add (new SpringAwareArchitecturallyEvidentType (type , beanTypes ));
85
84
86
85
return DelegatingType .of (type , delegates );
87
86
});
@@ -135,6 +134,14 @@ public boolean isConfigurationProperties() {
135
134
return false ;
136
135
}
137
136
137
+ public boolean isInjectable () {
138
+ return isService () || isController () || isEventListener () || isConfigurationProperties ();
139
+ }
140
+
141
+ public boolean isValueObject () {
142
+ return false ;
143
+ }
144
+
138
145
/**
139
146
* Returns other types that are interesting in the context of the current {@link ArchitecturallyEvidentType}. For
140
147
* example, for an event listener this might be the event types the particular listener is interested in.
@@ -195,8 +202,13 @@ static class SpringAwareArchitecturallyEvidentType extends ArchitecturallyEviden
195
202
private static final Predicate <JavaMethod > IS_EVENT_LISTENER = IS_ANNOTATED_EVENT_LISTENER
196
203
.or (IS_IMPLEMENTING_EVENT_LISTENER );
197
204
198
- public SpringAwareArchitecturallyEvidentType (JavaClass type ) {
205
+ private final boolean injectable ;
206
+
207
+ public SpringAwareArchitecturallyEvidentType (JavaClass type , Classes beanTypes ) {
208
+
199
209
super (type );
210
+
211
+ this .injectable = beanTypes .contains (type );
200
212
}
201
213
202
214
/*
@@ -253,6 +265,15 @@ public boolean isConfigurationProperties() {
253
265
return Types .isAnnotatedWith (SpringTypes .AT_CONFIGURATION_PROPERTIES ).test (getType ());
254
266
}
255
267
268
+ /*
269
+ * (non-Javadoc)
270
+ * @see org.springframework.modulith.model.ArchitecturallyEvidentType#isInjectable()
271
+ */
272
+ @ Override
273
+ public boolean isInjectable () {
274
+ return injectable || SpringTypes .isComponent ().test (getType ()) || super .isInjectable ();
275
+ }
276
+
256
277
/*
257
278
* (non-Javadoc)
258
279
* @see org.springframework.modulith.model.ArchitecturallyEvidentType#getOtherTypeReferences()
@@ -411,20 +432,35 @@ public boolean isService() {
411
432
public boolean isEventListener () {
412
433
return getType ().getMethods ().stream ().anyMatch (IS_ANNOTATED_EVENT_LISTENER );
413
434
}
435
+
436
+ /*
437
+ * (non-Javadoc)
438
+ * @see org.springframework.modulith.model.ArchitecturallyEvidentType#isValueObject()
439
+ */
440
+ @ Override
441
+ public boolean isValueObject () {
442
+
443
+ JavaClass type = getType ();
444
+
445
+ return Types .isAnnotatedWith (org .jmolecules .ddd .annotation .ValueObject .class ).test (type )
446
+ || type .isAssignableTo (org .jmolecules .ddd .types .ValueObject .class );
447
+ }
414
448
}
415
449
416
450
static class DelegatingType extends ArchitecturallyEvidentType {
417
451
418
452
private final Supplier <Boolean > isAggregateRoot , isRepository , isEntity , isService , isController ,
419
- isEventListener ,
420
- isConfigurationProperties ;
453
+ isEventListener , isConfigurationProperties , isInjectable , isValueObject ;
454
+
421
455
private final Supplier <Collection <JavaClass >> referenceTypes ;
422
456
private final Supplier <Collection <ReferenceMethod >> referenceMethods ;
423
457
424
458
DelegatingType (JavaClass type , Supplier <Boolean > isAggregateRoot ,
425
459
Supplier <Boolean > isRepository , Supplier <Boolean > isEntity , Supplier <Boolean > isService ,
426
460
Supplier <Boolean > isController , Supplier <Boolean > isEventListener ,
427
461
Supplier <Boolean > isConfigurationProperties ,
462
+ Supplier <Boolean > isInjectable ,
463
+ Supplier <Boolean > isValueObject ,
428
464
Supplier <Collection <JavaClass >> referenceTypes ,
429
465
Supplier <Collection <ReferenceMethod >> referenceMethods ) {
430
466
@@ -437,43 +473,49 @@ static class DelegatingType extends ArchitecturallyEvidentType {
437
473
this .isController = isController ;
438
474
this .isEventListener = isEventListener ;
439
475
this .isConfigurationProperties = isConfigurationProperties ;
476
+ this .isInjectable = isInjectable ;
477
+ this .isValueObject = isValueObject ;
440
478
this .referenceTypes = referenceTypes ;
441
479
this .referenceMethods = referenceMethods ;
442
480
}
443
481
444
482
public static DelegatingType of (JavaClass type , List <ArchitecturallyEvidentType > types ) {
445
483
446
- Supplier < Boolean > isAggregateRoot = Suppliers
484
+ var isAggregateRoot = Suppliers
447
485
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isAggregateRoot ));
448
486
449
- Supplier < Boolean > isRepository = Suppliers
487
+ var isRepository = Suppliers
450
488
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isRepository ));
451
489
452
- Supplier < Boolean > isEntity = Suppliers
490
+ var isEntity = Suppliers
453
491
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isEntity ));
454
492
455
- Supplier < Boolean > isService = Suppliers
493
+ var isService = Suppliers
456
494
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isService ));
457
495
458
- Supplier < Boolean > isController = Suppliers
496
+ var isController = Suppliers
459
497
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isController ));
460
498
461
- Supplier < Boolean > isEventListener = Suppliers
499
+ var isEventListener = Suppliers
462
500
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isEventListener ));
463
501
464
- Supplier < Boolean > isConfigurationProperties = Suppliers
502
+ var isConfigurationProperties = Suppliers
465
503
.memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isConfigurationProperties ));
466
504
505
+ var isInjectable = Suppliers .memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isInjectable ));
506
+
507
+ var isValueObject = Suppliers .memoize (() -> types .stream ().anyMatch (ArchitecturallyEvidentType ::isValueObject ));
508
+
467
509
Supplier <Collection <JavaClass >> referenceTypes = Suppliers .memoize (() -> types .stream () //
468
510
.flatMap (ArchitecturallyEvidentType ::getReferenceTypes ) //
469
- .collect ( Collectors . toList () ));
511
+ .toList ());
470
512
471
513
Supplier <Collection <ReferenceMethod >> referenceMethods = Suppliers .memoize (() -> types .stream () //
472
514
.flatMap (ArchitecturallyEvidentType ::getReferenceMethods ) //
473
- .collect ( Collectors . toList () ));
515
+ .toList ());
474
516
475
517
return new DelegatingType (type , isAggregateRoot , isRepository , isEntity , isService , isController ,
476
- isEventListener , isConfigurationProperties , referenceTypes , referenceMethods );
518
+ isEventListener , isConfigurationProperties , isInjectable , isValueObject , referenceTypes , referenceMethods );
477
519
}
478
520
479
521
/*
@@ -541,6 +583,24 @@ public boolean isConfigurationProperties() {
541
583
return isConfigurationProperties .get ();
542
584
}
543
585
586
+ /*
587
+ * (non-Javadoc)
588
+ * @see org.springframework.modulith.model.ArchitecturallyEvidentType#isInjectable()
589
+ */
590
+ @ Override
591
+ public boolean isInjectable () {
592
+ return isInjectable .get ();
593
+ }
594
+
595
+ /*
596
+ * (non-Javadoc)
597
+ * @see org.springframework.modulith.model.ArchitecturallyEvidentType#isValueObject()
598
+ */
599
+ @ Override
600
+ public boolean isValueObject () {
601
+ return isValueObject .get ();
602
+ }
603
+
544
604
/*
545
605
* (non-Javadoc)
546
606
* @see org.springframework.modulith.model.ArchitecturallyEvidentType#getOtherTypeReferences()
0 commit comments