use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.
the class DefaultInlineTagDefinition method parse.
@Override
public Tag parse(TagTitle title, JSDocCharScanner scanner) {
Tag tag = createInlineTag(title);
scanner.skipWS();
JSDocToken description = InlineTagTokenizer.INSTANCE.nextToken(scanner);
if (description != null) {
String raw = convertToText(description).getText();
int titleOff = raw.indexOf(title.getTitle());
int titleLen = title.getTitle().length();
int fix = titleOff + titleLen;
raw = raw.substring(fix);
Text text = DOM.createText();
text.setText(raw);
text.setBegin(description.start + fix);
text.setEnd(description.end);
addValue(tag, VALUE, text);
}
return tag;
}
use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.
the class RegionTokenizer method nextToken.
@Override
public JSDocToken nextToken(JSDocCharScanner scanner) {
int start = scanner.nextOffset();
if (!findMarker(scanner, startMarker)) {
return null;
}
StringBuilder strb = new StringBuilder();
if (includeMarkers) {
strb.append(startMarker);
} else {
start = scanner.nextOffset();
}
int nestedRegions = 0;
int end = start;
while (scanner.hasNext() && (allowLinebreaks || !scanner.skipped())) {
if (scanner.peek() == escapeChar) {
strb.append(scanner.next());
if (scanner.hasNext() && (allowLinebreaks || !scanner.skipped())) {
strb.append(scanner.next());
end = scanner.offset();
}
continue;
}
if (findMarker(scanner, startMarker)) {
if (nested) {
nestedRegions++;
}
strb.append(startMarker);
} else if (findMarker(scanner, endMarker)) {
if (nestedRegions == 0) {
if (includeMarkers) {
strb.append(endMarker);
end = scanner.offset();
}
return new JSDocToken(strb.toString(), start, end);
}
strb.append(endMarker);
nestedRegions--;
} else {
strb.append(scanner.next());
end = scanner.offset();
}
}
return null;
}
use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.
the class TagTitleTokenizerTest method test.
@SuppressWarnings("javadoc")
@Test
public void test() {
TagTitleTokenizer tokenizer = new TagTitleTokenizer();
assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test Hello World")));
assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test\nHello World")));
assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test\n * Hello World")));
assertNull(tokenizer.nextToken(new JSDocCharScanner("@ Hello World")));
assertNull(tokenizer.nextToken(new JSDocCharScanner("Test Hello World")));
assertNull(tokenizer.nextToken(new JSDocCharScanner("Test @Hello World")));
}
use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.
the class TextTokenizerTest method testLinebreak.
@SuppressWarnings("javadoc")
@Test
public void testLinebreak() {
TextTokenizer TEXT = TextTokenizer.INSTANCE;
assertEquals(new JSDocToken("Hello World\n", 7, 18), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n * Skipped */")));
assertEquals(new JSDocToken("Hello World", 7, 17), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n * @tag Skipped */")));
assertEquals(new JSDocToken("Hello World", 7, 17), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n */")));
}
use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.
the class TextTokenizerTest method testEmpty.
@SuppressWarnings("javadoc")
@Test
public void testEmpty() {
TextTokenizer TEXT = TextTokenizer.INSTANCE;
assertEquals(new JSDocToken("\n", 1, 1), TEXT.nextToken(new JSDocCharScanner("x\n cont", 1)));
assertNull(TEXT.nextToken(new JSDocCharScanner("x*/", 1)));
}
Aggregations