Skip to content

Commit f440e18

Browse files
Extract getBeanForClass
1 parent 3fbb788 commit f440e18

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

env-model-generator/src/parseJson.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,20 @@ function parseJsonComponent(id: string, namedBean: NamedComponent): model.Bean {
9696
for (const fieldName in component.fields) {
9797
if (!component.fields.hasOwnProperty(fieldName))
9898
continue;
99-
const fieldClass = component.fields[fieldName].type;
100-
101-
const fieldBeanId = model.Bean.tryGetIdByClass(fieldClass);
102-
if (fieldBeanId === undefined)
103-
throw new ConfigParseError(
104-
`Auto-wired field '${namedBean.qualifiedClassName}.${fieldName}' depends on a class '${fieldClass}' `
105-
+ `that has ${model.Bean.hasMultipleBeansForClass(fieldClass) ? "multiple" : "no"} implementations`);
106-
properties.push({ name: fieldName, value: new model.BeanRefValue(fieldBeanId) });
99+
properties.push({
100+
name: fieldName,
101+
value: getBeanForClass(component.fields[fieldName].type, `Auto-wired field '${namedBean.qualifiedClassName}.${fieldName}'`),
102+
});
107103
}
108104
// TODO: Handle constructor arguments
109105
return new model.Bean(undefined, id, namedBean.qualifiedClassName, false, [], properties);
110106
}
107+
108+
function getBeanForClass(className: string, userString: string): model.BeanRefValue {
109+
const fieldBeanId = model.Bean.tryGetIdByClass(className);
110+
if (fieldBeanId === undefined)
111+
throw new ConfigParseError(
112+
`${userString} depends on a class '${className}' `
113+
+ `that has ${model.Bean.hasMultipleBeansForClass(className) ? "multiple" : "no"} implementations`);
114+
return new model.BeanRefValue(fieldBeanId);
115+
}

0 commit comments

Comments
 (0)