visitAnnotation()

in lib/generator.js [436:549]


  visitAnnotation(annotation, level) {
    if (!annotation || !annotation.value) {
      return;
    }
    let comments = DSL.comment.getFrontComments(this.comments, annotation.index);
    this.visitComments(comments, level);
    var ast = Annotation.parse(annotation.value);
    var description = ast.items.find((item) => {
      return item.type === 'description';
    });
    var summary = ast.items.find((item) => {
      return item.type === 'summary';
    });
    var _return = ast.items.find((item) => {
      return item.type === 'return';
    });
    var deprecated = ast.items.find((item) => {
      return item.type === 'deprecated';
    });
    var params = ast.items.filter((item) => {
      return item.type === 'param';
    }).map((item) => {
      return {
        name: item.name.id,
        text: item.text.text.trimEnd()
      };
    });
    var throws = ast.items.filter((item) => {
      return item.type === 'throws';
    }).map((item) => {
      return item.text.text.trimEnd();
    });

    const descriptionText = description ? description.text.text.trimEnd() : '';
    const summaryText = summary ? summary.text.text.trimEnd() : '';
    const returnText = _return ? _return.text.text.trimEnd() : '';
    let hasNextSection = false;

    this.emit('"""\n', level);
    if (summaryText !== '') {
      summaryText.split('\n').forEach((line) => {
        this.emit(` * ${line}\n`, level);
      });
      hasNextSection = true;
    }
    if (descriptionText !== '') {
      if (hasNextSection) {
        this.emit(' * \n', level);
      }
      this.emit(' * @remarks\n', level);
      descriptionText.split('\n').forEach((line) => {
        this.emit(` * ${line}\n`, level);
      });
      hasNextSection = true;
    }
    if (deprecated) {
      if (hasNextSection) {
        this.emit(' * \n', level);
      }
      const deprecatedText = deprecated.text.text.trimEnd();
      this.emit(' * @deprecated', level);
      deprecatedText.split('\n').forEach((line, index) => {
        if (index === 0) {
          this.emit(` ${line}\n`);
        } else {
          this.emit(` * ${line}\n`, level);
        }
      });
      hasNextSection = true;
    }
    if (params.length > 0) {
      if (hasNextSection) {
        this.emit(' * \n', level);
      }
      params.forEach((item) => {
        this.emit(` * @param ${item.name} - `, level);
        const items = item.text.trimEnd().split('\n');
        items.forEach((line, index) => {
          if (index === 0) {
            this.emit(`${line}\n`);
          } else {
            this.emit(` * ${line}\n`, level);
          }
        });
      });
    }
    if (returnText !== '') {
      this.emit(' * @returns', level);
      const returns = returnText.split('\n');
      returns.forEach((line, index) => {
        if (index === 0) {
          this.emit(` ${line}\n`);
        } else {
          this.emit(` * ${line}\n`, level);
        }
      });
    }
    if (throws.length > 0) {
      this.emit(' * \n', level);
      throws.forEach((item) => {
        this.emit(' * @throws', level);
        const items = item.trimEnd().split('\n');
        items.forEach((line, index) => {
          if (index === 0) {
            this.emit(` ${line}\n`);
          } else {
            this.emit(` * ${line}\n`, level);
          }
        });
      });
    }
    this.emit('"""', level);
    this.emit('\n');
  }