Package com.pogofish.jadt.ast

Examples of com.pogofish.jadt.ast.Doc


    /**
     * Test that when given an IOException occurs it is handled properly
     */
    @Test
    public void testIOException() {
        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 resultDoc = parser.parse(new Source() {

View Full Code Here


    /**
     * Happy path should give back the srcInfo
     */
    @Test
    public void testHappy() {
        final Doc testDoc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList());
        final DocEmitter dummyDocEmitter = new DummyDocEmitter(testDoc, "SomeClass");
        final StringSinkFactory factory = new StringSinkFactory("baseDir");
        dummyDocEmitter.emit(factory, testDoc);
        assertEquals("some source", factory.getResults().get("SomeClass"));
    }
View Full Code Here

    /**
     * Sending in a different doc should cause an exception
     */
    @Test
    public void testWrongDoc() {
        final Doc testDoc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList());
        final Doc doc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList());
        final DocEmitter dummyDocEmitter = new DummyDocEmitter(testDoc, "SomeClass");
        final StringSinkFactory factory = new StringSinkFactory("baseDir");
        try {
            dummyDocEmitter.emit(factory, doc);
            fail("Did not get an exception with the wrong doc, got " + factory.getResults().get("SomeClass"));
View Full Code Here

     * Create a dummy configged jADT based on the provided syntaxErrors, semanticErrors, testSrcInfo, and sink factory
     * Useful for testing
     */
    public static JADT createDummyJADT(List<SyntaxError> syntaxErrors, List<SemanticError> semanticErrors, String testSrcInfo, SinkFactoryFactory factory) {
        final SourceFactory sourceFactory = new StringSourceFactory(TEST_STRING);
        final Doc doc = new Doc(TEST_SRC_INFO, Pkg._Pkg(NO_COMMENTS, "pkg"), Util.<Imprt> list(), Util.<DataType> list());
        final ParseResult parseResult = new ParseResult(doc, syntaxErrors);
        final DocEmitter docEmitter = new DummyDocEmitter(doc,  TEST_CLASS_NAME);
        final Parser parser = new DummyParser(parseResult, testSrcInfo, TEST_STRING);
        final Checker checker = new DummyChecker(semanticErrors);
        final JADT jadt = new JADT(sourceFactory, parser, checker, docEmitter, factory);
View Full Code Here

                logger.fine("Parsing " + source.getSrcInfo());
                final BufferedReader reader = source.createReader();
                try {
                    final ParserImpl impl = factory.create(source.getSrcInfo(),
                            reader);
                    final Doc doc = impl.doc();
                    return new ParseResult(doc, impl.errors());
                } finally {
                    reader.close();
                }
            }
View Full Code Here

     * Test that docs print properly
     */
    @Test
    public void testDoc() {
        // empty doc
        assertEquals("", print(new Doc("PrinterTest", EMPTY_PKG, NO_IMPORTS, Util.<DataType> list())));
        // package
        assertEquals("package some.package\n\n",
                print(new Doc("PrinterTest", Pkg._Pkg(NO_COMMENTS, "some.package"), NO_IMPORTS, Util.<DataType> list())));
        // imports
        assertEquals("import number.one\nimport number.two\n\n",
                print(new Doc("PrinterTest", EMPTY_PKG, list(Imprt._Imprt(NO_COMMENTS, "number.one"), Imprt._Imprt(NO_COMMENTS,"number.two")), Util.<DataType> list())));
        // package and imports
        assertEquals("package some.package\n\nimport number.one\nimport number.two\n\n", print(new Doc(
                "PrinterTest", Pkg._Pkg(NO_COMMENTS, "some.package"), list(Imprt._Imprt(NO_COMMENTS, "number.one"), Imprt._Imprt(NO_COMMENTS,"number.two")), Util.<DataType> list())));
        // package, imports and datatypes
        assertEquals("package some.package\n\nimport number.one\nimport number.two\n\nFoo =\n    Bar\n", print(new Doc(
                "PrinterTest", Pkg._Pkg(NO_COMMENTS, "some.package"), list(Imprt._Imprt(NO_COMMENTS, "number.one"), Imprt._Imprt(NO_COMMENTS,"number.two")), list(new DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", Util.<String>list(), NO_EXTENDS, NO_IMPLEMENTS,
                        list(new Constructor(NO_COMMENTS, "Bar", Util.<Arg> list())))))));
    }
View Full Code Here

     */
    @Test
    public void testDuplicateDataType() {
        final Checker checker = new StandardChecker();
        final DataType dataType = new DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", Util.<String>list(), NO_EXTENDS, NO_IMPLEMENTS, list(new Constructor(NO_COMMENTS, "Foo", Util.<Arg>list())));
        final Doc doc = new Doc("CheckerTest", Pkg._Pkg(NO_COMMENTS, ""), NO_IMPORTS, list(dataType, dataType));
        final List<SemanticError> errors = checker.check(doc);
        assertEquals(1, errors.size());
        assertTrue(errors.contains(_DuplicateDataType(dataType.name)));
    }
View Full Code Here

    @Test
    public void testDuplicateConstructor() {
        final Checker checker = new StandardChecker();
        final Constructor constructor = new Constructor(NO_COMMENTS, "Bar", Util.<Arg>list());
        final DataType dataType = new DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", Util.<String>list(), NO_EXTENDS, NO_IMPLEMENTS, list(constructor, constructor));
        final Doc doc = new Doc("CheckerTest", Pkg._Pkg(NO_COMMENTS, ""), NO_IMPORTS, list(dataType));
        final List<SemanticError> errors = checker.check(doc);
        assertEquals(1, errors.size());
        assertTrue(errors.contains(_DuplicateConstructor(dataType.name, constructor.name)));
    }
View Full Code Here

    public void testConstructorDataTypeConflict() {
        final Checker checker = new StandardChecker();
        final Constructor constructor1 = new Constructor(NO_COMMENTS, "Bar", Util.<Arg>list());
        final Constructor constructor2 = new Constructor(NO_COMMENTS, "Foo", Util.<Arg>list());
        final DataType dataType = new DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", Util.<String>list(), NO_EXTENDS, NO_IMPLEMENTS, list(constructor1, constructor2));
        final Doc doc = new Doc("CheckerTest", Pkg._Pkg(NO_COMMENTS, ""), NO_IMPORTS, list(dataType));
        final List<SemanticError> errors = checker.check(doc);
        assertEquals(1, errors.size());
        assertTrue(errors.contains(_ConstructorDataTypeConflict(dataType.name)));
    }
View Full Code Here

    @Test
    public void testDuplicateArgName() {
        final Checker checker = new StandardChecker();
        final Constructor constructor = new Constructor(NO_COMMENTS, "Bar", list(Arg._Arg(Util.<ArgModifier>list(), Type._Primitive(PrimitiveType._IntType()), "foo"), Arg._Arg(Util.<ArgModifier>list(), Type._Primitive(PrimitiveType._BooleanType()), "foo")));
        final DataType dataType = new DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", Util.<String>list(), NO_EXTENDS, NO_IMPLEMENTS, list(constructor));
        final Doc doc = new Doc("CheckerTest", Pkg._Pkg(NO_COMMENTS, ""), NO_IMPORTS, list(dataType));
        final List<SemanticError> errors = checker.check(doc);
        assertEquals(1, errors.size());
        assertTrue(errors.contains(_DuplicateArgName(dataType.name, constructor.name, "foo")));      
    }
View Full Code Here

TOP

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

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.