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());
}
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());
}
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());
}
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;
}
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;
}
}
Aggregations