【问题标题】:Xtext: Creating "JavaDoc" comments with @annotationsXtext:使用@annotations 创建“JavaDoc”注释
【发布时间】:2017-02-03 10:00:33
【问题描述】:

我正在使用 MultiLineCommentDocumentationProvider 为实体提供类似 JavaDoc 的 cmets(使用 /** */)。

但是,如果我对某些参数使用 @(注解),它不会像 Java 中那样变粗,甚至在鼠标悬停时也不会换行。

有没有办法可以使用扩展 Xtext 的 MultiLineCommentDocumentationProvider 来支持上述内容?

例子

/** some description 
@myParam param description */
someEntity(Param myParam) {..}

当鼠标悬停在 someEntity(或对它的某个引用)上时应该看起来像:

一些描述

myParam:参数说明

而不是(目前看起来像):

一些描述@myparam 参数描述

提前致谢。

【问题讨论】:

    标签: parameters documentation comments javadoc xtext


    【解决方案1】:

    这不是MultiLineCommentDocumentationProvider 的默认功能。你可以使用XbaseHoverDocumentationProvider/XbaseHoverProvider 或者至少让你从中得到启发。

    【讨论】:

      【解决方案2】:

      按照 Christian 的建议,我以这种方式更改了“MyDSLMultiLineCommentDocumentationProvider”:

          @Override
          public String getDocumentation(EObject o) {
              String returnValue = findComment(o);
              String returnValueWithAnnotations = getAnnotatedDocumentation(returnValue);
              return getTextFromMultilineComment(returnValueWithAnnotations);
          }
      
          private String getAnnotatedDocumentation(String returnValue) {
            boolean isFirstAnnotationFound = false;
            StringBuilder result = new StringBuilder("");
          String[] splitted = returnValue.trim().split(" +");
          for (int i = 0; i < splitted.length; i++)
          {
            if (splitted[i].charAt(0) == '@')
            {
              if (! isFirstAnnotationFound)
              {
                result.append("<br><b>Parameters:</b>");
                isFirstAnnotationFound = true;
              }
              result.append("<br>"); //new line
              result.append("<b>"); //bold
              result.append(splitted[i].substring(1) + " "); // do not include "@"
              result.append("</b>");
            }
            else
            {
              result.append(splitted[i] + " ");
            }
          }
          String resultString = result.toString();
          return resultString.substring(0, resultString.length()-1); // getting rid of the strange "/" in the end
        }
      

      【讨论】:

        猜你喜欢
        • 2015-11-02
        • 1970-01-01
        • 2013-05-16
        • 1970-01-01
        • 2011-09-14
        • 2014-10-05
        • 2018-05-18
        • 2012-03-17
        • 2015-07-15
        相关资源
        最近更新 更多