Search in sources :

Example 6 with AbstractInlineTagDefinition

use of org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition in project n4js by eclipse.

the class DocletParserTest method testParserResumesAfterUnkonwLineTag.

@SuppressWarnings("javadoc")
@Test
public void testParserResumesAfterUnkonwLineTag() {
    String in = "/** \n * @unkonwLineTag \n * @stubLineTagTitle1 \n * @stubLineTagTitle2 \n */";
    AbstractLineTagDefinition tag0 = new StubLineTagDefinition("stubLineTagTitle0");
    AbstractLineTagDefinition tag1 = new StubLineTagDefinition("stubLineTagTitle1");
    AbstractLineTagDefinition tag2 = new StubLineTagDefinition("stubLineTagTitle2");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag0, tag1, tag2)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    EList<LineTag> lineTags = doclet.getLineTags();
    assertEquals(2, lineTags.size());
    // assuming that list is as parsing order
    LineTag lineTag1 = lineTags.get(0);
    assertEquals("stubLineTagTitle1", lineTag1.getTitle().getTitle());
    LineTag lineTag2 = lineTags.get(1);
    assertEquals("stubLineTagTitle2", lineTag2.getTitle().getTitle());
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) AbstractLineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractLineTagDefinition) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Test(org.junit.Test)

Example 7 with AbstractInlineTagDefinition

use of org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition in project n4js by eclipse.

the class DocletParserTest method testJSDocParsing.

@SuppressWarnings("javadoc")
@Test
public void testJSDocParsing() {
    String in = "/** This is the description.\n * @stubLineTagTitle \n */";
    AbstractLineTagDefinition tag = new StubLineTagDefinition("stubLineTagTitle");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    Text descr = (Text) doclet.getContents().get(0);
    assertEquals("This is the description.", descr.getText());
    LineTag lineTag = doclet.getLineTags().get(0);
    assertEquals("stubLineTagTitle", lineTag.getTitle().getTitle());
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) AbstractLineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractLineTagDefinition) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Text(org.eclipse.n4js.jsdoc.dom.Text) Test(org.junit.Test)

Example 8 with AbstractInlineTagDefinition

use of org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition in project n4js by eclipse.

the class DocletParserTest method testTrailingDescriptionIsIgnored.

@SuppressWarnings("javadoc")
@Test
public void testTrailingDescriptionIsIgnored() {
    String in = "/** This is the description.\n * @stubLineTagTitle \n * Trailing description.\n */";
    AbstractLineTagDefinition tag = new StubLineTagDefinition("stubLineTagTitle");
    DocletParser docletParser = new DocletParser(new TagDictionary<>(Arrays.asList(tag)), new TagDictionary<AbstractInlineTagDefinition>());
    Doclet doclet = docletParser.parse(in);
    assertEquals(1, doclet.getContents().size());
    assertEquals(1, doclet.getContents().size());
    Text descr = (Text) doclet.getContents().get(0);
    assertEquals("This is the description.", descr.getText());
    LineTag lineTag = doclet.getLineTags().get(0);
    assertEquals("stubLineTagTitle", lineTag.getTitle().getTitle());
}
Also used : LineTag(org.eclipse.n4js.jsdoc.dom.LineTag) AbstractLineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractLineTagDefinition) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Text(org.eclipse.n4js.jsdoc.dom.Text) Test(org.junit.Test)

Example 9 with AbstractInlineTagDefinition

use of org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition in project n4js by eclipse.

the class DescriptionParser method parseRegion.

/**
 * Method used to parse Region encountered in text. Expects {@link JSDocCharScanner#nextNonWS()} to be beginning of
 * region. It will use provided {@link TagDictionary} to recognize parse region. If no tags will mach parsed region,
 * null is returned. If region is maching one of {@link InlineTag} definitions it will return result of parsing
 * region with given tag.
 *
 * @param scanner
 *            JSDocCharScanner with offset_ before region
 * @param inlineTagsDictinary
 *            Dictionary of tags used to parse given region
 * @return Returns instance of Tag if parsed successfully, null otherwise.
 */
Tag parseRegion(JSDocCharScanner scanner, TagDictionary<AbstractInlineTagDefinition> inlineTagsDictinary) {
    ScannerState stateBeforeRegion = scanner.saveState();
    char _char = scanner.nextNonWS();
    // unsafe if region is marked by more than one char
    if (!regionStart(_char)) {
        return null;
    }
    scanner.skipWS();
    JSDocToken tokenTitle = TagTitleTokenizer.INSTANCE.nextToken(scanner);
    if (tokenTitle != null) {
        ITagDefinition iTagDefinition = inlineTagsDictinary.getDefinition(tokenTitle.token);
        if (iTagDefinition != null) {
            TagTitle tagTitle = createTagTitle(tokenTitle, iTagDefinition);
            AbstractInlineTagDefinition tagDefinition = (AbstractInlineTagDefinition) iTagDefinition;
            // although start of the region will be parsed twice (e.g. tag
            // title) it allows given tag implementation to decide what to
            // do with whole region, also might be important for nested
            // regions detection.
            scanner.restoreState(stateBeforeRegion);
            InlineTag tag = (InlineTag) tagDefinition.parse(tagTitle, scanner);
            tag.setRange(tokenTitle.start, scanner.offset());
            return tag;
        } else {
            System.err.println("silent ignore of unrecognized InlineTag {" + tokenTitle.token + "}");
            return null;
        }
    }
    return null;
}
Also used : InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) TagTitle(org.eclipse.n4js.jsdoc.dom.TagTitle) ScannerState(org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)

Example 10 with AbstractInlineTagDefinition

use of org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition in project n4js by eclipse.

the class DocletDescriptionParserTest method testDescriptionWithUnknownInlineTag.

@SuppressWarnings("javadoc")
@Test
public void testDescriptionWithUnknownInlineTag() {
    String in = "/** This is the description with {@unkonwnInlineTag parsed as text} ..and finish description. \n */";
    AbstractInlineTagDefinition inlineTag = new StubInlineTagDefinition("inline");
    DocletParser docletParser = new DocletParser(null, new TagDictionary<>(Arrays.asList(inlineTag)));
    Doclet doclet = docletParser.parse(in);
    EList<ContentNode> contents = doclet.getContents();
    Text descr = (Text) contents.get(0);
    assertEquals("This is the description with {@unkonwnInlineTag parsed as text} ..and finish description.", descr.getText());
}
Also used : AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Text(org.eclipse.n4js.jsdoc.dom.Text) ContentNode(org.eclipse.n4js.jsdoc.dom.ContentNode) Test(org.junit.Test)

Aggregations

AbstractInlineTagDefinition (org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition)12 Doclet (org.eclipse.n4js.jsdoc.dom.Doclet)11 Test (org.junit.Test)11 AbstractLineTagDefinition (org.eclipse.n4js.jsdoc.tags.AbstractLineTagDefinition)8 Text (org.eclipse.n4js.jsdoc.dom.Text)7 LineTag (org.eclipse.n4js.jsdoc.dom.LineTag)6 ContentNode (org.eclipse.n4js.jsdoc.dom.ContentNode)3 InlineTag (org.eclipse.n4js.jsdoc.dom.InlineTag)3 Composite (org.eclipse.n4js.jsdoc.dom.Composite)2 TagValue (org.eclipse.n4js.jsdoc.dom.TagValue)2 ScannerState (org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)1 TagTitle (org.eclipse.n4js.jsdoc.dom.TagTitle)1