visitConstructModel()

in lib/generator.js [1717:1768]


  visitConstructModel(ast, level) {
    assert.equal(ast.type, 'construct_model');
    if (ast.aliasId.isModule) {
      let aliasId = ast.aliasId.lexeme;
      let suffix = '';
      const { namespace, modelDir, exceptionDir } = this.moduleClass.get(aliasId);
      const moduleModelName = ast.propertyPath.map((item) => {
        return item.lexeme;
      }).join('\\');

      let type = modelDir;
      const usedEx = this.usedExternException.get(aliasId);
      if(usedEx && usedEx.has(moduleModelName)) {
        type = exceptionDir;
        suffix = 'Exception';
      }
      const subModelName = this.getRealModelName(`${namespace}\\${type}\\${moduleModelName}${suffix}`);
      this.emit(`new ${subModelName}`);
    }

    if (ast.aliasId.isModel) {
      let mainModelName = ast.aliasId;
      let type = this.modelDir;
      let suffix = '';

      this.emit('new ');
      const modelName = [mainModelName, ...ast.propertyPath].map((item) => {
        return item.lexeme;
      }).join('\\');
      
      if(_isBuiltinModel(modelName)) {
        const subModelName = this.getRealModelName(this.getType(modelName));
        this.emit(subModelName);
      } else {
        if(this.predefined[modelName] && this.predefined[modelName].isException) {
          type = this.exceptionDir;
          suffix = 'Exception';
        }
        const subModelName = this.getRealModelName(`${this.namespace}\\${type}\\${modelName}${suffix}`);
        this.emit(subModelName);
      }
      
    }

    this.emit('(');
    if (ast.object) {
      this.visitObject(ast.object, level);
    } else {
      this.emit('[ ]');
    }
    this.emit(')');
  }