Fix AnnotationStatement definition 31/80731/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Mar 2019 20:37:13 +0000 (21:37 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Mar 2019 20:41:46 +0000 (21:41 +0100)
Annotation argument is required to be identifiers, which means their
argument really binds as a QName to the defining module. Change the
definition to reflect this fact.

This forces the argument to be validated properly as well as making
it easier to use.

Change-Id: Idca53d98517ab3627b4b555386bed6a740c3e66d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/rfc7952-model-api/src/main/java/org/opendaylight/yangtools/rfc7952/model/api/AnnotationEffectiveStatement.java
yang/rfc7952-model-api/src/main/java/org/opendaylight/yangtools/rfc7952/model/api/AnnotationStatement.java
yang/rfc7952-parser-support/src/main/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationStatementSupport.java

index 787f9c703559589994d51b8b7bad3f7327ddec1c..0cb9f3779b64cb511cdb5a3a29ce3c86946774f8 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.rfc7952.model.api;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 /**
@@ -15,7 +16,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
  * <a href="https://tools.ietf.org/html/rfc7952">RFC7952</a>.
  */
 @Beta
-public interface AnnotationEffectiveStatement extends EffectiveStatement<String, AnnotationStatement>,
+public interface AnnotationEffectiveStatement extends EffectiveStatement<QName, AnnotationStatement>,
         AnnotationSchemaNode {
 
 }
index 93d92c76d34d49d6024c9eea66b4d38f472b8978..aac43fb5437f1bce325a11dae949416341d7866a 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.rfc7952.model.api;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
 
 /**
@@ -15,6 +16,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
  * <a href="https://tools.ietf.org/html/rfc7952">RFC7952</a>.
  */
 @Beta
-public interface AnnotationStatement extends UnknownStatement<String> {
+public interface AnnotationStatement extends UnknownStatement<QName> {
 
 }
index 9a3337683dedfbe952df6338459e774264e0dfc9..85fdcc5c54e1de391ff235a4902cc3d3bda7cd4f 100644 (file)
@@ -29,29 +29,28 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 public final class AnnotationStatementSupport
-        extends AbstractStatementSupport<String, AnnotationStatement, AnnotationEffectiveStatement> {
+        extends AbstractStatementSupport<QName, AnnotationStatement, AnnotationEffectiveStatement> {
 
-    private static final class Declared extends AbstractDeclaredStatement<String> implements AnnotationStatement {
-        Declared(final StmtContext<String, ?, ?> context) {
+    private static final class Declared extends AbstractDeclaredStatement<QName> implements AnnotationStatement {
+        Declared(final StmtContext<QName, ?, ?> context) {
             super(context);
         }
 
         @Override
-        public String getArgument() {
+        public QName getArgument() {
             return argument();
         }
     }
 
-    private static final class Effective extends UnknownEffectiveStatementBase<String, AnnotationStatement>
+    private static final class Effective extends UnknownEffectiveStatementBase<QName, AnnotationStatement>
             implements AnnotationEffectiveStatement {
 
         private final TypeDefinition<?> type;
         private final SchemaPath path;
 
-        Effective(final StmtContext<String, AnnotationStatement, ?> ctx) {
+        Effective(final StmtContext<QName, AnnotationStatement, ?> ctx) {
             super(ctx);
-            path = ctx.coerceParentContext().getSchemaPath().get().createChild(
-                StmtContextUtils.parseIdentifier(ctx, argument()));
+            path = ctx.coerceParentContext().getSchemaPath().get().createChild(argument());
 
             final TypeEffectiveStatement<?> typeStmt = SourceException.throwIfNull(
                 firstSubstatementOfType(TypeEffectiveStatement.class), ctx.getStatementSourceReference(),
@@ -105,24 +104,23 @@ public final class AnnotationStatementSupport
     }
 
     @Override
-    public AnnotationStatement createDeclared(final StmtContext<String, AnnotationStatement, ?> ctx) {
+    public AnnotationStatement createDeclared(final StmtContext<QName, AnnotationStatement, ?> ctx) {
         return new Declared(ctx);
     }
 
     @Override
     public AnnotationEffectiveStatement createEffective(
-            final StmtContext<String, AnnotationStatement, AnnotationEffectiveStatement> ctx) {
+            final StmtContext<QName, AnnotationStatement, AnnotationEffectiveStatement> ctx) {
         return new Effective(ctx);
     }
 
     @Override
-    public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        // FIXME: validate this is in fact an identifier as per RFC7950 Section 6.2
-        return value;
+    public QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+        return StmtContextUtils.parseIdentifier(ctx, value);
     }
 
     @Override
-    public void onStatementAdded(final Mutable<String, AnnotationStatement, AnnotationEffectiveStatement> stmt) {
+    public void onStatementAdded(final Mutable<QName, AnnotationStatement, AnnotationEffectiveStatement> stmt) {
         final StatementDefinition parentDef = stmt.coerceParentContext().getPublicDefinition();
         SourceException.throwIf(YangStmtMapping.MODULE != parentDef && YangStmtMapping.SUBMODULE != parentDef,
                 stmt.getStatementSourceReference(),