Allow fluent use of BuildAction 11/65311/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Nov 2017 13:05:58 +0000 (14:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Nov 2017 09:36:44 +0000 (10:36 +0100)
This adds the ability to use BuildAction as a fluent builder, simplifying
users and their explicit dependencies.

Change-Id: I4eea2e0c56eb74a7ca0ae860bf00d11b988d54ef
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6874Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentSimplestTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveBuildTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportResolutionBasicTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MoreRevisionsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java

index 0d435ee6e9073de17587d96bca72d59c1762c7a6..f1c088f904649f042a6a69fb065067af489d69e2 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
 public class ConstraintDefinitionsTest {
@@ -38,11 +37,10 @@ public class ConstraintDefinitionsTest {
     @Test
     public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException,
             YangSyntaxErrorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
-        reactor.addSource(YangStatementStreamSource.create(
-            YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")));
-        final SchemaContext schemaContext = reactor.buildEffective();
+        final SchemaContext schemaContext = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(YangStatementStreamSource.create(
+                    YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")))
+                .buildEffective();
         assertNotNull(schemaContext);
 
         final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
index 95198e45c4764375b1b49e6c4079f2adf9a579eb..80967d484e3dbb9b96a233bc4912c9c8c09778fc 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.DescriptionStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IncludeStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ModuleStatementImpl;
@@ -85,19 +84,18 @@ public class Bug6874Test {
 
     @Test
     public void descriptionAndReferenceTest11() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(ROOT_MODULE, CHILD_MODULE, CHILD_MODULE_1, IMPORTED_MODULE);
-
-        reactor.build().getRootStatements().forEach(declaredStmt -> {
-            if (declaredStmt instanceof ModuleStatementImpl) {
-                declaredStmt.declaredSubstatements().forEach(subStmt -> {
-                    if (subStmt instanceof IncludeStatementImpl
-                            && subStmt.rawArgument().equals("child-module")) {
-                        subStmt.declaredSubstatements().forEach(Bug6874Test::verifyDescAndRef);
-                    }
-                });
-            }
-        });
+        YangInferencePipeline.RFC6020_REACTOR.newBuild()
+            .addSources(ROOT_MODULE, CHILD_MODULE, CHILD_MODULE_1, IMPORTED_MODULE)
+            .build().getRootStatements().forEach(declaredStmt -> {
+                if (declaredStmt instanceof ModuleStatementImpl) {
+                    declaredStmt.declaredSubstatements().forEach(subStmt -> {
+                        if (subStmt instanceof IncludeStatementImpl
+                                && subStmt.rawArgument().equals("child-module")) {
+                            subStmt.declaredSubstatements().forEach(Bug6874Test::verifyDescAndRef);
+                        }
+                    });
+                }
+            });
     }
 
     @SuppressWarnings("rawtypes")
index 9f96a0f26c50839879d380dc092b2a41a26d6e87..8d7f688e96eb7bc6fe14d86f763627d31a6b25b2 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
 public class AugmentProcessTest {
@@ -87,51 +86,41 @@ public class AugmentProcessTest {
 
     @Test
     public void multipleAugmentsAndMultipleModulesTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        addSources(reactor, MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED,
-                MULTIPLE_AUGMENT_SUBMODULE);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED, MULTIPLE_AUGMENT_SUBMODULE)
+                .buildEffective();
         assertNotNull(result);
     }
 
     @Test
     public void multipleAugmentTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        addSources(reactor, MULTIPLE_AUGMENT);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(MULTIPLE_AUGMENT)
+                .buildEffective();
         assertNotNull(result);
     }
 
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void multipleAugmentIncorrectPathTest() throws  ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        addSources(reactor, MULTIPLE_AUGMENT_INCORRECT);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(MULTIPLE_AUGMENT_INCORRECT)
+                .buildEffective();
         assertNull(result);
     }
 
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void multipleAugmentIncorrectPathAndGrpTest() throws  ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        addSources(reactor, MULTIPLE_AUGMENT_INCORRECT2);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(MULTIPLE_AUGMENT_INCORRECT2)
+                .buildEffective();
         assertNull(result);
     }
 
     @Test
     public void readAndParseYangFileTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        addSources(reactor, AUGMENTED, ROOT);
-
-        final SchemaContext root = reactor.buildEffective();
+        final SchemaContext root = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(AUGMENTED, ROOT)
+                .buildEffective();
         assertNotNull(root);
 
         final Module augmentedModule = root.findModules("augmented").iterator().next();
@@ -172,13 +161,6 @@ public class AugmentProcessTest {
         assertNotNull(grpAddNode);
     }
 
-    private static void addSources(final CrossSourceStatementReactor.BuildAction reactor,
-            final StatementStreamSource... sources) {
-        for (final StatementStreamSource source : sources) {
-            reactor.addSource(source);
-        }
-    }
-
     @Test
     public void caseShortHandAugmentingTest() throws Exception {
         final SchemaContext context = StmtTestUtils.parseYangSources("/choice-case-type-test-models");
index ce8c541d5d79138a021bec1fceda64474b290705..b6f8d39a09661110e3b117c502d56c6dd1c86974 100644 (file)
@@ -15,7 +15,6 @@ import org.junit.Test;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
@@ -27,10 +26,9 @@ public class AugmentSimplestTest {
 
     @Test
     public void readAndParseYangFileTest() throws SourceException, ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(AUGMENTED, ROOT);
-
-        EffectiveModelContext result = reactor.build();
+        EffectiveModelContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(AUGMENTED, ROOT)
+                .build();
         assertNotNull(result);
     }
 }
index bb1783ecf08ebd1016093f4eadf2c712f68dfb0f..59247e0ad3272c6b5cc55ca7142216ea47d7ef6e 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
 public class EffectiveBuildTest {
@@ -43,9 +42,8 @@ public class EffectiveBuildTest {
 
     @Test
     public void effectiveBuildTest() throws ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(SIMPLE_MODULE);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild().addSources(SIMPLE_MODULE)
+                .buildEffective();
 
         assertNotNull(result);
 
@@ -96,9 +94,7 @@ public class EffectiveBuildTest {
 
     @Test
     public void extensionsTest() throws ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(YANG_EXT);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild().addSource(YANG_EXT).buildEffective();
         assertNotNull(result);
 
         Set<GroupingDefinition> groupings = result.getGroupings();
@@ -118,10 +114,7 @@ public class EffectiveBuildTest {
 
     @Test
     public void mockTest() throws ReactorException, FileNotFoundException, URISyntaxException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSource(YANG_EXT);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild().addSource(YANG_EXT).buildEffective();
         assertNotNull(result);
     }
 }
index 2586233833a5cf84a40c29b290443dcf1769d3fa..2e832f03eda066b968a1f871ca3c9c36c7a4db88 100644 (file)
@@ -46,24 +46,24 @@ public class ImportResolutionBasicTest {
 
     @Test
     public void inImportOrderTest() throws ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED);
-        EffectiveModelContext result = reactor.build();
+        EffectiveModelContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED)
+                .build();
         assertNotNull(result);
     }
 
     @Test
     public void inInverseOfImportOrderTest() throws ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
-        EffectiveModelContext result = reactor.build();
+        EffectiveModelContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT)
+                .build();
         assertNotNull(result);
     }
 
     @Test
     public void missingImportedSourceTest() {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to missing imported source");
@@ -76,8 +76,8 @@ public class ImportResolutionBasicTest {
 
     @Test
     public void circularImportsTest() {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(CYCLE_YIN, CYCLE_YANG);
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(CYCLE_YIN, CYCLE_YANG);
         try {
             reactor.build();
             fail("reactor.process should fail due to circular import");
@@ -89,8 +89,8 @@ public class ImportResolutionBasicTest {
 
     @Test
     public void selfImportTest() {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to self import");
@@ -102,10 +102,9 @@ public class ImportResolutionBasicTest {
 
     @Test
     public void bug2649Test() throws ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(FOO, IMPORT);
-
-        SchemaContext buildEffective = reactor.buildEffective();
+        SchemaContext buildEffective = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(FOO, IMPORT)
+                .buildEffective();
         assertNotNull(buildEffective);
     }
 }
index 7e7552c153a3fef2afeff9ddbe486d0bb7feaef1..c5e807a729ee5f694d5b214af1a137c01b541992 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
 public class MoreRevisionsTest {
@@ -70,9 +69,7 @@ public class MoreRevisionsTest {
 
     @Test
     public void readAndParseYangFileTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSource(REVFILE);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild().addSource(REVFILE).buildEffective();
         assertNotNull(result);
         final Module moduleByName = result.getModules().iterator().next();
         assertEquals("2015-06-07", moduleByName.getQNameModule().getRevision().get().toString());
@@ -80,21 +77,17 @@ public class MoreRevisionsTest {
 
     @Test
     public void twoRevisionsTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
-        reactor.addSources(TED_20130712, TED_20131021, IETF_TYPES);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(TED_20130712, TED_20131021, IETF_TYPES)
+                .buildEffective();
         assertNotNull(result);
     }
 
     @Test
     public void twoRevisionsTest2() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
-        reactor.addSources(NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021, IETF_TYPES);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021, IETF_TYPES)
+                .buildEffective();
         assertNotNull(result);
         Set<Module> modules = result.getModules();
 
@@ -104,13 +97,10 @@ public class MoreRevisionsTest {
 
     @Test
     public void moreRevisionsListKeyTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-
-        reactor.addSources(TED_20130712, TED_20131021, ISIS_20130712,
-                ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES,
-                NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
-
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(TED_20130712, TED_20131021, ISIS_20130712, ISIS_20131021, L3_20130712, L3_20131021)
+                .addSources(IETF_TYPES,NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021)
+                .buildEffective();
         assertNotNull(result);
     }
 
index 8d39a4b678f8d222f39bb21d51d1de54ba8473d7..176764ee829c9c0724f4e1efecde9471e8533c54 100644 (file)
@@ -55,8 +55,7 @@ public final class TestUtils {
 
     public static SchemaContext loadModules(final URI resourceDirectory)
             throws ReactorException, IOException, YangSyntaxErrorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
         File[] files = new File(resourceDirectory).listFiles();
 
         for (File file : files) {
@@ -96,9 +95,9 @@ public final class TestUtils {
 
     public static Module loadYinModule(final YinTextSchemaSource source) throws ReactorException, SAXException,
             IOException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source)));
-        SchemaContext ctx = reactor.buildEffective();
+        final SchemaContext ctx = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source)))
+                .buildEffective();
         return ctx.getModules().iterator().next();
     }
 
index 8fe2a6af4b901e1e255570e904ad9e1831ccf505..3b27675a0658fbd26f3cdabb7d7d17850bd55d84 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 import org.opendaylight.yangtools.yang.stmt.TestUtils;
 import org.xml.sax.SAXException;
@@ -55,25 +55,25 @@ public class YinFileStmtTest {
 
     @Test
     public void readAndParseYinFileTestModel() throws SourceException, ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(YIN_FILE, EXT_FILE, EXT_USE_FILE);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(YIN_FILE, EXT_FILE, EXT_USE_FILE)
+                .buildEffective();
         assertNotNull(result);
     }
 
     // parsing yin file whose import statement references a module which does not exist
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void readAndParseInvalidYinFileTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(INVALID_YIN_FILE);
-        SchemaContext result = reactor.buildEffective();
+        SchemaContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(INVALID_YIN_FILE)
+                .buildEffective();
         assertNotNull(result);
     }
 
     // parsing yin file with duplicate key name in a list statement
     public void readAndParseInvalidYinFileTest2() {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(INVALID_YIN_FILE_2);
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSource(INVALID_YIN_FILE_2);
 
         try {
             reactor.buildEffective();
index 08b64eace3074629bc74a44754cbbd22a31e3da6..f22aed69ce96a9c981f1db74be457d450081c1c9 100644 (file)
@@ -102,9 +102,11 @@ public final class CrossSourceStatementReactor {
          *
          * @param source
          *            which should be added into main sources
+         * @return This build action, for fluent use.
          */
-        public void addSource(final StatementStreamSource source) {
+        public BuildAction addSource(final StatementStreamSource source) {
             context.addSource(source);
+            return this;
         }
 
         /**
@@ -112,15 +114,18 @@ public final class CrossSourceStatementReactor {
          *
          * @param sources
          *            which should be added into main sources
+         * @return This build action, for fluent use.
          */
-        public void addSources(final StatementStreamSource... sources) {
+        public BuildAction addSources(final StatementStreamSource... sources) {
             addSources(Arrays.asList(sources));
+            return this;
         }
 
-        public void addSources(final Collection<? extends StatementStreamSource> sources) {
+        public BuildAction addSources(final Collection<? extends StatementStreamSource> sources) {
             for (final StatementStreamSource source : sources) {
                 context.addSource(source);
             }
+            return this;
         }
 
         /**
@@ -132,15 +137,18 @@ public final class CrossSourceStatementReactor {
          *
          * @param libSources
          *            yang sources which should be added into library sources
+         * @return This build action, for fluent use.
          */
-        public void addLibSources(final StatementStreamSource... libSources) {
+        public BuildAction addLibSources(final StatementStreamSource... libSources) {
             addLibSources(Arrays.asList(libSources));
+            return this;
         }
 
-        public void addLibSources(final Collection<StatementStreamSource> libSources) {
+        public BuildAction addLibSources(final Collection<StatementStreamSource> libSources) {
             for (final StatementStreamSource libSource : libSources) {
                 context.addLibSource(libSource);
             }
+            return this;
         }
 
         /**
@@ -150,11 +158,13 @@ public final class CrossSourceStatementReactor {
          * @param supportedFeatures
          *            Set of supported features in the final SchemaContext.
          *            If the set is empty, no features encountered will be supported.
+         * @return This build action, for fluent use.
          */
-        public void setSupportedFeatures(@Nonnull final Set<QName> supportedFeatures) {
+        public BuildAction setSupportedFeatures(@Nonnull final Set<QName> supportedFeatures) {
             checkState(!supportedFeaturesSet, "Supported features should be set only once.");
             context.setSupportedFeatures(requireNonNull(supportedFeatures));
             supportedFeaturesSet = true;
+            return this;
         }
 
         /**
@@ -164,12 +174,14 @@ public final class CrossSourceStatementReactor {
          * @param modulesDeviatedByModules
          *            Map of YANG modules (Map key) which can be deviated by specified modules (Map value) in the final
          *            SchemaContext. If the map is empty, no deviations encountered will be supported.
+         * @return This build action, for fluent use.
          */
-        public void setModulesWithSupportedDeviations(
+        public BuildAction setModulesWithSupportedDeviations(
                 @Nonnull final Map<QNameModule, Set<QNameModule>> modulesDeviatedByModules) {
             checkState(!modulesDeviatedByModulesSet, "Modules with supported deviations should be set only once.");
             context.setModulesDeviatedByModules(requireNonNull(modulesDeviatedByModules));
             modulesDeviatedByModulesSet = true;
+            return this;
         }
 
         /**