6262// Public mostly only for testing scenarios.
6363public final class DefaultInstanceManager implements InstanceManager {
6464
65- private final Assignability assignability ;
6665
67- private final TypeAndElementSource tes ;
66+ /*
67+ * Instance fields.
68+ */
69+
70+
71+ private final Assignability assignability ;
6872
6973 private final TypeMirror scopeletType ;
7074
7175 private final BeanSelectionCriteria anyScopeletSelector ;
7276
7377 private final BeanSet beanSet ;
7478
75- public DefaultInstanceManager (final TypeAndElementSource tes ,
76- final Assignability assignability ,
79+
80+ /*
81+ * Constructors.
82+ */
83+
84+
85+ public DefaultInstanceManager (final Assignability assignability ,
7786 final Collection <? extends Bean <?>> beans ) {
7887 super ();
79- this .tes = Objects . requireNonNullElse ( tes , typeAndElementSource ()) ;
80- this . assignability = Objects . requireNonNullElse ( assignability , new Assignability ( this .tes ) );
81- this .scopeletType = this . tes .declaredType (null , this . tes .typeElement (Scopelet .class ), this . tes .wildcardType (null , null ));
82- this .anyScopeletSelector = new BeanSelectionCriteria (this .tes , this . assignability , this .scopeletType , List .of (anyQualifier ()), true );
88+ this .assignability = assignability == null ? new Assignability () : assignability ;
89+ final TypeAndElementSource tes = this .assignability . typeAndElementSource ( );
90+ this .scopeletType = tes .declaredType (null , tes .typeElement (Scopelet .class ), tes .wildcardType (null , null ));
91+ this .anyScopeletSelector = new BeanSelectionCriteria (this .assignability , this .scopeletType , List .of (anyQualifier ()), true );
8392 final Collection <Bean <?>> newBeans = new ArrayList <>(beans .size () + 5 );
8493 newBeans .addAll (beans );
8594 newBeans .add (new SingletonScopelet ().bean ());
8695 newBeans .add (new NoneScopelet ().bean ());
87- newBeans .add (new Bean <>(new Id (List .of (this . tes .declaredType (DefaultAutoCloseableRegistry .class ),
88- this . tes .declaredType (AutoCloseableRegistry .class )),
96+ newBeans .add (new Bean <>(new Id (List .of (tes .declaredType (DefaultAutoCloseableRegistry .class ),
97+ tes .declaredType (AutoCloseableRegistry .class )),
8998 anyAndDefaultQualifiers (),
9099 NONE_ID ),
91100 (c , r ) -> new DefaultAutoCloseableRegistry ()));
92- TypeElement e = this . tes .typeElement (DefaultCreation .class );
101+ TypeElement e = tes .typeElement (DefaultCreation .class );
93102 TypeVariable tv = (TypeVariable )e .getTypeParameters ().get (0 ).asType ();
94- final TypeMirror t0 = this . tes .declaredType (null , e , tv );
95- final TypeMirror t1 = this . tes .declaredType (null , e );
103+ final TypeMirror t0 = tes .declaredType (null , e , tv );
104+ final TypeMirror t1 = tes .declaredType (null , e );
96105 e = tes .typeElement (Creation .class );
97106 tv = (TypeVariable )e .getTypeParameters ().get (0 ).asType ();
98- final TypeMirror t2 = this . tes .declaredType (null , e , tv );
99- final TypeMirror t3 = this . tes .declaredType (null , e );
107+ final TypeMirror t2 = tes .declaredType (null , e , tv );
108+ final TypeMirror t3 = tes .declaredType (null , e );
100109 final BeanSelectionCriteria bsc =
101- new BeanSelectionCriteria (this .tes , this . assignability , this . tes .declaredType (AutoCloseableRegistry .class ), defaultQualifiers (), true );
110+ new BeanSelectionCriteria (this .assignability , tes .declaredType (AutoCloseableRegistry .class ), defaultQualifiers (), true );
102111 newBeans .add (new Bean <>(new Id (List .of (t0 , t1 , t2 , t3 ),
103112 anyAndDefaultQualifiers (),
104113 NONE_ID ),
@@ -107,13 +116,21 @@ public DefaultInstanceManager(final TypeAndElementSource tes,
107116 anyAndDefaultQualifiers (),
108117 SINGLETON_ID ),
109118 new Singleton <>(this )));
110- this .beanSet = new DefaultBeanSet (assignability , tes , newBeans );
119+ this .beanSet = new DefaultBeanSet (assignability , newBeans );
111120 }
112121
122+
123+ /*
124+ * Instance methods.
125+ */
126+
127+
128+ @ Override // InstanceManager
113129 public final BeanSet beanSet () {
114130 return this .beanSet ;
115131 }
116132
133+ @ Override // InstanceManager;
117134 @ SuppressWarnings ("unchecked" )
118135 public final <I > I instance (final BeanSelectionCriteria beanSelectionCriteria ,
119136 final Bean <I > bean , // nullable
@@ -140,6 +157,20 @@ public final <I> I instance(final BeanSelectionCriteria beanSelectionCriteria,
140157 referenceSelector );
141158 }
142159
160+ public final boolean remove (final Id id ) {
161+ return
162+ id != null &&
163+ this .<Scopelet <?>>instance (new BeanSelectionCriteria (this .assignability , scopeletType , List .of (id .governingScopeId ()), true ),
164+ null , // Factory
165+ null , // Creation
166+ null ) // ReferenceSelector
167+ .remove (id );
168+ }
169+
170+ /*
171+ * Private methods.
172+ */
173+
143174 private final <I > I instance (final Bean <I > bean ,
144175 final Function <? super Scopelet <?>, ? extends I > f ,
145176 final Creation <I > creation ,
@@ -148,7 +179,7 @@ private final <I> I instance(final Bean<I> bean,
148179 final I singleton = factory .singleton ();
149180 if (singleton == null ) {
150181 final BeanSelectionCriteria scopeletBeanSelectionCriteria =
151- new BeanSelectionCriteria (this .tes , this . assignability , scopeletType , List .of (bean .id ().governingScopeId ()), true );
182+ new BeanSelectionCriteria (this .assignability , scopeletType , List .of (bean .id ().governingScopeId ()), true );
152183 if (bean .equals (this .beanSet .bean (scopeletBeanSelectionCriteria , DefaultInstanceManager ::handleInactiveScopelets ))) {
153184 return factory .create (creation , referenceSelector );
154185 }
@@ -157,16 +188,6 @@ private final <I> I instance(final Bean<I> bean,
157188 return singleton ;
158189 }
159190
160- public final boolean remove (final Id id ) {
161- return
162- id != null &&
163- this .<Scopelet <?>>instance (new BeanSelectionCriteria (this .tes , this .assignability , scopeletType , List .of (id .governingScopeId ()), true ),
164- null , // Factory
165- null , // Creation
166- null ) // ReferenceSelector
167- .remove (id );
168- }
169-
170191
171192 /*
172193 * Static methods.
0 commit comments