visitAnnotation()

in lib/generator.js [566:688]


  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();
    });

    let hasNextSection = false;
    this.emit(`/**\n`, level);
    const descriptionText = description ? description.text.text : '';
    const summaryText = summary ? summary.text.text : '';
    const returnText = _return ? _return.text.text.trimEnd() : '';
    if (descriptionText !== '') {
      this.emit(` * <b>description</b> :\n`, level);
      const descriptionTexts = md2Html(descriptionText).trimEnd();
      descriptionTexts.split('\n').forEach((line) => {
        this.emit(` * ${line}\n`, level);
      });
      hasNextSection = true;
    }
    if (summaryText !== '') {
      if (hasNextSection) {
        this.emit(` * \n`, level);
      }
      this.emit(` * <b>summary</b> : \n`, level);
      const summaryTexts = md2Html(summaryText).trimEnd();
      summaryTexts.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);
          }
        });
      });
      hasNextSection = true;
    }
    if (returnText !== '') {
      this.emit(` * @return `, level);
      const returns = returnText.split('\n');
      returns.forEach((line, index) => {
        if (index === 0) {
          this.emit(`${line}\n`);
        } else {
          this.emit(` * ${line}\n`, level);
        }
      });
      hasNextSection = true;
    }
    if (throws.length > 0) {
      if (hasNextSection) {
        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`);
    if (deprecated) {
      this.emit(`@Deprecated\n`, level);
    }
  }