2016-09-26 94 views
0

我正在使用MultiLineCommentDocumentationProvider来允许JavaDoc-like注释实体(使用/ ** * /)。Xtext:使用@annotations创建“JavaDoc”注释

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

有没有一种方法可以使用扩展Xtext的MultiLineCommentDocumentationProvider来支持上述?

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

应该看时鼠标悬停在someEntity等(或在某些参照它):

一些描述

myParam: PARAM描述

相反(现在看起来像):

一些说明@myparam参数说明

在此先感谢。

回答

0

随着基督教的建议下,我改变了 '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 
    } 
1

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