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

Examples of com.asakusafw.utils.java.internal.parser.javadoc.ir.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


            DefaultJavadocScanner bs = new DefaultJavadocScanner(
                new ArrayList<JavadocToken>(tokens.subList(start + offset, start + offset + count)),
                success);
            JavadocToken first = scanner.lookahead(offset);
            int init = first.getStartPosition();
            IrLocation location = new IrLocation(init, success - init);
            JavadocBlockInfo info = new JavadocBlockInfo(null, bs, location);
            scanner.consume(offset + count);
            return info;
        }
    }
View Full Code Here

            T elem,
            JavadocToken start,
            JavadocToken stop) {
        int s = start.getStartPosition();
        int e = stop.getStartPosition() + stop.getText().length();
        IrLocation location = new IrLocation(s, e - s);
        elem.setLocation(location);
        return elem;
    }
View Full Code Here

        if (start == null || stop == null) {
            return elem;
        }
        int s = start.getStartPosition();
        int e = stop.getStartPosition() + stop.getLength();
        IrLocation location = new IrLocation(s, e - s);
        elem.setLocation(location);
        return elem;
    }
View Full Code Here

        int endPos = tail.getStartPosition();
        if (legalBlock) {
            endPos += tail.getText().length();
        }

        IrLocation blockLocation = new IrLocation(startPos, endPos - startPos);
        DefaultJavadocScanner blockScanner = new DefaultJavadocScanner(
            new ArrayList<JavadocToken>(scanner.getTokens().subList(startIndex,
            stopIndex)),
            endPos);
View Full Code Here

            stream.rewind();
            return null;
        } else {
            stream.discard();
        }
        IrLocation delim = type.getLocation();
        boolean varargs;
        if (consumeIfMatch(stream, DOT) != null) {
            if ((stream.lookahead(0).getKind() != DOT)
                    || (stream.lookahead(1).getKind() != DOT)) {
                stream.rewind();
View Full Code Here

    }

    private static JavadocInfo fetchJavadocInfo(JavadocScanner scanner) throws IllegalDocCommentFormatException {
        int offset = 0;

        IrLocation firstLocation = scanner.lookahead(0).getLocation();

        // "/" "*" "*"
        if (!hasJavadocHead(scanner, offset)) {
            throw new IllegalDocCommentFormatException(true, scanner.lookahead(0).getLocation(), null);
        }
        offset += 3;

        // "/" "*" "*" "/" の回避
        if (scanner.lookahead(offset).getKind() == JavadocTokenKind.SLASH) {
            throw new IllegalDocCommentFormatException(true, scanner.lookahead(0).getLocation(), null);
        }

        // 本体ブロックの取得
        int bodyStart = offset;
        offset += JavadocScannerUtil.countUntilCommentEnd(scanner, false, offset);
        int bodyEnd = offset;

        // "*" "/"
        if (!hasJavadocTail(scanner, offset)) {
            throw new IllegalDocCommentFormatException(false, scanner.lookahead(0).getLocation(), null);
        }

        IrLocation lastLocation = scanner.lookahead(offset + 1).getLocation();

        // Javadocの中身のみをスキャンするスキャナ
        int base = scanner.getIndex();
        JavadocScanner bodyScanner = new DefaultJavadocScanner(
            scanner.getTokens().subList(base + bodyStart, base + bodyEnd),
            scanner.lookahead(offset).getStartPosition());

        List<JavadocBlockInfo> blockScanners = splitBlocks(bodyScanner);

        int locStart = firstLocation.getStartPosition();
        int locEnd = lastLocation.getStartPosition() + lastLocation.getLength();
        IrLocation location = new IrLocation(locStart, locEnd - locStart);
        scanner.consume(offset);
        return new JavadocInfo(location, blockScanners);
    }
View Full Code Here

        int success = scanner.lookahead(count).getStartPosition();
        DefaultJavadocScanner bs = new DefaultJavadocScanner(
            new ArrayList<JavadocToken>(tokens.subList(bodyStart, bodyStart + count)),
            success);
        int init = first.getStartPosition();
        IrLocation location = new IrLocation(init, success - init);
        JavadocBlockInfo info = new JavadocBlockInfo(tagName, bs, location);
        scanner.consume(count);

        return info;
    }
View Full Code Here

        i4.setAcceptable(Pattern.compile("<SYNOPSIS>"));
        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

TOP

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

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.