visitEcxceptionBody()

in lib/generator.js [2179:2213]


  visitEcxceptionBody(ast, level, exceptionName, env) {
    assert.equal(ast.type, 'exceptionBody');
    let node;
    for (let i = 0; i < ast.nodes.length; i++) {
      node = ast.nodes[i];
      const fieldName = _name(node.fieldName);
      // 父类里有的字段如果重复写,则表示new(隐藏父类)而不是override(覆盖父类)
      if (!exceptionFields.includes(fieldName)) {
        let comments = DSL.comment.getFrontComments(this.comments, node.tokenRange[0]);
        this.visitComments(comments, level);
        this.emit('public ', level);
        this.visitFieldType(node.fieldValue, level, exceptionName, fieldName);
        this.emit(` ${_escape(_upperFirst(_name(node.fieldName)))}`);
        this.emit(' { get; set; }\n');
      }

      if (node.fieldValue.type === 'modelBody') {
        this.emit(`public class ${exceptionName}${_upperFirst(node.fieldName.lexeme)} : Darabonba.Model\n`, level);
        this.emit('{\n', level);
        this.visitModelBody(node.fieldValue, level + 1, env, exceptionName + _upperFirst(node.fieldName.lexeme));
        this.emit('}\n', level);
      }
    }
    if (node) {
      //find the last node's back comment
      let comments = DSL.comment.getBetweenComments(this.comments, node.tokenRange[0], ast.tokenRange[1]);
      this.visitComments(comments, level);
    }

    if (ast.nodes.length === 0) {
      //empty block's comment
      let comments = DSL.comment.getBetweenComments(this.comments, ast.tokenRange[0], ast.tokenRange[1]);
      this.visitComments(comments, level);
    }
  }