@Test public void testFetchText() { DefaultJavadocScanner scanner = scanner("testFetchText.txt"); { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertEquals("onlyIdentifier", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertEquals("Identifier with space", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertNull(text); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertEquals("head ", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LEFT_BRACE, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntil(EnumSet.of(JavadocTokenKind.RIGHT_BRACE), scanner, 0) + 1); offset = scanner.lookahead(0).getStartPosition(); text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertEquals(" tail", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertEquals(" <- 3spaces -> ", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, true, false); assertEquals("<- 3spaces -> ", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset + 3, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, true); assertEquals(" <- 3spaces ->", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { int offset = scanner.lookahead(0).getStartPosition(); IrDocText text = JavadocBlockParserUtil.fetchText(scanner, true, true); assertEquals("<- 3spaces ->", text.getContent()); assertNotNull(text.getLocation()); assertEquals(offset + 3, text.getLocation().getStartPosition()); assertEquals(text.getContent().length(), text.getLocation().getLength()); assertEquals(JavadocTokenKind.LINE_BREAK, scanner.lookahead(0).getKind()); scanner.consume(JavadocScannerUtil.countUntilNextLineStart(scanner, 0)); } { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); assertNull(text); } }
public static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; while (true) { offset += JavadocScannerUtil.countUntil(S_TEXT_DELIM, scanner, offset); JavadocTokenKind kind = scanner.lookahead(offset).getKind(); if (kind == LEFT_BRACE) { JavadocToken la = scanner.lookahead(offset + 1); if (la.getKind() == JavadocTokenKind.AT) { break; } offset++; } else { break; } } return consumeAsText(scanner, offset, trimHead, trimTail); }
JavadocBlockParserUtil { public static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; while (true) { offset += JavadocScannerUtil.countUntil(S_TEXT_DELIM, scanner, offset); JavadocTokenKind kind = scanner.lookahead(offset).getKind(); if (kind == LEFT_BRACE) { JavadocToken la = scanner.lookahead(offset + 1); if (la.getKind() == JavadocTokenKind.AT) { break; } offset++; } else { break; } } return consumeAsText(scanner, offset, trimHead, trimTail); } }
JavadocBlockParserUtil { public static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; while (true) { offset += JavadocScannerUtil.countUntil(S_TEXT_DELIM, scanner, offset); JavadocTokenKind kind = scanner.lookahead(offset).getKind(); if (kind == LEFT_BRACE) { JavadocToken la = scanner.lookahead(offset + 1); if (la.getKind() == JavadocTokenKind.AT) { break; } offset++; } else { break; } } return consumeAsText(scanner, offset, trimHead, trimTail); } private  JavadocBlockParserUtil(); }
JavadocBlockParserUtil { public static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; while (true) { offset += JavadocScannerUtil.countUntil(S_TEXT_DELIM, scanner, offset); JavadocTokenKind kind = scanner.lookahead(offset).getKind(); if (kind == LEFT_BRACE) { JavadocToken la = scanner.lookahead(offset + 1); if (la.getKind() == JavadocTokenKind.AT) { break; } offset++; } else { break; } } return consumeAsText(scanner, offset, trimHead, trimTail); } private  JavadocBlockParserUtil(); static T setLocation(T elem, JavadocToken start, JavadocToken stop); static T setLocation(T elem, IrLocation start, IrLocation stop); static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail); static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner); static int countWhileTagName(JavadocScanner scanner, int start); static IrDocSimpleName fetchSimpleName(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocName fetchName(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocBasicType fetchBasicType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocBasicType fetchPrimitiveType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocNamedType fetchNamedType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocType fetchType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocField fetchField(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocFragment fetchLinkTarget(JavadocScanner scanner, Set<JavadocTokenKind> follow); static String buildString(List<? extends JavadocToken> tokens); }
JavadocBlockParserUtil { public static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; while (true) { offset += JavadocScannerUtil.countUntil(S_TEXT_DELIM, scanner, offset); JavadocTokenKind kind = scanner.lookahead(offset).getKind(); if (kind == LEFT_BRACE) { JavadocToken la = scanner.lookahead(offset + 1); if (la.getKind() == JavadocTokenKind.AT) { break; } offset++; } else { break; } } return consumeAsText(scanner, offset, trimHead, trimTail); } private  JavadocBlockParserUtil(); static T setLocation(T elem, JavadocToken start, JavadocToken stop); static T setLocation(T elem, IrLocation start, IrLocation stop); static IrDocText fetchText(JavadocScanner scanner, boolean trimHead, boolean trimTail); static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner); static int countWhileTagName(JavadocScanner scanner, int start); static IrDocSimpleName fetchSimpleName(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocName fetchName(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocBasicType fetchBasicType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocBasicType fetchPrimitiveType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocNamedType fetchNamedType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocType fetchType(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocField fetchField(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow); static IrDocFragment fetchLinkTarget(JavadocScanner scanner, Set<JavadocTokenKind> follow); static String buildString(List<? extends JavadocToken> tokens); static final Set<JavadocTokenKind> S_WHITE; }