YANGTOOLS-706: Add TypedefEffectiveStatement.asTypeEffectiveStatement() 20/65420/7
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 10 Nov 2017 21:40:58 +0000 (22:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 11 Nov 2017 13:43:52 +0000 (14:43 +0100)
This is a bridge method from typedef to the effective type statement,
e.g. the use of a typedef. Promote it from implementation-specific
method to API contract, allowing TypedefEffectiveStatementImpl to be
hidden.

Change-Id: Idd149a2e2c16706c6b6c5cbe79f908907b2ccf89
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/TypedefEffectiveStatement.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/typedef/TypedefEffectiveStatementImpl.java

index de8511de17b0af6f37d2af8e08cd0bb2f0da61d8..f030d0a3f3990db3e83ffe1c30ff2007e997d503 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
@@ -15,4 +17,11 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
  */
 public interface TypedefEffectiveStatement extends EffectiveStatement<QName, TypedefStatement>, TypeDefinitionAware {
 
+    /**
+     * Return this type definition as an effective type statement.
+     *
+     * @return Effective type statement.
+     */
+    @Beta
+    @Nonnull TypeEffectiveStatement<TypeStatement> asTypeEffectiveStatement();
 }
index 195cc9200f0ea80b236d22e7b83bb3c1fb85ad3e..467579c0fc2fbd0a4050fe0f404e3fe14389f6ad 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
-import com.google.common.base.Verify;
 import com.google.common.collect.ImmutableMap;
 import java.util.Collection;
 import java.util.Map;
@@ -39,7 +38,6 @@ import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.typedef.TypedefEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@@ -148,10 +146,7 @@ abstract class AbstractTypeStatementSupport
                 final StmtContext<?, TypedefStatement, TypedefEffectiveStatement> typedef =
                         SourceException.throwIfNull(ctx.getFromNamespace(TypeNamespace.class, qname),
                             ctx.getStatementSourceReference(), "Type '%s' not found", qname);
-
-                final TypedefEffectiveStatement effectiveTypedef = typedef.buildEffective();
-                Verify.verify(effectiveTypedef instanceof TypedefEffectiveStatementImpl);
-                typeStmt = ((TypedefEffectiveStatementImpl) effectiveTypedef).asTypeEffectiveStatement();
+                typeStmt = typedef.buildEffective().asTypeEffectiveStatement();
         }
 
         if (ctx.declaredSubstatements().isEmpty() && ctx.effectiveSubstatements().isEmpty()) {
index 5f882f10b5724ae7486d238fe0168b61af857771..5ebc860312995b4f69ed3a67fdee9b4a82ec79c5 100644 (file)
@@ -36,8 +36,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-// FIXME: hide this class
-public final class TypedefEffectiveStatementImpl extends AbstractEffectiveSchemaNode<TypedefStatement> implements
+final class TypedefEffectiveStatementImpl extends AbstractEffectiveSchemaNode<TypedefStatement> implements
         TypedefEffectiveStatement {
     private static final Logger LOG = LoggerFactory.getLogger(TypedefEffectiveStatementImpl.class);
 
@@ -89,6 +88,7 @@ public final class TypedefEffectiveStatementImpl extends AbstractEffectiveSchema
         return typeDefinition;
     }
 
+    @Override
     public TypeEffectiveStatement<TypeStatement> asTypeEffectiveStatement() {
         TypeEffectiveStatement<TypeStatement> ret = typeStatement;
         if (ret == null) {