@Test public void testFetchRestFragments() throws Exception { MockJavadocBlockParser inline = new MockJavadocBlockParser(); inline.setIdentifier("INLINE"); MockJavadocBlockParser parser = new MockJavadocBlockParser(inline); { DefaultJavadocScanner scanner = string(""); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertEquals(0, fragments.size()); } { DefaultJavadocScanner scanner = string("Single line"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, TEXT); assertTextEquals("Single line", fragments.get(0)); } { DefaultJavadocScanner scanner = string( "Multi\n" + "Lines"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, TEXT, TEXT); assertTextEquals("Multi", fragments.get(0)); assertTextEquals("Lines", fragments.get(1)); } { DefaultJavadocScanner scanner = string( "Formatted\n" + " * Text\n" + " * \n" + " * Sequence\n"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, TEXT, TEXT, TEXT); assertTextEquals("Formatted", fragments.get(0)); assertTextEquals("Text", fragments.get(1)); assertTextEquals("Sequence", fragments.get(2)); } { DefaultJavadocScanner scanner = string("{@code hello}"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, BLOCK); { IrDocBlock block = (IrDocBlock) fragments.get(0); assertEquals(0, block.getLocation().getStartPosition()); assertEquals("{@code hello}".length(), block.getLocation().getLength()); assertEquals("@code", block.getTag()); assertMockBlockEquals(inline, "@code", block); } } { DefaultJavadocScanner scanner = string("{@code hello}{@code world!}"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, BLOCK, BLOCK); { IrDocBlock block = (IrDocBlock) fragments.get(0); assertEquals(0, block.getLocation().getStartPosition()); assertEquals("{@code hello}".length(), block.getLocation().getLength()); assertEquals("@code", block.getTag()); assertMockBlockEquals(inline, "@code", block); } { IrDocBlock block = (IrDocBlock) fragments.get(1); assertEquals("{@code hello}".length(), block.getLocation().getStartPosition()); assertEquals("{@code world!}".length(), block.getLocation().getLength()); assertMockBlockEquals(inline, "@code", block); } } { DefaultJavadocScanner scanner = string( "This returns {@code null} {@code value}\n" + " * {@link Object}"); List<IrDocFragment> fragments = parser.fetchRestFragments(scanner); assertKinds(fragments, TEXT, BLOCK, TEXT, BLOCK, BLOCK); assertTextEquals("This returns ", fragments.get(0)); assertMockBlockEquals(inline, "@code", fragments.get(1)); assertTextEquals(" ", fragments.get(2)); assertMockBlockEquals(inline, "@code", fragments.get(3)); assertMockBlockEquals(inline, "@link", fragments.get(4)); } }
public List<IrDocFragment> fetchRestFragments(JavadocScanner scanner) throws JavadocParseException { int index = scanner.getIndex(); try { ArrayList<IrDocFragment> fragments = new ArrayList<>(); while (true) { JavadocTokenKind la = scanner.lookahead(0).getKind(); if (la == JavadocTokenKind.LINE_BREAK) { int count = JavadocScannerUtil.countUntilNextPrintable(scanner, 0); scanner.consume(count); } else if (la == JavadocTokenKind.LEFT_BRACE) { JavadocBlockInfo info = JavadocBlockParserUtil.fetchBlockInfo(scanner); IrDocBlock inline = parseBlock(info); fragments.add(inline); } else if (la == JavadocTokenKind.EOF) { break; } else { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); fragments.add(text); } } fragments.trimToSize(); return fragments; } catch (JavadocParseException e) { scanner.seek(index); throw e; } }
JavadocBlockParser extends JavadocBaseParser { public List<IrDocFragment> fetchRestFragments(JavadocScanner scanner) throws JavadocParseException { int index = scanner.getIndex(); try { ArrayList<IrDocFragment> fragments = new ArrayList<>(); while (true) { JavadocTokenKind la = scanner.lookahead(0).getKind(); if (la == JavadocTokenKind.LINE_BREAK) { int count = JavadocScannerUtil.countUntilNextPrintable(scanner, 0); scanner.consume(count); } else if (la == JavadocTokenKind.LEFT_BRACE) { JavadocBlockInfo info = JavadocBlockParserUtil.fetchBlockInfo(scanner); IrDocBlock inline = parseBlock(info); fragments.add(inline); } else if (la == JavadocTokenKind.EOF) { break; } else { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); fragments.add(text); } } fragments.trimToSize(); return fragments; } catch (JavadocParseException e) { scanner.seek(index); throw e; } } }
JavadocBlockParser extends JavadocBaseParser { public List<IrDocFragment> fetchRestFragments(JavadocScanner scanner) throws JavadocParseException { int index = scanner.getIndex(); try { ArrayList<IrDocFragment> fragments = new ArrayList<>(); while (true) { JavadocTokenKind la = scanner.lookahead(0).getKind(); if (la == JavadocTokenKind.LINE_BREAK) { int count = JavadocScannerUtil.countUntilNextPrintable(scanner, 0); scanner.consume(count); } else if (la == JavadocTokenKind.LEFT_BRACE) { JavadocBlockInfo info = JavadocBlockParserUtil.fetchBlockInfo(scanner); IrDocBlock inline = parseBlock(info); fragments.add(inline); } else if (la == JavadocTokenKind.EOF) { break; } else { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); fragments.add(text); } } fragments.trimToSize(); return fragments; } catch (JavadocParseException e) { scanner.seek(index); throw e; } } protected  JavadocBlockParser(); protected  JavadocBlockParser(List<? extends JavadocBlockParser> blockParsers); }
JavadocBlockParser extends JavadocBaseParser { public List<IrDocFragment> fetchRestFragments(JavadocScanner scanner) throws JavadocParseException { int index = scanner.getIndex(); try { ArrayList<IrDocFragment> fragments = new ArrayList<>(); while (true) { JavadocTokenKind la = scanner.lookahead(0).getKind(); if (la == JavadocTokenKind.LINE_BREAK) { int count = JavadocScannerUtil.countUntilNextPrintable(scanner, 0); scanner.consume(count); } else if (la == JavadocTokenKind.LEFT_BRACE) { JavadocBlockInfo info = JavadocBlockParserUtil.fetchBlockInfo(scanner); IrDocBlock inline = parseBlock(info); fragments.add(inline); } else if (la == JavadocTokenKind.EOF) { break; } else { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); fragments.add(text); } } fragments.trimToSize(); return fragments; } catch (JavadocParseException e) { scanner.seek(index); throw e; } } protected  JavadocBlockParser(); protected  JavadocBlockParser(List<? extends JavadocBlockParser> blockParsers); abstract boolean canAccept(String tag); abstract IrDocBlock parse(String tag, JavadocScanner scanner); IrDocBlock newBlock(String tag, List<? extends IrDocFragment> fragments); List<IrDocFragment> fetchRestFragments(JavadocScanner scanner); IrDocSimpleName fetchSimpleName(JavadocScanner scanner); IrDocName fetchName(JavadocScanner scanner); IrDocBasicType fetchBasicType(JavadocScanner scanner); IrDocBasicType fetchPrimitiveType(JavadocScanner scanner); IrDocNamedType fetchNamedType(JavadocScanner scanner); IrDocType fetchType(JavadocScanner scanner); IrDocField fetchField(JavadocScanner scanner); IrDocMethod fetchMethod(JavadocScanner scanner); IrDocFragment fetchLinkTarget(JavadocScanner scanner); }
JavadocBlockParser extends JavadocBaseParser { public List<IrDocFragment> fetchRestFragments(JavadocScanner scanner) throws JavadocParseException { int index = scanner.getIndex(); try { ArrayList<IrDocFragment> fragments = new ArrayList<>(); while (true) { JavadocTokenKind la = scanner.lookahead(0).getKind(); if (la == JavadocTokenKind.LINE_BREAK) { int count = JavadocScannerUtil.countUntilNextPrintable(scanner, 0); scanner.consume(count); } else if (la == JavadocTokenKind.LEFT_BRACE) { JavadocBlockInfo info = JavadocBlockParserUtil.fetchBlockInfo(scanner); IrDocBlock inline = parseBlock(info); fragments.add(inline); } else if (la == JavadocTokenKind.EOF) { break; } else { IrDocText text = JavadocBlockParserUtil.fetchText(scanner, false, false); fragments.add(text); } } fragments.trimToSize(); return fragments; } catch (JavadocParseException e) { scanner.seek(index); throw e; } } protected  JavadocBlockParser(); protected  JavadocBlockParser(List<? extends JavadocBlockParser> blockParsers); abstract boolean canAccept(String tag); abstract IrDocBlock parse(String tag, JavadocScanner scanner); IrDocBlock newBlock(String tag, List<? extends IrDocFragment> fragments); List<IrDocFragment> fetchRestFragments(JavadocScanner scanner); IrDocSimpleName fetchSimpleName(JavadocScanner scanner); IrDocName fetchName(JavadocScanner scanner); IrDocBasicType fetchBasicType(JavadocScanner scanner); IrDocBasicType fetchPrimitiveType(JavadocScanner scanner); IrDocNamedType fetchNamedType(JavadocScanner scanner); IrDocType fetchType(JavadocScanner scanner); IrDocField fetchField(JavadocScanner scanner); IrDocMethod fetchMethod(JavadocScanner scanner); IrDocFragment fetchLinkTarget(JavadocScanner scanner);  }