@Test public void testCountUntilCommentEnd() { { DefaultJavadocScanner scanner = string("*/"); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, true, 0); assertEquals(0, count); } { DefaultJavadocScanner scanner = string("*/ "); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, true, 0); assertEquals(0, count); } { DefaultJavadocScanner scanner = string("*****/ "); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, true, 0); assertEquals(4, count); } { DefaultJavadocScanner scanner = string("*****/ "); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, false, 0); assertEquals(4, count); } { DefaultJavadocScanner scanner = string("*****+/ "); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, true, 0); assertEquals(11, count); } { DefaultJavadocScanner scanner = string("*****+/ /* +/"); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, true, 0); assertEquals(-1, count); } { DefaultJavadocScanner scanner = string("*****+/ /* +/"); int count = JavadocScannerUtil.countUntilCommentEnd(scanner, false, 0); assertEquals(scanner.getTokens().size(), count); } }
public static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start) { JavadocToken token = scanner.lookahead(start); if (token.getKind() == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : 0); } int offset = 1; boolean sawAster = (token.getKind() == JavadocTokenKind.ASTERISK); while (true) { JavadocToken la = scanner.lookahead(start + offset); JavadocTokenKind kind = la.getKind(); if (kind == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : offset); } else if (sawAster && kind == JavadocTokenKind.SLASH) { offset--; return offset; } else if (kind == JavadocTokenKind.ASTERISK) { sawAster = true; offset++; } else { sawAster = false; offset++; } } }
JavadocScannerUtil { public static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start) { JavadocToken token = scanner.lookahead(start); if (token.getKind() == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : 0); } int offset = 1; boolean sawAster = (token.getKind() == JavadocTokenKind.ASTERISK); while (true) { JavadocToken la = scanner.lookahead(start + offset); JavadocTokenKind kind = la.getKind(); if (kind == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : offset); } else if (sawAster && kind == JavadocTokenKind.SLASH) { offset--; return offset; } else if (kind == JavadocTokenKind.ASTERISK) { sawAster = true; offset++; } else { sawAster = false; offset++; } } } }
JavadocScannerUtil { public static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start) { JavadocToken token = scanner.lookahead(start); if (token.getKind() == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : 0); } int offset = 1; boolean sawAster = (token.getKind() == JavadocTokenKind.ASTERISK); while (true) { JavadocToken la = scanner.lookahead(start + offset); JavadocTokenKind kind = la.getKind(); if (kind == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : offset); } else if (sawAster && kind == JavadocTokenKind.SLASH) { offset--; return offset; } else if (kind == JavadocTokenKind.ASTERISK) { sawAster = true; offset++; } else { sawAster = false; offset++; } } } private  JavadocScannerUtil(); }
JavadocScannerUtil { public static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start) { JavadocToken token = scanner.lookahead(start); if (token.getKind() == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : 0); } int offset = 1; boolean sawAster = (token.getKind() == JavadocTokenKind.ASTERISK); while (true) { JavadocToken la = scanner.lookahead(start + offset); JavadocTokenKind kind = la.getKind(); if (kind == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : offset); } else if (sawAster && kind == JavadocTokenKind.SLASH) { offset--; return offset; } else if (kind == JavadocTokenKind.ASTERISK) { sawAster = true; offset++; } else { sawAster = false; offset++; } } } private  JavadocScannerUtil(); static List<JavadocToken> lookaheadTokens(JavadocScanner scanner, int start, int count); static int countWhile(Collection<JavadocTokenKind> kinds, JavadocScanner scanner, int start); static int countUntil(Collection<JavadocTokenKind> kinds, JavadocScanner scanner, int start); static int countUntilBlockEnd(JavadocScanner scanner, int start); static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start); static int countUntilNextPrintable(JavadocScanner scanner, int start); static int countUntilNextLineStart(JavadocScanner scanner, int start); static int consumeLineEnd(JavadocScanner scanner, boolean multiline); }
JavadocScannerUtil { public static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start) { JavadocToken token = scanner.lookahead(start); if (token.getKind() == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : 0); } int offset = 1; boolean sawAster = (token.getKind() == JavadocTokenKind.ASTERISK); while (true) { JavadocToken la = scanner.lookahead(start + offset); JavadocTokenKind kind = la.getKind(); if (kind == JavadocTokenKind.EOF) { return (returnMinusIfMissing ? -1 : offset); } else if (sawAster && kind == JavadocTokenKind.SLASH) { offset--; return offset; } else if (kind == JavadocTokenKind.ASTERISK) { sawAster = true; offset++; } else { sawAster = false; offset++; } } } private  JavadocScannerUtil(); static List<JavadocToken> lookaheadTokens(JavadocScanner scanner, int start, int count); static int countWhile(Collection<JavadocTokenKind> kinds, JavadocScanner scanner, int start); static int countUntil(Collection<JavadocTokenKind> kinds, JavadocScanner scanner, int start); static int countUntilBlockEnd(JavadocScanner scanner, int start); static int countUntilCommentEnd(JavadocScanner scanner, boolean returnMinusIfMissing, int start); static int countUntilNextPrintable(JavadocScanner scanner, int start); static int countUntilNextLineStart(JavadocScanner scanner, int start); static int consumeLineEnd(JavadocScanner scanner, boolean multiline);  }