@Test public void testFetchBlockInfoEmpty() { DefaultJavadocScanner scanner = scanner("empty-inline.txt"); JavadocBlockInfo block = JavadocBlockParserUtil.fetchBlockInfo(scanner); assertEquals(JavadocTokenKind.EOF, scanner.lookahead(0).getKind()); assertEquals("code", block.getTagName()); assertEquals(0, block.getLocation().getStartPosition()); assertEquals(scanner.lookahead(0).getStartPosition(), block.getLocation().getLength()); JavadocScanner bScanner = block.getBlockScanner(); assertEquals(JavadocTokenKind.EOF, bScanner.lookahead(0).getKind()); }
public static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; offset += JavadocScannerUtil.countUntilNextPrintable(scanner, offset); JavadocToken head = scanner.lookahead(offset); if (head.getKind() != LEFT_BRACE) { return null; } offset++; JavadocToken at = scanner.lookahead(offset); if (at.getKind() != AT) { return null; } offset++; int nameCount = countWhileTagName(scanner, offset); String tagName = buildString(JavadocScannerUtil.lookaheadTokens(scanner, offset, nameCount)); offset += nameCount; int blockEnd = JavadocScannerUtil.countUntil(S_INLINE_BLOCK_DELIM, scanner, offset); JavadocToken token = scanner.lookahead(offset + blockEnd); JavadocTokenKind kind = token.getKind(); if (kind == LEFT_BRACE) { blockEnd = 0; } boolean legalBlock = (kind == JavadocTokenKind.RIGHT_BRACE); JavadocToken tail = scanner.lookahead(offset + blockEnd); int startIndex = scanner.getIndex() + offset; int stopIndex = startIndex + blockEnd; int startPos = head.getStartPosition(); int endPos = tail.getStartPosition(); if (legalBlock) { endPos += tail.getText().length(); } IrLocation blockLocation = new IrLocation(startPos, endPos - startPos); DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(new ArrayList<>( scanner.getTokens().subList(startIndex, stopIndex)), endPos); scanner.consume(offset + blockEnd); if (legalBlock) { scanner.consume(1); } return new JavadocBlockInfo(tagName, blockScanner, blockLocation); }
JavadocBlockParserUtil { public static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; offset += JavadocScannerUtil.countUntilNextPrintable(scanner, offset); JavadocToken head = scanner.lookahead(offset); if (head.getKind() != LEFT_BRACE) { return null; } offset++; JavadocToken at = scanner.lookahead(offset); if (at.getKind() != AT) { return null; } offset++; int nameCount = countWhileTagName(scanner, offset); String tagName = buildString(JavadocScannerUtil.lookaheadTokens(scanner, offset, nameCount)); offset += nameCount; int blockEnd = JavadocScannerUtil.countUntil(S_INLINE_BLOCK_DELIM, scanner, offset); JavadocToken token = scanner.lookahead(offset + blockEnd); JavadocTokenKind kind = token.getKind(); if (kind == LEFT_BRACE) { blockEnd = 0; } boolean legalBlock = (kind == JavadocTokenKind.RIGHT_BRACE); JavadocToken tail = scanner.lookahead(offset + blockEnd); int startIndex = scanner.getIndex() + offset; int stopIndex = startIndex + blockEnd; int startPos = head.getStartPosition(); int endPos = tail.getStartPosition(); if (legalBlock) { endPos += tail.getText().length(); } IrLocation blockLocation = new IrLocation(startPos, endPos - startPos); DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(new ArrayList<>( scanner.getTokens().subList(startIndex, stopIndex)), endPos); scanner.consume(offset + blockEnd); if (legalBlock) { scanner.consume(1); } return new JavadocBlockInfo(tagName, blockScanner, blockLocation); } }
JavadocBlockParserUtil { public static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; offset += JavadocScannerUtil.countUntilNextPrintable(scanner, offset); JavadocToken head = scanner.lookahead(offset); if (head.getKind() != LEFT_BRACE) { return null; } offset++; JavadocToken at = scanner.lookahead(offset); if (at.getKind() != AT) { return null; } offset++; int nameCount = countWhileTagName(scanner, offset); String tagName = buildString(JavadocScannerUtil.lookaheadTokens(scanner, offset, nameCount)); offset += nameCount; int blockEnd = JavadocScannerUtil.countUntil(S_INLINE_BLOCK_DELIM, scanner, offset); JavadocToken token = scanner.lookahead(offset + blockEnd); JavadocTokenKind kind = token.getKind(); if (kind == LEFT_BRACE) { blockEnd = 0; } boolean legalBlock = (kind == JavadocTokenKind.RIGHT_BRACE); JavadocToken tail = scanner.lookahead(offset + blockEnd); int startIndex = scanner.getIndex() + offset; int stopIndex = startIndex + blockEnd; int startPos = head.getStartPosition(); int endPos = tail.getStartPosition(); if (legalBlock) { endPos += tail.getText().length(); } IrLocation blockLocation = new IrLocation(startPos, endPos - startPos); DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(new ArrayList<>( scanner.getTokens().subList(startIndex, stopIndex)), endPos); scanner.consume(offset + blockEnd); if (legalBlock) { scanner.consume(1); } return new JavadocBlockInfo(tagName, blockScanner, blockLocation); } private  JavadocBlockParserUtil(); }
JavadocBlockParserUtil { public static JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; offset += JavadocScannerUtil.countUntilNextPrintable(scanner, offset); JavadocToken head = scanner.lookahead(offset); if (head.getKind() != LEFT_BRACE) { return null; } offset++; JavadocToken at = scanner.lookahead(offset); if (at.getKind() != AT) { return null; } offset++; int nameCount = countWhileTagName(scanner, offset); String tagName = buildString(JavadocScannerUtil.lookaheadTokens(scanner, offset, nameCount)); offset += nameCount; int blockEnd = JavadocScannerUtil.countUntil(S_INLINE_BLOCK_DELIM, scanner, offset); JavadocToken token = scanner.lookahead(offset + blockEnd); JavadocTokenKind kind = token.getKind(); if (kind == LEFT_BRACE) { blockEnd = 0; } boolean legalBlock = (kind == JavadocTokenKind.RIGHT_BRACE); JavadocToken tail = scanner.lookahead(offset + blockEnd); int startIndex = scanner.getIndex() + offset; int stopIndex = startIndex + blockEnd; int startPos = head.getStartPosition(); int endPos = tail.getStartPosition(); if (legalBlock) { endPos += tail.getText().length(); } IrLocation blockLocation = new IrLocation(startPos, endPos - startPos); DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(new ArrayList<>( scanner.getTokens().subList(startIndex, stopIndex)), endPos); scanner.consume(offset + blockEnd); if (legalBlock) { scanner.consume(1); } return new JavadocBlockInfo(tagName, blockScanner, blockLocation); } 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 JavadocBlockInfo fetchBlockInfo(JavadocScanner scanner) { if (scanner == null) { throw new IllegalArgumentException("scanner"); } int offset = 0; offset += JavadocScannerUtil.countUntilNextPrintable(scanner, offset); JavadocToken head = scanner.lookahead(offset); if (head.getKind() != LEFT_BRACE) { return null; } offset++; JavadocToken at = scanner.lookahead(offset); if (at.getKind() != AT) { return null; } offset++; int nameCount = countWhileTagName(scanner, offset); String tagName = buildString(JavadocScannerUtil.lookaheadTokens(scanner, offset, nameCount)); offset += nameCount; int blockEnd = JavadocScannerUtil.countUntil(S_INLINE_BLOCK_DELIM, scanner, offset); JavadocToken token = scanner.lookahead(offset + blockEnd); JavadocTokenKind kind = token.getKind(); if (kind == LEFT_BRACE) { blockEnd = 0; } boolean legalBlock = (kind == JavadocTokenKind.RIGHT_BRACE); JavadocToken tail = scanner.lookahead(offset + blockEnd); int startIndex = scanner.getIndex() + offset; int stopIndex = startIndex + blockEnd; int startPos = head.getStartPosition(); int endPos = tail.getStartPosition(); if (legalBlock) { endPos += tail.getText().length(); } IrLocation blockLocation = new IrLocation(startPos, endPos - startPos); DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(new ArrayList<>( scanner.getTokens().subList(startIndex, stopIndex)), endPos); scanner.consume(offset + blockEnd); if (legalBlock) { scanner.consume(1); } return new JavadocBlockInfo(tagName, blockScanner, blockLocation); } 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; }