@@ -26,12 +26,20 @@ export interface BeanProperty {
26
26
}
27
27
28
28
interface Factory {
29
- bean : Bean ;
29
+ bean : IBean ;
30
30
method : string ;
31
31
}
32
32
33
- export class Bean {
34
- private readonly isAnonymous : boolean ;
33
+ export interface IBean {
34
+ readonly IsAnonymous : boolean ;
35
+ readonly name : string ;
36
+ readonly getter : string ;
37
+ readonly javaMembers : Member [ ] ;
38
+ readonly exceptions : string [ ] ;
39
+ }
40
+
41
+ export class Bean implements IBean {
42
+ public readonly IsAnonymous : boolean ;
35
43
public readonly name : string ;
36
44
private readonly impl : string | Factory ;
37
45
private readonly isLazyInit : boolean ;
@@ -70,16 +78,16 @@ export class Bean {
70
78
71
79
if ( impl === undefined )
72
80
throw Error ( `Tried to create a Bean ('${ name } ') without a class name or a factory bean/method` ) ;
73
- this . isAnonymous = name === undefined ;
81
+ this . IsAnonymous = name === undefined ;
74
82
if ( name === undefined )
75
- name = Bean . getNextAnonName ( typeof impl === "string" ? impl : impl . bean . identifier + "_" + impl . method ) ;
83
+ name = Bean . getNextAnonName ( typeof impl === "string" ? impl : impl . bean . name + "_" + impl . method ) ;
76
84
this . name = name ;
77
85
this . impl = impl ;
78
86
this . isLazyInit = isLazyInit ;
79
87
this . constructorArgs = constructorArgs ;
80
88
this . properties = propertiesMap ;
81
89
this . initMethod = initMethod ;
82
- Bean . beans . add ( this ) ;
90
+ Repository . registerBean ( this ) ;
83
91
}
84
92
85
93
private get identifier ( ) : string {
@@ -172,46 +180,83 @@ export class Bean {
172
180
Bean . anonIndexByClass . set ( baseName , index ) ;
173
181
return baseName + index ;
174
182
}
183
+ }
184
+
185
+ export class UndefinedBean implements IBean {
186
+ private readonly typeName : string ;
187
+ public readonly name : string ;
188
+ public readonly IsAnonymous = true ;
189
+
190
+ public constructor ( identifier : string , typeName : string ) {
191
+ this . name = identifier ;
192
+ this . typeName = typeName ;
193
+ Repository . registerBean ( this ) ;
194
+ Repository . registerIdForClass ( this . typeName , this . name ) ;
195
+ }
196
+
197
+ public get getter ( ) : string {
198
+ return `get${ upperInitialChar ( this . name ) } ` ;
199
+ }
200
+
201
+ public get javaMembers ( ) : Member [ ] {
202
+ return [
203
+ new Method (
204
+ `public static ${ this . typeName } ${ this . getter } ()` ,
205
+ [
206
+ new Return ( new FnCall ( "org.cprover.CProver.nondetWithNull" , [ ] ) ) ,
207
+ ] ,
208
+ [ ] ) ,
209
+ new BlankLine ( ) ,
210
+ ] ;
211
+ }
212
+
213
+ public readonly exceptions : string [ ] = [ ] ;
214
+ }
175
215
176
- private static beans = new NameMap < Bean > ( ) ;
216
+ export namespace Repository {
217
+ const beans = new NameMap < IBean > ( ) ;
218
+
219
+ export function registerBean ( bean : IBean ) {
220
+ beans . add ( bean ) ;
221
+ }
177
222
178
- public static tryGet ( beanId : string ) {
179
- const aliasedBeanId = Bean . getAlias ( beanId ) ;
180
- return Bean . beans . get ( aliasedBeanId === undefined ? beanId : aliasedBeanId ) ;
223
+ export function tryGet ( beanId : string ) {
224
+ const aliasedBeanId = getAlias ( beanId ) ;
225
+ return beans . get ( aliasedBeanId === undefined ? beanId : aliasedBeanId ) ;
181
226
}
182
227
183
- public static getAll ( ) : Iterable < Bean > {
184
- return Bean . beans ;
228
+ export function getAll ( ) : Iterable < IBean > {
229
+ return beans ;
185
230
}
186
231
187
- public static getNamed ( ) : Bean [ ] {
188
- return [ ...Bean . getAll ( ) ] . filter ( ( bean ) => ! bean . isAnonymous ) ;
232
+ export function getNamed ( ) : IBean [ ] {
233
+ return [ ...getAll ( ) ] . filter ( ( bean ) => ! bean . IsAnonymous ) ;
189
234
}
190
235
191
- private static aliases = new Map < string , string > ( ) ;
236
+ let aliases = new Map < string , string > ( ) ;
192
237
193
- public static getAlias ( alias : string ) : string | undefined {
194
- return Bean . aliases . get ( alias ) ;
238
+ export function getAlias ( alias : string ) : string | undefined {
239
+ return aliases . get ( alias ) ;
195
240
}
196
241
197
- public static addAlias ( alias : string , beanId : string ) {
198
- const existingAlias = Bean . getAlias ( alias ) ;
242
+ export function addAlias ( alias : string , beanId : string ) {
243
+ const existingAlias = getAlias ( alias ) ;
199
244
if ( existingAlias !== undefined ) {
200
245
if ( existingAlias !== beanId )
201
246
throw new ConfigParseError ( `Found multiple aliases from '${ alias } ' to '${ existingAlias } ' and '${ beanId } '` ) ;
202
247
// No point in adding the same alias again
203
248
return ;
204
249
}
205
- Bean . aliases . set ( alias , beanId ) ;
250
+ aliases . set ( alias , beanId ) ;
206
251
}
207
252
208
- public static checkAliases ( beanWithIdExists : ( beanId : string ) => boolean ) : void {
253
+ export function checkAliases ( beanWithIdExists : ( beanId : string ) => boolean ) : void {
209
254
// If A -> B is added before B -> C then A -> B needs updating to A -> C now
210
- const aliases = new Map < string , string > ( ) ;
211
- for ( const [ alias , target ] of Bean . aliases ) {
255
+ const simplifiedAliases = new Map < string , string > ( ) ;
256
+ for ( const [ alias , target ] of aliases ) {
212
257
let beanId = target ;
213
258
while ( true ) {
214
- const aliasedBeanId = Bean . aliases . get ( beanId ) ;
259
+ const aliasedBeanId = aliases . get ( beanId ) ;
215
260
if ( aliasedBeanId === undefined )
216
261
break ;
217
262
beanId = aliasedBeanId ;
@@ -220,27 +265,27 @@ export class Bean {
220
265
}
221
266
if ( ! beanWithIdExists ( beanId ) )
222
267
throw new ConfigParseError ( `Couldn't find bean '${ beanId } ' aliased from '${ alias } '` ) ;
223
- aliases . set ( alias , beanId ) ;
268
+ simplifiedAliases . set ( alias , beanId ) ;
224
269
}
225
- Bean . aliases = aliases ;
270
+ aliases = simplifiedAliases ;
226
271
}
227
272
228
- public static getAliases ( ) : Iterable < [ string , string ] > {
229
- return Bean . aliases ;
273
+ export function getAliases ( ) : Iterable < [ string , string ] > {
274
+ return aliases ;
230
275
}
231
276
232
- private static beanIdByClass = new MapTrackingDuplicates < string , string > ( ) ;
277
+ const beanIdByClass = new MapTrackingDuplicates < string , string > ( ) ;
233
278
234
- public static registerIdForClass ( qualifiedClassName : string , beanId : string ) {
235
- Bean . beanIdByClass . set ( qualifiedClassName , beanId ) ;
279
+ export function registerIdForClass ( qualifiedClassName : string , beanId : string ) {
280
+ beanIdByClass . set ( qualifiedClassName , beanId ) ;
236
281
}
237
282
238
- public static tryGetIdByClass ( qualifiedClassName : string ) : string | undefined {
239
- return Bean . beanIdByClass . get ( qualifiedClassName ) ;
283
+ export function tryGetIdByClass ( qualifiedClassName : string ) : string | undefined {
284
+ return beanIdByClass . get ( qualifiedClassName ) ;
240
285
}
241
286
242
- public static hasMultipleBeansForClass ( qualifiedClassName : string ) : boolean {
243
- return Bean . beanIdByClass . hasDuplicates ( qualifiedClassName ) ;
287
+ export function hasMultipleBeansForClass ( qualifiedClassName : string ) : boolean {
288
+ return beanIdByClass . hasDuplicates ( qualifiedClassName ) ;
244
289
}
245
290
}
246
291
@@ -384,7 +429,7 @@ export class BeanRefValue extends Value {
384
429
}
385
430
386
431
private get bean ( ) {
387
- const bean = Bean . tryGet ( this . beanRef ) ;
432
+ const bean = Repository . tryGet ( this . beanRef ) ;
388
433
if ( bean === undefined )
389
434
throw new Error ( `Reference created to bean '${ this . beanRef } ' that has no implementation` ) ;
390
435
return bean ;
@@ -396,9 +441,9 @@ export class BeanRefValue extends Value {
396
441
}
397
442
398
443
export class BeanValue extends Value {
399
- private bean : Bean ;
444
+ private bean : IBean ;
400
445
401
- public constructor ( bean : Bean ) {
446
+ public constructor ( bean : IBean ) {
402
447
super ( ) ;
403
448
this . bean = bean ;
404
449
}
0 commit comments