Fix Module.getVersion() 15/64515/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 19 Oct 2017 09:06:36 +0000 (11:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 19 Oct 2017 15:57:18 +0000 (17:57 +0200)
We should be returning YangVersion instead of a String, do exactly
that.

Change-Id: Ieeef1b8f1da9a5084d969cb217f7994374eea425
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java
yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java
yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/EffectiveSchemaContextEmitterTest.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleDependencySort.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java

index 1d39a77b3218e084d89552089211be32dd118928..68ae7c6108b79dce326d3a44d76468e9bf9cc5e2 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.Immutable;
 import org.opendaylight.yangtools.concepts.SemVer;
+import org.opendaylight.yangtools.yang.common.YangVersion;
 
 /**
  * This interface contains the methods for getting the data from the YANG
@@ -76,14 +77,11 @@ public interface Module extends DataNodeContainer, ModuleIdentifier, Notificatio
     String getPrefix();
 
     /**
-     * Returns the YANG version. Default value is 1.
+     * Returns the YANG version.
      *
-     * @return string with the module YANG version which is specified as
-     *         argument of YANG {@link Module <b> <font
-     *         color="#8b4513">yang-version</font></b>} keyword
+     * @return YANG version of this module.
      */
-    // FIXME: version 2.0.0: return YangVersion
-    String getYangVersion();
+    YangVersion getYangVersion();
 
     /**
      * Returns the module description.
index ebfb5acfaf78872df49b6ba93c43128cc82df056..364e8f7a4e13d1deb256c22da8a5aa14247334e4 100644 (file)
@@ -199,17 +199,16 @@ abstract class SchemaContextEmitter {
              * augment) we can get declared form i.e. ModuleStatement and then
              * use DeclaredSchemaContextEmitter
              */
-            new DeclaredSchemaContextEmitter(yangSchemaWriter, extensions,
-                    YangVersion.parse(module.getYangVersion()).orElse(null))
-                            .emitModule(((EffectiveStatement<?, ?>) module).getDeclared());
+            new DeclaredSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion())
+            .emitModule(((EffectiveStatement<?, ?>) module).getDeclared());
         } else {
             /*
              * if we don't have access to declared form of supplied module or we
              * want to emit also instantiated statements (e.g. statements added
              * by uses or augment), we use EffectiveSchemaContextEmitter.
              */
-            new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions,
-                    YangVersion.parse(module.getYangVersion()).orElse(null), emitInstantiated).emitModule(module);
+            new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion(), emitInstantiated)
+            .emitModule(module);
         }
     }
 
@@ -1116,7 +1115,7 @@ abstract class SchemaContextEmitter {
                 } else if (child instanceof ConfigStatement) {
                     emitConfigNode((ConfigStatement) child);
                 } else if (child instanceof UnknownStatement) {
-                    emitUnknownStatementNode((UnknownStatement<?>) child);
+                    emitUnknownStatementNode(child);
                 }
             }
             super.writer.endNode();
@@ -1259,8 +1258,8 @@ abstract class SchemaContextEmitter {
             }
         }
 
-        private void emitYangVersionNode(final String input) {
-            super.writer.startYangVersionNode(input);
+        private void emitYangVersionNode(final YangVersion input) {
+            super.writer.startYangVersionNode(input.toString());
             super.writer.endNode();
         }
 
index 00b7403155735d60e1f2dfbdd0f5681b2d92f6f1..c7d683e7decb368f32431a5e7548744c3d7a519b 100644 (file)
@@ -30,7 +30,6 @@ import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -87,8 +86,8 @@ public class EffectiveSchemaContextEmitterTest {
                 prefixToNs);
         final YangModuleWriter yangSchemaWriter = SchemaToStatementWriterAdaptor.from(statementWriter);
         final Map<QName, StatementDefinition> extensions = ExtensionStatement.mapFrom(ctx.getExtensions());
-        new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions,
-                YangVersion.parse(module.getYangVersion()).orElse(null), emitInstantiated).emitModule(module);
+        new EffectiveSchemaContextEmitter(yangSchemaWriter, extensions, module.getYangVersion(), emitInstantiated)
+        .emitModule(module);
     }
 
     private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) {
index a424e70e391525a369373c9d37b27271bb177a0d..8bdd17c80d80ffe2b10524a187524f9bc70a7c64 100644 (file)
@@ -133,7 +133,7 @@ public final class ModuleDependencySort {
                  * If it is an yang 1 module, check imports: If module is imported twice with different
                  * revisions then throw exception
                  */
-                if (YangVersion.VERSION_1.toString().equals(module.getYangVersion())) {
+                if (module.getYangVersion() == YangVersion.VERSION_1) {
                     final Date impRevision = imported.get(toName);
                     if (impRevision != null && !impRevision.equals(toRevision)
                         && !DEFAULT_DATE_REV.equals(impRevision) && !DEFAULT_DATE_REV.equals(toRevision)) {
index 7e01ba968a44d99ac7afd28ae3eaac6634ba66ec..871d2878e9050ebb8af5acca1d686a893e7dd047 100644 (file)
@@ -299,8 +299,8 @@ abstract class AbstractEffectiveModule<D extends DeclaredStatement<String>> exte
     }
 
     @Override
-    public String getYangVersion() {
-        return yangVersion.toString();
+    public YangVersion getYangVersion() {
+        return yangVersion;
     }
 
     @Override
index 4803e52342a94320741c2a0dce8a250e02e571ba..f8aa9f917b15f4ced84ae8633b49fe80264a87c3 100644 (file)
@@ -84,7 +84,7 @@ public class EffectiveModuleTest {
         assertNotNull(rootModule);
 
         assertEquals("root-pref", rootModule.getPrefix());
-        assertEquals(YangVersion.VERSION_1.toString(), rootModule.getYangVersion());
+        assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion());
         assertEquals("cisco", rootModule.getOrganization());
         assertEquals("cisco email", rootModule.getContact());
 
index 855757d0276c58686be8df069ec6efcf53a87515..f6b0cefbe5f187a9764c25cd159c43f9d44b5627 100644 (file)
@@ -91,7 +91,7 @@ public class YangParserTest {
     @Test
     public void testHeaders() throws ParseException {
         assertEquals("foo", foo.getName());
-        assertEquals(YangVersion.VERSION_1.toString(), foo.getYangVersion());
+        assertEquals(YangVersion.VERSION_1, foo.getYangVersion());
         assertEquals(FOO.getNamespace(), foo.getNamespace());
         assertEquals("foo", foo.getPrefix());
 
index 47852d18ca4aafa4c3a6af56d3908f4b227078ae..ebe9c065945c0853deb1cc861568c3f54daf8953 100644 (file)
@@ -35,7 +35,7 @@ public class YinFileHeaderStmtsTest {
     public void testYinFileHeader() throws URISyntaxException {
         Module testModule = TestUtils.findModule(modules, "config").get();
 
-        assertEquals(YangVersion.VERSION_1.toString(), testModule.getYangVersion());
+        assertEquals(YangVersion.VERSION_1, testModule.getYangVersion());
         assertEquals(new URI("urn:opendaylight:params:xml:ns:yang:controller:config"), testModule.getNamespace());
         assertEquals("config", testModule.getPrefix());
     }