resolveFunc()

in src/resolver/client.js [187:240]


  resolveFunc(func, ast, body) {
    this.currThrows = {};
    if (ast.annotation) {
      func.addAnnotation(this.resolveAnnotation(ast.annotation, func.index));
    }
    this.addAnnotations(func, ast);
    if (body === null) {
      func.addBodyNode(new GrammerThrows(exceptionType, [], 'Un-implemented'));
    }

    if (ast.isAsync) {
      func.modify.push(Modify.async());
    }
    if (ast.isStatic) {
      func.modify.push(Modify.static());
    }
    func.modify.push(Modify.public());

    ast.params.params.forEach(p => {
      var param = new GrammerValue();
      param.type = this.resolveTypeItem(p.paramType, p);
      param.key = p.paramName.lexeme;
      if (p.needValidate) {
        func.addBodyNode(new GrammerCall('method', [
          { type: 'object', name: param.key },
          { type: 'call', name: 'validate' }
        ], [], new TypeVoid(), true)); // validator
      }
      func.params.push(param);
    });

    func.return.push(this.resolveTypeItem(ast.returnType));

    if (ast.runtimeBody) {
      this.runtimeMode(func, ast, body);
    } else {
      if (ast.functionBody || ast.wrapBody) {
        body.stmts.stmts.forEach(stmtItem => {
          this.visitStmt(func, stmtItem, func.index);
        });
      } else {
        this.requestBody(ast, body, func);
      }
    }

    if (func.body.length === 0) {
      this.findComments(func, body, 'between');
    }

    if (Object.keys(this.currThrows).length > 0) {
      func.throws = Object.values(this.currThrows);
    }
    this.object.addBodyNode(func);
  }