visitType()

in lib/common_generator.js [1043:1136]


  visitType(ast, isSubType = false) {
    if (ast.type === 'map') {
      this.emit(`java.util.Map<`);
      this.visitType(ast.keyType, true);
      this.emit(`, `);
      this.visitType(ast.valueType, true);
      this.emit(`>`);
    } else if (ast.type === 'array') {
      this.emit(`java.util.List<`);
      this.visitType(ast.subType || ast.itemType, true);
      this.emit(`>`);
    } else if (ast.type === 'model') {
      if (ast.moduleName) {
        const modelMap = `${ast.moduleName}:${_name(ast)}`;
        if (this.ctx.conflictModels.get(modelMap)) {
          this.emit(`${this.ctx.imports[ast.moduleName].package}.models.`);
        }
      } else {
        const modelMap = `${_name(ast)}`;
        if (this.ctx.conflictModels.get(modelMap)) {
          this.emit(`${this.ctx.package}.models.`);
        }
      }
      this.emit(`${_type(this.getSubFieldClassName(ast.name, true))}`);
    } else if (ast.type === 'subModel') {
      let className = '';
      for (let i = 0; i < ast.path.length; i++) {
        const item = ast.path[i];
        if (i > 0) {
          className += '.';
        }
        className += item.lexeme;
      }
      let resultName = this.getSubModelClassName(className.split('.'), 0, '');
      this.emit(resultName);
    } else if (ast.type === 'moduleModel') {
      const [moduleId, ...rest] = ast.path;
      let pathName = rest.map((item) => {
        return item.lexeme;
      }).join('.');
      let subModelName = '';
      if (rest.length > 1) {
        subModelName = `.${_subModelName(pathName, this.ctx.conflictModelNameMap, this.ctx.allModleNameMap)}`;
      }
      var modelName = rest[0].lexeme;
      var moduleName = moduleId.lexeme;
      var packageName = `${this.ctx.imports[moduleName].package}.models.`;
      const checkModel = moduleName + ':' + pathName;
      if (this.ctx.conflictModels.get(checkModel)) {
        this.emit(packageName + modelName + subModelName);
      } else {
        this.emit(modelName + subModelName);
      }
    } else if (ast.type === 'basic') {
      this.emit(_type(ast.name));
    } else if (this.ctx.predefined && this.ctx.predefined[`module:${_name(ast)}`]) {
      var className = this.ctx.imports[ast.lexeme || ast.name].className || 'DefaultAsyncClient';
      this.emit(`${this.ctx.imports[_name(ast)]}.${className}`);
    } else if (ast.idType === 'module') {
      let className = this.ctx.imports[ast.lexeme || ast.name].className;
      if (this.ctx.conflictModels.get(className) && this.ctx.conflictModels.get(className) !== this.ctx.imports[ast.lexeme].package) {
        this.emit(`${this.ctx.imports[ast.lexeme || ast.name].package}.${className}`);
      } else {
        if (!this.ctx.conflictModels.get(className)) {
          this.ctx.conflictModels.set(className, this.ctx.imports[ast.lexeme || ast.name].package);
        }
        this.emit(className);
      }
    } else if (ast.idType === 'model') {
      const modelMap = `${_name(ast)}`;
      if (this.ctx.conflictModels.get(modelMap)) {
        this.emit(`${this.ctx.package}.models.`);
      }
      this.emit(modelMap);
    } else if (ast.type === 'module_instance') {
      let className = this.ctx.imports[ast.lexeme || ast.name].className;
      if (this.ctx.conflictModels.get(className) && this.ctx.conflictModels.get(className) !== this.ctx.imports[ast.lexeme].package) {
        this.emit(`${this.ctx.imports[ast.lexeme || ast.name].package}.${className}`);
      } else {
        if (!this.ctx.conflictModels.get(className)) {
          this.ctx.conflictModels.set(className, this.ctx.imports[ast.lexeme || ast.name].package);
        }
        this.emit(className);
      }
    } else if (ast.type === 'iterator') {
      this.emit(`ResponseIterable<${_type(ast.valueType.lexeme || ast.valueType.name)}>`);
    } else {
      if (isSubType) {
        this.emit(collectionType(_type(ast.lexeme || ast.name)));
      } else {
        this.emit(_type(ast.lexeme || ast.name));
      }
    }
  }