Skip to content

Commit f2f470f

Browse files
Documentation
1 parent 111f000 commit f2f470f

File tree

3 files changed

+293
-5
lines changed

3 files changed

+293
-5
lines changed

env-model-generator/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"build": "tsc",
1717
"lint": "tslint src/**/*.ts",
1818
"fix-lint": "tslint src/**/*.ts --fix",
19+
"gen-docs": "typedoc --out doc",
1920
"start": "node built/env-model-generator.js ../benchmarks/GENUINE/sakai/edu-services/cm-service/cm-impl/hibernate-impl/impl/src/test/spring-test.xml --outputPath output"
2021
},
2122
"dependencies": {
@@ -32,6 +33,7 @@
3233
"@types/xml2js": "0.4.2",
3334
"tslint": "5.4.2",
3435
"tslint-language-service": "0.9.6",
36+
"typedoc": "^0.11.1",
3537
"typescript": "2.4.1"
3638
}
3739
}

env-model-generator/src/parseJson.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,30 @@ interface NamedComponent {
1010
component: jsonConfig.Component;
1111
}
1212

13+
/**
14+
* [[BeanDefinitionMethod]] does not include the name of the method or the name of the class it is defined in; these are provided by the context.
15+
*
16+
* This class therefore combines these bits of information to act as the value to be used in a map from calculated identifiers to bean definition
17+
* methods.
18+
*/
1319
interface NamedBeanDefinitionMethod {
1420
className: string;
1521
name: string;
1622
method: jsonConfig.BeanDefinitionMethod;
1723
}
1824

25+
// A map from identifiers to components discovered in the JSON file.
1926
const componentsById = new Map<string, NamedComponent>();
27+
// A map from identifiers to bean definition methods discovered in the JSON file.
2028
const beansById = new Map<string, NamedBeanDefinitionMethod>();
2129

30+
/**
31+
* Collect beans from the JSON configuration file without parsing them.
32+
*
33+
* This allows us to set up objects that can be used to resolve circular references discovered later during parsing.
34+
* @param filePath The path to the configuration file to read the input from
35+
* @returns Paths to other config files to also include
36+
*/
2237
export async function collectBeansFromConfigFile(filePath: string): Promise<string[]> {
2338
let json: string;
2439
try {
@@ -60,7 +75,12 @@ export async function collectBeansFromConfigFile(filePath: string): Promise<stri
6075
return [];
6176
}
6277

63-
// Check for duplicate ids from other beans
78+
/**
79+
* Check for duplicate ids from other beans or aliases
80+
* @param id The bean identifier to check
81+
* @param location The location to include in the text of any thrown exception
82+
* @throws [[ConfigParseError]] If the bean identifier has already been used
83+
*/
6484
function checkBeanId(id: string, location: string): void {
6585
if (componentsById.has(id))
6686
throw new ConfigParseError(`${location}: There is an existing component with id '${id}'`);
@@ -71,10 +91,18 @@ function checkBeanId(id: string, location: string): void {
7191
throw new ConfigParseError(`${location}: There is an existing alias with identifier '${aliasedBeanId}'`);
7292
}
7393

94+
/**
95+
* Check whether a bean identifier is already implemented by an element from the JSON configuration
96+
* @param id The bean identifier to check
97+
* @returns True if the bean identifier is already registered
98+
*/
7499
export function beanWithIdExists(id: string): boolean {
75100
return componentsById.has(id) || beansById.has(id);
76101
}
77102

103+
/**
104+
* Create the model for each bean discovered during the execution of [[collectBeansFromConfigFile]]
105+
*/
78106
export function parseAllBeans(): void {
79107
for (const [ beanId, component ] of componentsById) {
80108
if (model.Bean.tryGet(beanId) !== undefined)
@@ -90,6 +118,11 @@ export function parseAllBeans(): void {
90118
}
91119
}
92120

121+
/**
122+
* Create the model for a bean with the given identifier
123+
* @param id The identifier of a bean implemented by a component or bean definition method
124+
* @returns The model for the bean
125+
*/
93126
export function parseBean(id: string): model.Bean {
94127
const component = componentsById.get(id);
95128
if (component !== undefined)
@@ -100,6 +133,12 @@ export function parseBean(id: string): model.Bean {
100133
throw new Error("Called parseBean on a bean that did not exist");
101134
}
102135

136+
/**
137+
* Create the model for a bean with the given identifier defined by a component from the JSON configuration file
138+
* @param id The identifier of a bean implemented by a component
139+
* @param namedBean The component definition from the JSON configuration file
140+
* @returns The model for the bean
141+
*/
103142
function parseJsonComponent(id: string, namedBean: NamedComponent): model.Bean {
104143
const component = namedBean.component;
105144
const properties: model.BeanProperty[] = [];
@@ -115,6 +154,12 @@ function parseJsonComponent(id: string, namedBean: NamedComponent): model.Bean {
115154
return new model.Bean(undefined, id, namedBean.qualifiedClassName, false, [], properties);
116155
}
117156

157+
/**
158+
* Create the model for a bean with the given identifier defined by a component from the JSON configuration file
159+
* @param id The identifier of a bean implemented by a bean definition method
160+
* @param namedMethod The bean definition method definition from the JSON configuration file
161+
* @returns The model for the bean
162+
*/
118163
function parseJsonBean(id: string, namedMethod: NamedBeanDefinitionMethod): model.Bean {
119164
const fieldBeanId = model.Bean.tryGetIdByClass(namedMethod.className);
120165
if (fieldBeanId === undefined)

0 commit comments

Comments
 (0)