Package com.asakusafw.utils.java.internal.parser.javadoc.ir

Examples of com.asakusafw.utils.java.internal.parser.javadoc.ir.IrDocText


     * Test method for {@link JavadocBlockParserUtil#setLocation(IrDocElement, JavadocToken, JavadocToken)}.
     */
    @Test
    public void testSetLocationToken() {
        {
            IrDocElement elem = new IrDocText("text");
            JavadocToken start = new JavadocToken(JavadocTokenKind.IDENTIFIER, "id", 10);
            JavadocToken stop = new JavadocToken(JavadocTokenKind.IDENTIFIER, "id", 20);
            JavadocBlockParserUtil.setLocation(elem, start, stop);
            assertEquals(10, elem.getLocation().getStartPosition());
            assertEquals(12, elem.getLocation().getLength());
        }
        {
            IrDocElement elem = new IrDocText("text");
            JavadocToken start = new JavadocToken(JavadocTokenKind.IDENTIFIER, "id", 10);
            JavadocBlockParserUtil.setLocation(elem, start, start);
            assertEquals(10, elem.getLocation().getStartPosition());
            assertEquals(2, elem.getLocation().getLength());
        }
    }
View Full Code Here


     * Test method for {@link JavadocBlockParserUtil#setLocation(IrDocElement, IrLocation, IrLocation)}.
     */
    @Test
    public void testSetLocationLocation() {
        {
            IrDocElement elem = new IrDocText("text");
            IrLocation start = new IrLocation(10, 2);
            IrLocation stop = new IrLocation(20, 2);
            JavadocBlockParserUtil.setLocation(elem, start, stop);
            assertEquals(10, elem.getLocation().getStartPosition());
            assertEquals(12, elem.getLocation().getLength());
        }
        {
            IrDocElement elem = new IrDocText("text");
            IrLocation start = new IrLocation(10, 2);
            JavadocBlockParserUtil.setLocation(elem, start, start);
            assertEquals(10, elem.getLocation().getStartPosition());
            assertEquals(2, elem.getLocation().getLength());
        }
        {
            IrDocElement elem = new IrDocText("text");
            IrLocation fragment = new IrLocation(10, 2);
            JavadocBlockParserUtil.setLocation(elem, null, fragment);
            assertNull(elem.getLocation());
        }
        {
            IrDocElement elem = new IrDocText("text");
            IrLocation fragment = new IrLocation(10, 2);
            JavadocBlockParserUtil.setLocation(elem, fragment, null);
            assertNull(elem.getLocation());
        }
    }
View Full Code Here

    @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);
        }
    }
View Full Code Here

        assertEquals("code", block.getTagName());
        assertEquals(0, block.getLocation().getStartPosition());
        assertEquals(scanner.lookahead(0).getStartPosition(), block.getLocation().getLength());

        JavadocScanner bScanner = block.getBlockScanner();
        IrDocText inline = JavadocBlockParserUtil.fetchText(bScanner, false, false);
        assertEquals(" Hello, world!", inline.getContent());
        assertEquals(JavadocTokenKind.EOF, bScanner.lookahead(0).getKind());
    }
View Full Code Here

        assertEquals("code", block.getTagName());
        assertEquals(0, block.getLocation().getStartPosition());
        assertEquals(scanner.lookahead(0).getStartPosition(), block.getLocation().getLength());

        JavadocScanner bScanner = block.getBlockScanner();
        IrDocText inline = JavadocBlockParserUtil.fetchText(bScanner, false, false);
        assertEquals(" Hello, world! EOF->", inline.getContent());
        assertEquals(JavadocTokenKind.EOF, bScanner.lookahead(0).getKind());
    }
View Full Code Here

    @Override
    public IrDocBlock parse(String tag, JavadocScanner scanner) {
        IrDocBlock block = new IrDocBlock();
        block.setTag(tag);
        block.setFragments(Arrays.asList(new IrDocText(identifier)));
        return block;
    }
View Full Code Here

                    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;
View Full Code Here

        assert scanner != null;
        assert count >= 0;
        int mark = scanner.getIndex();
        List<JavadocToken> tokens = consumeTokens(scanner, count, trimHead,
            trimTail);
        IrDocText elem = buildText(tokens);
        if (elem == null) {
            scanner.seek(mark);
            return null;
        } else {
            return elem;
View Full Code Here

        assert tokens != null;
        if (tokens.isEmpty()) {
            return null;
        }
        String text = buildString(tokens);
        IrDocText elem = new IrDocText(text);
        JavadocToken start = tokens.get(0);
        JavadocToken stop = tokens.get(tokens.size() - 1);
        setLocation(elem, start, stop);
        return elem;
    }
View Full Code Here

            IrDocBlock block = parser.newBlock(null, Collections.<IrDocFragment>emptyList());
            assertNull(block.getTag());
            assertEquals(0, block.getFragments().size());
        }
        {
            IrDocText f0 = new IrDocText("Hello, world!");
            IrDocBlock block = parser.newBlock("code", Arrays.asList(f0));
            assertEquals("@code", block.getTag());
            assertEquals(1, block.getFragments().size());
            assertEquals(f0, block.getFragments().get(0));
        }
        {
            IrDocSimpleName f0 = new IrDocSimpleName("arg0");
            IrDocText f1 = new IrDocText("Hello!");
            IrDocText f2 = new IrDocText("This is text");
            IrDocBlock block = parser.newBlock("param", Arrays.<IrDocFragment>asList(f0, f1, f2));
            assertEquals("@param", block.getTag());
            assertEquals(3, block.getFragments().size());
            assertEquals(f0, block.getFragments().get(0));
            assertEquals(f1, block.getFragments().get(1));
View Full Code Here

TOP

Related Classes of com.asakusafw.utils.java.internal.parser.javadoc.ir.IrDocText

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.