@Test public void testFetchMethod() { { DefaultJavadocScanner scanner = string("String#length(){"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("String", elem.getDeclaringType().getName().asString()); assertEquals("length", elem.getName().asString()); assertEquals(0, elem.getParameters().size()); assertEquals(LEFT_BRACE, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("#length(){"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertNull(elem.getDeclaringType()); assertEquals("length", elem.getName().asString()); assertEquals(0, elem.getParameters().size()); assertEquals(LEFT_BRACE, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Math#abs(int)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Math", elem.getDeclaringType().getName().asString()); assertEquals("abs", elem.getName().asString()); assertEquals(1, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertNull(param.getName()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Math#abs(int number)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Math", elem.getDeclaringType().getName().asString()); assertEquals("abs", elem.getName().asString()); assertEquals(1, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertFalse(param.isVariableArity()); assertNotNull(param.getName()); assertEquals("number", param.getName().getIdentifier()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Arrays#asList(Object...)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Arrays", elem.getDeclaringType().getName().asString()); assertEquals("asList", elem.getName().asString()); assertEquals(1, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.NAMED_TYPE, param.getType().getKind()); assertEquals("Object", ((IrDocNamedType) param.getType()).getName().asString()); assertTrue(param.isVariableArity()); assertNull(param.getName()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Arrays#asList(Object...elems)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Arrays", elem.getDeclaringType().getName().asString()); assertEquals("asList", elem.getName().asString()); assertEquals(1, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.NAMED_TYPE, param.getType().getKind()); assertEquals("Object", ((IrDocNamedType) param.getType()).getName().asString()); assertTrue(param.isVariableArity()); assertNotNull(param.getName()); assertEquals("elems", param.getName().getIdentifier()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Math#max(int, int)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Math", elem.getDeclaringType().getName().asString()); assertEquals("max", elem.getName().asString()); assertEquals(2, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertFalse(param.isVariableArity()); assertNull(param.getName()); } { IrDocMethodParameter param = elem.getParameters().get(1); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertFalse(param.isVariableArity()); assertNull(param.getName()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("Math#max(int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNotNull(elem); assertEquals("Math", elem.getDeclaringType().getName().asString()); assertEquals("max", elem.getName().asString()); assertEquals(2, elem.getParameters().size()); { IrDocMethodParameter param = elem.getParameters().get(0); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertFalse(param.isVariableArity()); assertNotNull(param.getName()); assertEquals("a", param.getName().getIdentifier()); } { IrDocMethodParameter param = elem.getParameters().get(1); assertEquals(IrDocElementKind.BASIC_TYPE, param.getType().getKind()); assertEquals(IrBasicTypeKind.INT, ((IrDocBasicType) param.getType()).getTypeKind()); assertFalse(param.isVariableArity()); assertNotNull(param.getName()); assertEquals("b", param.getName().getIdentifier()); } assertEquals(EOF, scanner.lookahead(0).getKind()); } { DefaultJavadocScanner scanner = string("/Math#max(int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math+#max(int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#+max(int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max+(int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max(+int a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max(int *a, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max(int a+, int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max(int a int b)"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("Math#max(int a, int b"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, null); assertNull(elem); assertEquals(0, scanner.getIndex()); } { DefaultJavadocScanner scanner = string("String#length(){"); IrDocMethod elem = JavadocBlockParserUtil.fetchMethod(scanner, EnumSet.of(WHITE_SPACES)); assertNull(elem); assertEquals(0, scanner.getIndex()); } }
public static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow) { JavadocTokenStream stream = new DefaultJavadocTokenStream(scanner); stream.mark(); IrDocMethod elem = fetchMethod(stream); if (!follows(stream, follow)) { stream.rewind(); return null; } else { stream.discard(); return elem; } }
JavadocBlockParserUtil { public static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow) { JavadocTokenStream stream = new DefaultJavadocTokenStream(scanner); stream.mark(); IrDocMethod elem = fetchMethod(stream); if (!follows(stream, follow)) { stream.rewind(); return null; } else { stream.discard(); return elem; } } }
JavadocBlockParserUtil { public static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow) { JavadocTokenStream stream = new DefaultJavadocTokenStream(scanner); stream.mark(); IrDocMethod elem = fetchMethod(stream); if (!follows(stream, follow)) { stream.rewind(); return null; } else { stream.discard(); return elem; } } private  JavadocBlockParserUtil(); }
JavadocBlockParserUtil { public static IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow) { JavadocTokenStream stream = new DefaultJavadocTokenStream(scanner); stream.mark(); IrDocMethod elem = fetchMethod(stream); if (!follows(stream, follow)) { stream.rewind(); return null; } else { stream.discard(); return elem; } } 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 IrDocMethod fetchMethod(JavadocScanner scanner, Set<JavadocTokenKind> follow) { JavadocTokenStream stream = new DefaultJavadocTokenStream(scanner); stream.mark(); IrDocMethod elem = fetchMethod(stream); if (!follows(stream, follow)) { stream.rewind(); return null; } else { stream.discard(); return elem; } } 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; }