apiBefore()

in lib/generator.js [2486:2579]


  apiBefore(level, extendParam, filepath, main) {
    this.used.push('System');
    this.used.push('System.IO');
    this.used.push('System.Collections');
    this.used.push('System.Collections.Generic');
    this.used.push('System.Threading.Tasks');
    this.used.push('Darabonba');
    this.used.push('Darabonba.Utils');
    let className = this.className;
    const fileInfo = path.parse(filepath);
    if (!main) {
      const beginNotes = DSL.note.getNotes(this.notes, 0, this.ast.moduleBody.nodes[0].tokenRange[0]);
      const clientNote = beginNotes.find(note => note.note.lexeme === '@clientName');
      if (clientNote) {
        className = clientNote.arg.value.string;
      } else {
        className = `${_upperFirst(fileInfo.name.toLowerCase())}Client`;
      }
    }
    this.emit(`public class ${className} `, level + 1);

    if (extendParam.extend && extendParam.extend.length > 0) {
      const extendsModuleName = this.getRealClientName(this.ast.extends.lexeme);
      const extendsInterfaces = extendParam.extend.filter(item => item.startsWith('I'));
      this.emit(`: ${extendsModuleName}${extendsInterfaces.join(', ') === '' ? '' : ', '}${extendsInterfaces.join(', ')}
    {
`);
    } else {
      this.emit(`
    {
`);
    }

  }

  // init(level) {
  //   // Nothing
  // }

  apiAfter() {
    // Nothing
  }

  wrapBefore() {

  }

  eachFunction(ast, level, env = {}) {
    let wrapName = _upperFirst(_name(ast.functionName));
    if (wrapName === 'Main' && env.isAsyncMode && !(this.isExec && this.asyncOnly)) {
      return;
    }
    this.visitAnnotation(ast.annotation, level);
    let comments = DSL.comment.getFrontComments(this.comments, ast.tokenRange[0]);
    this.visitComments(comments, level);
    this.emit('public ', level);
    if (ast.isStatic) {
      this.emit('static ');
    }
    if (env.isAsyncMode) {
      this.emit('async ');
      if (wrapName !== 'Main') {
        wrapName += 'Async';
      }
    }

    env.returnType = ast.returnType;
    this.visitReturnType(ast, 0, env);
    this.emit(`${wrapName}`);
    if (this.isExec && wrapName === 'Main') {
      this.emit('(string[] args)');
    } else {
      this.visitParams(ast.params, level, env);
    }

    this.emit('\n');
    this.emit('{\n', level);
    if (ast.functionBody) {
      this.visitWrapBody(ast.functionBody, level + 1, env);
    } else {
      this.emit('throw new NotImplementedException();\n', level + 1);
    }
    this.emit('}\n', level);
  }

  wrapAfter() {
    // Nothing
  }

  moduleAfter() {
    this.emit(`
    }
}\n`, 0);
  }