in lib/generator.js [711:806]
visitType(ast, level) {
if (ast.type === 'array') {
this.visitType(ast.subType, level);
this.emit('[]');
} else if (ast.type === 'moduleModel') {
const [moduleId, ...rest] = ast.path;
const { namespace, modelDir, exceptionDir } = this.moduleClass.get(moduleId.lexeme);
const moduleModelName = rest.map((item) => {
return item.lexeme;
}).join('\\');
let type = modelDir;
let suffix = '';
const usedEx = this.usedExternException.get(moduleId.lexeme);
if(usedEx && usedEx.has(moduleModelName)) {
type = exceptionDir;
suffix = 'Exception';
}
const subModelName = this.getRealModelName(`${namespace}\\${type}\\${moduleModelName}${suffix}`);
this.emit(subModelName);
} else if (ast.type === 'subModel') {
const [moduleId, ...rest] = ast.path;
const subModelName = _subModelName([moduleId.lexeme, ...rest.map((item) => {
return item.lexeme;
})].join('\\'));
const realModelName = this.getRealModelName(`${this.namespace}\\${this.modelDir}\\${subModelName}`);
this.emit(realModelName);
} else if (ast.type === 'map') {
this.visitType(ast.valueType, level);
this.emit('[]');
} else if (ast.type === 'model') {
let namespace = this.namespace;
let type = this.modelDir;
let suffix = '';
if (ast.moduleName) {
namespace = this.moduleClass.get(ast.moduleName).namespace;
const { modelDir, exceptionDir } = this.moduleClass.get(ast.moduleName);
type = modelDir;
const usedEx = this.usedExternException.get(ast.moduleName);
if(usedEx && usedEx.has(ast.name)) {
suffix = 'Exception';
type = exceptionDir;
}
} else if(this.predefined[ast.name] && this.predefined[ast.name].isException) {
suffix = 'Exception';
type = this.exceptionDir;
}
const realModelName = this.getRealModelName(`${namespace}\\${type}\\${ast.name}${suffix}`);
this.emit(realModelName);
} else if (this.isIterator(ast)) {
this.visitType(ast.valueType);
} else if (ast.type === 'entry') {
this.emit('[string, ');
this.visitType(ast.valueType);
this.emit(']');
} else if (ast.idType === 'model') {
let type = this.modelDir;
let suffix = '';
if(this.predefined[ast.lexeme] && this.predefined[ast.lexeme].isException) {
type = this.exceptionDir;
suffix = 'Exception';
}
const realModelName = this.getRealModelName(`${this.namespace}\\${type}\\${ast.lexeme}${suffix}`);
this.emit(realModelName);
} else if (ast.idType === 'module') {
let moduleName = _name(ast);
if(this.builtin[moduleName]) {
moduleName = this.getType(moduleName);
} else {
moduleName = this.getRealClientName(moduleName);
}
this.emit(moduleName);
} else if (ast.idType === 'builtin_model') {
const realModelName = this.getRealModelName(this.getType(ast.lexeme));
this.emit(realModelName);
} else if (ast.type === 'moduleTypedef') {
const [moduleId, modelName] = ast.path;
const moduleTypedef = this.moduleTypedef[moduleId.lexeme];
const typedef = moduleTypedef[modelName.lexeme];
if(!typedef.import) {
this.emit(typedef.type);
} else {
const typedefName = this.getRealModelName(`${typedef.import}\\${typedef.type}`);
this.emit(typedefName);
}
} else if (ast.type === 'typedef' || ast.idType === 'typedef') {
const typedef = this.typedef[ast.lexeme];
if(!typedef.import) {
this.emit(typedef.type);
} else {
const typedefName = this.getRealModelName(`${typedef.import}\\${typedef.type}`);
this.emit(typedefName);
}
} else {
this.emit(this.getType(_name(ast)));
}
}