Package com.pogofish.jadt.ast

Examples of com.pogofish.jadt.ast.ParseResult


     * Test the whole shebang with a minimal document
     */
    @Test
    public void testMinimal() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                "Foo = Foo"));

        assertEquals(new ParseResult(new Doc("ParserTest", EMPTY_PKG, NO_IMPORTS, list(_DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                list(_Constructor(NO_COMMENTS, "Foo", Util.<Arg> list()))))), Util.<SyntaxError>list()), result);
    }
View Full Code Here


    @Test
    public void testFull() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final String source = "//a pre-start comment\n//a start comment\npackage hello.world /* here are some imports */import wow.man import flim.flam "
                + "//an annotation comment\n@foo\n@foo(@bar)\n//datatype comment\nFooBar //equal comment\n= //constructor comment\nfoo //bar comment\n| //really a bar comment\nbar(int hey, final String[] yeah) whatever = whatever";
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                source));

        assertEquals(
                new ParseResult(new Doc(
                        "ParserTest",
                        Pkg._Pkg(list(_JavaEOLComment("//a pre-start comment"), _JavaEOLComment("//a start comment")), "hello.world"), list(Imprt._Imprt(list(IMPORTS_COMMENT), "wow.man"), Imprt._Imprt(NO_COMMENTS, "flim.flam")),
                        list(new DataType(list(_JavaEOLComment("//an annotation comment"), _JavaEOLComment("//datatype comment")), list(_Annotation("foo", Optional.<AnnotationElement>_None()), _Annotation("foo", _Some(_ElementValue(_AnnotationValueAnnotation(_Annotation("bar", Optional.<AnnotationElement>_None())))))),
                                "FooBar",
                                NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                                list(
                                        new Constructor(list(_JavaEOLComment("//equal comment"), _JavaEOLComment("//constructor comment")), "foo", Util
                                                .<Arg> list()),
                                        new Constructor(list(_JavaEOLComment("//bar comment"), _JavaEOLComment("//really a bar comment")),
                                                "bar",
                                                list(new Arg(Util
                                                        .<ArgModifier> list(),
                                                        _Primitive(_IntType()),
                                                        "hey"),
                                                        new Arg(
                                                                list(_Final()),
                                                                _Ref(_ArrayType(_Ref(_ClassType(
                                                                        "String",
                                                                        NO_ACTUAL_TYPE_ARGUMENTS)))),
                                                                "yeah"))))),
                                new DataType(NO_COMMENTS, NO_ANNOTATIONS, "whatever", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                                        list(new Constructor(NO_COMMENTS, "whatever", Util
                                                .<Arg> list()))))), Util.<SyntaxError>list()).toString(), result.toString());
    }
View Full Code Here

    @Test
   public void testError() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final String source = "//a start comment\npackage hello.world /* here are some imports */import wow.man import flim.flam "
                + "FooBar = foo | bar(int hey, final String[] yeah) whatever = int";
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                source));

        assertEquals(
                new ParseResult(new Doc(
                        "ParserTest",
                        Pkg._Pkg(list(_JavaEOLComment("//a start comment")), "hello.world"), list(Imprt._Imprt(list(IMPORTS_COMMENT), "wow.man"), Imprt._Imprt(NO_COMMENTS, "flim.flam")),
                        list(new DataType(NO_COMMENTS, NO_ANNOTATIONS,
                                "FooBar",
                                NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                                list(
                                        new Constructor(NO_COMMENTS, "foo", Util
                                                .<Arg> list()),
                                        new Constructor(NO_COMMENTS,
                                                "bar",
                                                list(new Arg(Util
                                                        .<ArgModifier> list(),
                                                        _Primitive(_IntType()),
                                                        "hey"),
                                                        new Arg(
                                                                list(_Final()),
                                                                _Ref(_ArrayType(_Ref(_ClassType(
                                                                        "String",
                                                                        NO_ACTUAL_TYPE_ARGUMENTS)))),
                                                                "yeah"))))),
                                new DataType(NO_COMMENTS, NO_ANNOTATIONS, "whatever", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                                        list(new Constructor(NO_COMMENTS, "BAD_IDENTIFIER_int@1", Util
                                                .<Arg> list()))))), list(SyntaxError._UnexpectedToken("a constructor name", "'int'", 2))).toString(), result.toString());
               
    }
View Full Code Here

    @Test
    public void testNonsense() throws Exception {
        // the old parser would get stuck in a loop with this extraneous >
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
       
        final ParseResult result = parser.parse(new StringSource("whatever", "FormalParameter = FormalParameter(final List<Modifier> modifiers>, final TypeRef type, final String name)"));
        assertEquals(ParseResult._ParseResult(Doc._Doc("whatever", EMPTY_PKG, NO_IMPORTS,
                list(_DataType(NO_COMMENTS, NO_ANNOTATIONS, "FormalParameter", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                        list(_Constructor(NO_COMMENTS, "FormalParameter",
                                list(_Arg(list(_Final()), _Ref(_ClassType("List", list(_ClassType("Modifier", NO_ACTUAL_TYPE_ARGUMENTS)))), "modifiers") /*,
                                     _Arg(list(_Final()), _Ref(_ClassType("TypeRef", Util.<RefType>list())), "type"),
                                     _Arg(list(_Final()), _Ref(_ClassType("String", Util.<RefType>list())), "name") */)
                                                ))))), list(SyntaxError._UnexpectedToken("')'", "'>'", 1))).toString(), result.toString());
    }
View Full Code Here

                };
            }
        });
       
        try {
            final ParseResult parseResult = parser.parse(source);
            fail("Did not get exception, got " + parseResult );
           
        } catch (RuntimeException caught) {
            assertEquals("Got wrong exception", thrown, caught.getCause());
        }
View Full Code Here

    @Test
    public void testExceptionHandling() {
        final Throwable thrown1 = new RuntimeException("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown1));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException caught) {
            assertSame("got wrong exception", thrown1, caught);
        }
       
        final Throwable thrown2 = new Error("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown2));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (Error caught) {
            assertSame("got wrong exception", thrown2, caught);
        }
       
        final Throwable thrown3 = new Exception("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown3));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException caught) {
            assertSame("got wrong exception", thrown3, caught.getCause());
        }
    }
View Full Code Here

    /**
     * Test that when given the source, and string the dummy parser gives back the testDoc
     */
    @Test
    public void testHappy() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        final ParseResult result = parser.parse(new StringSource("some source", "some string"));
        assertSame(testResult, result);
    }
View Full Code Here

    /**
     * Test that when given a different source string an exception occurs
     */
    @Test
    public void testWrongSourceString() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some source", "some other string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

    /**
     * Test that when given a different source info an exception occurs
     */
    @Test
    public void testWrongSourceInfo() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some other source", "some string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

    /**
     * Test that when given an additional source line an exception occurs
     */
    @Test
    public void testWrongExtraSource() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some source", "some string\nmore string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

TOP

Related Classes of com.pogofish.jadt.ast.ParseResult

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.