Search in sources :

Example 1 with LineTag

use of org.eclipse.n4js.jsdoc.dom.LineTag in project n4js by eclipse.

the class LineTagTest method testLineTagDescr.

@SuppressWarnings("javadoc")
@Test
public void testLineTagDescr() {
    String in = "/** foo." + "\n * @stubLineTagTitle  tag description. " + "\n */";
    AbstractLineTagDefinition tag = new StubLineTagWithRegionDefinition("stubLineTagTitle");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    LineTag lineTag = doclet.getLineTags().get(0);
    TagValue vDescription = lineTag.getValueByKey(StubLineTagWithRegionDefinition.DESCR);
    Text tabDescription = (Text) vDescription.getContents().get(0);
    String deString = tabDescription.getText();
    assertEquals("tag description. ", deString);
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) DocletParser(org.eclipse.n4js.jsdoc.DocletParser) Text(org.eclipse.n4js.jsdoc.dom.Text) TagValue(org.eclipse.n4js.jsdoc.dom.TagValue) Test(org.junit.Test)

Example 2 with LineTag

use of org.eclipse.n4js.jsdoc.dom.LineTag in project n4js by eclipse.

the class LineTagTest method testSimpleLineTag.

@SuppressWarnings("javadoc")
@Test
public void testSimpleLineTag() {
    String in = "/** foo.\n * @stubLineTagTitle \n */";
    AbstractLineTagDefinition tag = new StubLineTagWithRegionDefinition("stubLineTagTitle");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    LineTag lineTag = doclet.getLineTags().get(0);
    assertEquals("stubLineTagTitle", lineTag.getTitle().getTitle());
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) DocletParser(org.eclipse.n4js.jsdoc.DocletParser) Test(org.junit.Test)

Example 3 with LineTag

use of org.eclipse.n4js.jsdoc.dom.LineTag in project n4js by eclipse.

the class LineTagTest method testLineTagWithRegionAndDescr.

@SuppressWarnings("javadoc")
@Test
public void testLineTagWithRegionAndDescr() {
    String in = "/** foo.\n * @stubLineTagTitle {@region value} tag description. \n */";
    AbstractLineTagDefinition tag = new StubLineTagWithRegionDefinition("stubLineTagTitle");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    LineTag lineTag = doclet.getLineTags().get(0);
    TagValue region = lineTag.getValueByKey(StubLineTagWithRegionDefinition.REGION);
    Text strcturedText = (Text) region.getContents().get(0);
    assertEquals("@region value", strcturedText.getText());
    TagValue vDescription = lineTag.getValueByKey(StubLineTagWithRegionDefinition.DESCR);
    Text tabDescription = (Text) vDescription.getContents().get(0);
    String deString = tabDescription.getText();
    assertEquals("tag description. ", deString);
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) DocletParser(org.eclipse.n4js.jsdoc.DocletParser) Text(org.eclipse.n4js.jsdoc.dom.Text) TagValue(org.eclipse.n4js.jsdoc.dom.TagValue) Test(org.junit.Test)

Example 4 with LineTag

use of org.eclipse.n4js.jsdoc.dom.LineTag in project n4js by eclipse.

the class DocletParser method parse.

/**
 * @param commentString
 *            Input string that will be parsed. Multiline comment expected.
 * @return Instance of Doclet (not null, but may have no contents).
 */
public Doclet parse(String commentString) {
    JSDocCharScanner scanner = new JSDocCharScanner(commentString);
    // parse main description
    Doclet doclet = parseMainDescription(scanner);
    TagTitleTokenizer tagTitleTokenizer = new TagTitleTokenizer();
    JSDocToken token;
    // TODO error handling
    while (null != (token = tagTitleTokenizer.nextToken(scanner))) {
        ITagDefinition tagDefinition = lineTagDictionary.getDefinition(token.token);
        int lineTagEnd = scanner.findLineTagEnd();
        scanner.fence(lineTagEnd);
        if (tagDefinition != null) {
            TagTitle tagTitle = createTagTitle(token, tagDefinition);
            LineTag tag = (LineTag) tagDefinition.parse(tagTitle, scanner, descriptionParser);
            tag.setRange(token.start, scanner.offset());
            doclet.getLineTags().add(tag);
        }
        scanner.unfence();
        scanner.setNextOffset(lineTagEnd);
    }
    doclet.setEnd(scanner.offset());
    return doclet;
}
Also used : TagTitleTokenizer(org.eclipse.n4js.jsdoc.tokenizers.TagTitleTokenizer) LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) TagTitle(org.eclipse.n4js.jsdoc.dom.TagTitle)

Example 5 with LineTag

use of org.eclipse.n4js.jsdoc.dom.LineTag in project n4js by eclipse.

the class JSDoc2HoverSerializer method caseDoclet.

@Override
public Boolean caseDoclet(Doclet doclet) {
    md2HtmlBuilder.resetMarkdownConverter();
    appendContents(doclet.getContents());
    // Reset md2HtmlBuilder to enforce all open blocks to closes, so that we have a defined status when
    // handling the line tags.
    md2HtmlBuilder.resetMarkdownConverter();
    Map<ITagDefinition, List<LineTag>> groupedLineTags = new HashMap<>();
    for (LineTag lineTag : doclet.getLineTags()) {
        ITagDefinition tagDef = lineTag.getTagDefinition();
        List<LineTag> group = groupedLineTags.get(tagDef);
        if (group == null) {
            group = new ArrayList<>(5);
            groupedLineTags.put(tagDef, group);
        }
        group.add(lineTag);
    }
    if (!groupedLineTags.isEmpty()) {
        md2HtmlBuilder.append("\n<dl>");
        for (ITagDefinition tagDef : N4JSDocletParser.N4JS_LINE_TAGS) {
            TagHandler tagHandler = LINETAG_HANDLERS.get(tagDef);
            if (tagHandler == null) {
                // default tag handler
                tagHandler = TAG_SECTION;
            }
            if (tagHandler != null) {
                List<LineTag> lineTags = groupedLineTags.get(tagDef);
                handleLineTags(tagDef, tagHandler, lineTags);
                // open/close dt/dd tags is handled appending tags directly
                // reset state to isolate tag line from each other
                md2HtmlBuilder.resetMarkdownConverter();
            }
        }
        md2HtmlBuilder.append("\n</dl>");
    }
    return false;
}
Also used : HashMap(java.util.HashMap) LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

LineTag (org.eclipse.n4js.jsdoc.dom.LineTag)19 Doclet (org.eclipse.n4js.jsdoc.dom.Doclet)14 Test (org.junit.Test)12 DocletParser (org.eclipse.n4js.jsdoc.DocletParser)6 Text (org.eclipse.n4js.jsdoc.dom.Text)6 AbstractInlineTagDefinition (org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition)6 AbstractLineTagDefinition (org.eclipse.n4js.jsdoc.tags.AbstractLineTagDefinition)6 FullMemberReference (org.eclipse.n4js.jsdoc.dom.FullMemberReference)3 TagValue (org.eclipse.n4js.jsdoc.dom.TagValue)3 ContentNode (org.eclipse.n4js.jsdoc.dom.ContentNode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 TagTitle (org.eclipse.n4js.jsdoc.dom.TagTitle)1 TagTitleTokenizer (org.eclipse.n4js.jsdoc.tokenizers.TagTitleTokenizer)1 TMember (org.eclipse.n4js.ts.types.TMember)1 TMethod (org.eclipse.n4js.ts.types.TMethod)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1