Search in sources :

Example 1 with InlineTag

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

the class DocletDescriptionParserTest method testParserResumesAfterUnkownInlineTag.

@SuppressWarnings("javadoc")
@Test
public void testParserResumesAfterUnkownInlineTag() {
    String in = "/** This is the description with {@unkonwnInlineTag parsed as text} ... text in between... {@inline tag description} ..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();
    Composite composite = (Composite) contents.get(0);
    ContentNode node0 = composite.getContents().get(0);
    ContentNode node1 = composite.getContents().get(1);
    ContentNode node2 = composite.getContents().get(2);
    Text descriptionText1 = (Text) node0;
    InlineTag descriptionInlineTag = (InlineTag) node1;
    Text descriptionText2 = (Text) node2;
    assertEquals("This is the description with {@unkonwnInlineTag parsed as text} ... text in between... ", descriptionText1.getText());
    assertEquals(" ..and finish description.", descriptionText2.getText());
    TagValue inlineDescription = descriptionInlineTag.getValueByKey(StubInlineTagDefinition.PARAM_VALUE);
    Text tValue = (Text) inlineDescription.getContents().get(0);
    assertEquals(" tag description", tValue.getText());
}
Also used : InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) Composite(org.eclipse.n4js.jsdoc.dom.Composite) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Text(org.eclipse.n4js.jsdoc.dom.Text) TagValue(org.eclipse.n4js.jsdoc.dom.TagValue) ContentNode(org.eclipse.n4js.jsdoc.dom.ContentNode) Test(org.junit.Test)

Example 2 with InlineTag

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

the class DocletDescriptionParserTest method testDescriptionWithInline.

@SuppressWarnings("javadoc")
@Test
public void testDescriptionWithInline() {
    String in = "/** This is the description with {@inline tag description} ..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();
    Composite composite = (Composite) contents.get(0);
    ContentNode node0 = composite.getContents().get(0);
    ContentNode node1 = composite.getContents().get(1);
    ContentNode node2 = composite.getContents().get(2);
    Text descriptionText1 = (Text) node0;
    InlineTag descriptionInlineTag = (InlineTag) node1;
    Text descriptionText2 = (Text) node2;
    assertEquals("This is the description with ", descriptionText1.getText());
    assertEquals(" ..and finish description.", descriptionText2.getText());
    TagValue inlineDescription = descriptionInlineTag.getValueByKey(StubInlineTagDefinition.PARAM_VALUE);
    Text tValue = (Text) inlineDescription.getContents().get(0);
    assertEquals(" tag description", tValue.getText());
}
Also used : InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) Composite(org.eclipse.n4js.jsdoc.dom.Composite) AbstractInlineTagDefinition(org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) Text(org.eclipse.n4js.jsdoc.dom.Text) TagValue(org.eclipse.n4js.jsdoc.dom.TagValue) ContentNode(org.eclipse.n4js.jsdoc.dom.ContentNode) Test(org.junit.Test)

Example 3 with InlineTag

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

the class InlineTagTest method testSimpleLineTag.

@SuppressWarnings("javadoc")
@Test
public void testSimpleLineTag() {
    String in = "/** Some Description {@inline me} some other text. \n */";
    AbstractInlineTagDefinition tag = new StubInlineTagDefinition("inline");
    DocletParser docletParser = new DocletParser(new TagDictionary<AbstractLineTagDefinition>(), new TagDictionary<>(Arrays.asList(tag)));
    Doclet doclet = docletParser.parse(in);
    EList<ContentNode> contents = doclet.getContents();
    Composite composite = (Composite) contents.get(0);
    ContentNode node0 = composite.getContents().get(0);
    ContentNode node1 = composite.getContents().get(1);
    ContentNode node2 = composite.getContents().get(2);
    Text descriptionText1 = (Text) node0;
    InlineTag descriptionInlineTag = (InlineTag) node1;
    Text descriptionText2 = (Text) node2;
    assertEquals("Some Description ", descriptionText1.getText());
    assertEquals(" some other text.", descriptionText2.getText());
    TagValue inlineDescription = descriptionInlineTag.getValueByKey(StubInlineTagDefinition.PARAM_VALUE);
    Text tValue = (Text) inlineDescription.getContents().get(0);
    assertEquals(" me", tValue.getText());
}
Also used : Composite(org.eclipse.n4js.jsdoc.dom.Composite) Text(org.eclipse.n4js.jsdoc.dom.Text) ContentNode(org.eclipse.n4js.jsdoc.dom.ContentNode) InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) Doclet(org.eclipse.n4js.jsdoc.dom.Doclet) DocletParser(org.eclipse.n4js.jsdoc.DocletParser) TagValue(org.eclipse.n4js.jsdoc.dom.TagValue) Test(org.junit.Test)

Example 4 with InlineTag

use of org.eclipse.n4js.jsdoc.dom.InlineTag 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 5 with InlineTag

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

the class DescriptionParser method parse.

/**
 * Returns Text if descriptions contains only text. If it contains any inline Tags, than returned composedContent
 * will contain multiple nodes, one for each inline tag and one for each text before/after/in between inline tags.
 * Order of data is preserved. Stops scanning for text when reaches end of comment or LineTag.
 *
 * InlineTags are identified based on dictionary provided with method call.
 */
public ContentNode parse(JSDocCharScanner scanner, TagDictionary<AbstractInlineTagDefinition> inlineTagsDictinary) {
    ComposedContent description = DomFactory.eINSTANCE.createComposedContent();
    if (!scanner.hasNext()) {
        return null;
    }
    if (nextIsTagTitle(scanner)) {
        return null;
    }
    int start = scanner.nextOffset();
    int end = start;
    StringBuilder strb = new StringBuilder();
    while (scanner.hasNext()) {
        char c = scanner.peek();
        if (regionStart(c)) {
            ScannerState st = scanner.saveState();
            InlineTag tag = (InlineTag) parseRegion(scanner, inlineTagsDictinary);
            if (tag != null) {
                saveTextTokens(description, start, end, strb);
                strb = new StringBuilder();
                start = end;
                description.getContents().add(tag);
                continue;
            } else {
                scanner.restoreState(st);
                if (start == end) {
                    assert false;
                }
            /*
					 * On unkown region just continue with text parsing
					 */
            // saveTextTokens(description, start, end, strb);
            // break;
            }
        }
        // consume c
        scanner.next();
        if (JSDocCharScanner.isNL(c)) {
            if (scanner.hasNext() && !nextIsTagTitle(scanner)) {
                end = scanner.offset();
            } else {
                break;
            }
        }
        strb.append(c);
        end = scanner.offset();
    }
    String pendingData = strb.toString();
    if (pendingData.isEmpty() == false) {
        saveTextTokens(description, start, end, strb);
    }
    switch(description.getContents().size()) {
        case 0:
            return null;
        case 1:
            return description.getContents().get(0);
        default:
            return description;
    }
}
Also used : InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) ComposedContent(org.eclipse.n4js.jsdoc.dom.ComposedContent) ScannerState(org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)

Aggregations

InlineTag (org.eclipse.n4js.jsdoc.dom.InlineTag)6 Composite (org.eclipse.n4js.jsdoc.dom.Composite)3 ContentNode (org.eclipse.n4js.jsdoc.dom.ContentNode)3 Doclet (org.eclipse.n4js.jsdoc.dom.Doclet)3 TagValue (org.eclipse.n4js.jsdoc.dom.TagValue)3 Text (org.eclipse.n4js.jsdoc.dom.Text)3 AbstractInlineTagDefinition (org.eclipse.n4js.jsdoc.tags.AbstractInlineTagDefinition)3 Test (org.junit.Test)3 ScannerState (org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)2 DocletParser (org.eclipse.n4js.jsdoc.DocletParser)1 ComposedContent (org.eclipse.n4js.jsdoc.dom.ComposedContent)1 TagTitle (org.eclipse.n4js.jsdoc.dom.TagTitle)1