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

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


        i1.setIdentifier("i1");
        i1.setAcceptable(Pattern.compile("a"));

        DefaultJavadocBlockParser parser = new DefaultJavadocBlockParser(Arrays.asList(i1));
        {
            IrDocBlock block = parser.parse(null, string(" Hello, world!"));
            assertNull(block.getTag());
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, TEXT);
        }
        {
            IrDocBlock block = parser.parse(null, string("{@a sample}"));
            assertNull(block.getTag());
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, BLOCK);
            assertMockBlockEquals(i1, "@a", fragments.get(0));
        }
        {
            IrDocBlock block = parser.parse(null, string("Hello, {@a THIS} world!"));
            assertNull(block.getTag());
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, TEXT, BLOCK, TEXT);
            assertTextEquals("Hello, ", fragments.get(0));
            assertMockBlockEquals(i1, "@a", fragments.get(1));
            assertTextEquals(" world!", fragments.get(2));
        }
View Full Code Here


     */
    @Test
    public void testNewBlock() {
        MockJavadocBlockParser parser = new MockJavadocBlockParser();
        {
            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));
            assertEquals(f2, block.getFragments().get(2));
        }
    }
View Full Code Here

     */
    public IrDocBlock newBlock(String tag, List<? extends IrDocFragment> fragments) {
        if (fragments == null) {
            throw new IllegalArgumentException("fragments"); //$NON-NLS-1$
        }
        IrDocBlock block = new IrDocBlock();
        block.setTag(tag);
        block.setFragments(fragments);
        return block;
    }
View Full Code Here

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

            throw new IllegalArgumentException("block"); //$NON-NLS-1$
        }
        String tag = block.getTagName();
        for (JavadocBlockParser parser: getBlockParsers()) {
            if (parser.canAccept(tag)) {
                IrDocBlock result = parser.parse(tag, block.getBlockScanner());
                result.setLocation(block.getLocation());
                return result;
            }
        }
        throw new MissingJavadocBlockParserException(tag, block.getLocation(), null);
    }
View Full Code Here

        int index = scanner.getIndex();
        try {
            JavadocInfo info = fetchJavadocInfo(scanner);
            List<IrDocBlock> blocks = new ArrayList<IrDocBlock>(info.getBlocks().size());
            for (JavadocBlockInfo b: info.getBlocks()) {
                IrDocBlock block = parseBlock(b);
                blocks.add(block);
            }
            IrDocComment elem = new IrDocComment();
            elem.setBlocks(blocks);
            elem.setLocation(info.getLocation());
View Full Code Here

        i4.setIdentifier("i4");

        MockJavadocBlockParser parser = new MockJavadocBlockParser(i1, i2, i3, i4);
        {
            JavadocBlockInfo block = new JavadocBlockInfo("a", string(""), new IrLocation(0, 1));
            IrDocBlock parsed = parser.parseBlock(block);
            assertEquals(new IrLocation(0, 1), parsed.getLocation());
            List<? extends IrDocFragment> fragments = parsed.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("i1", fragments.get(0));
        }
        {
            JavadocBlockInfo block = new JavadocBlockInfo("b", string(""), new IrLocation(0, 1));
            IrDocBlock parsed = parser.parseBlock(block);
            assertEquals(new IrLocation(0, 1), parsed.getLocation());
            List<? extends IrDocFragment> fragments = parsed.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("i2", fragments.get(0));
        }
        {
            JavadocBlockInfo block = new JavadocBlockInfo("c", string(""), new IrLocation(0, 1));
            IrDocBlock parsed = parser.parseBlock(block);
            assertEquals(new IrLocation(0, 1), parsed.getLocation());
            List<? extends IrDocFragment> fragments = parsed.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("i3", fragments.get(0));
        }
        {
            JavadocBlockInfo block = new JavadocBlockInfo("d", string(""), new IrLocation(0, 1));
            IrDocBlock parsed = parser.parseBlock(block);
            assertEquals(new IrLocation(0, 1), parsed.getLocation());
            List<? extends IrDocFragment> fragments = parsed.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("i3", fragments.get(0));
        }
        {
            JavadocBlockInfo block = new JavadocBlockInfo("e", string(""), new IrLocation(0, 1));
            try {
                parser.parseBlock(block);
                fail();
            } catch (MissingJavadocBlockParserException e) {
                // ok.
                assertEquals("e", e.getTagName());
            }
        }
        {
            JavadocBlockInfo block = new JavadocBlockInfo(null, string(""), new IrLocation(0, 1));
            IrDocBlock parsed = parser.parseBlock(block);
            assertEquals(new IrLocation(0, 1), parsed.getLocation());
            List<? extends IrDocFragment> fragments = parsed.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("i4", fragments.get(0));
        }
    }
View Full Code Here

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

    @Test
    public void testParse() throws Exception {
        {
            ParamBlockParser parser = new ParamBlockParser();
            DefaultJavadocScanner scanner = string("a");
            IrDocBlock block = parser.parse("param", scanner);
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, SIMPLE_NAME);
            assertEquals("a", ((IrDocSimpleName) fragments.get(0)).getIdentifier());
        }
        {
            ParamBlockParser parser = new ParamBlockParser();
            DefaultJavadocScanner scanner = string("a a parameter");
            IrDocBlock block = parser.parse("param", scanner);
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, SIMPLE_NAME, TEXT);
            assertEquals("a", ((IrDocSimpleName) fragments.get(0)).getIdentifier());
            assertTextEquals(" a parameter", fragments.get(1));
        }
        {
            ParamBlockParser parser = new ParamBlockParser();
            DefaultJavadocScanner scanner = string("<T> a parameter");
            IrDocBlock block = parser.parse("param", scanner);
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, TEXT, SIMPLE_NAME, TEXT, TEXT);
            assertTextEquals("<", fragments.get(0));
            assertEquals("T", ((IrDocSimpleName) fragments.get(1)).getIdentifier());
            assertTextEquals(">", fragments.get(2));
            assertTextEquals(" a parameter", fragments.get(3));
        }
        {
            ParamBlockParser parser = new ParamBlockParser();
            DefaultJavadocScanner scanner = string("<T< a parameter");
            IrDocBlock block = parser.parse("param", scanner);
            List<? extends IrDocFragment> fragments = block.getFragments();
            assertKinds(fragments, TEXT);
            assertTextEquals("<T< a parameter", fragments.get(0));
        }
    }
View Full Code Here

TOP

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

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.