Move TypeUtils.typeEffectiveSchemaPath() 38/65438/4
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 11 Nov 2017 13:07:15 +0000 (14:07 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 13 Nov 2017 11:30:33 +0000 (12:30 +0100)
Only users of this method reside in rfc7950.stmt.type package,
move it to AbstractTypeStatementSupport and hide it.

Change-Id: I867bb4c19456002ec1034d7a21c5d9a2aa0dd4c5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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/type/BinaryTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/BooleanTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/DecimalTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/EmptyTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/IdentityrefTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/LeafrefTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/StringTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/TypeUtils.java

index bf5f8b925d9a872afcb34e07f8d3b40c4fa79808..604c1abe58e93d4f9f7da6bac06bbf83b6a20ceb 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import java.util.Collection;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -46,13 +48,13 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Infere
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 abstract class AbstractTypeStatementSupport
         extends AbstractStatementSupport<String, TypeStatement, EffectiveStatement<String, TypeStatement>> {
@@ -216,40 +218,32 @@ abstract class AbstractTypeStatementSupport
                 (InstanceIdentifierTypeDefinition) baseType);
         } else if (baseType instanceof Int8TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newInt8Builder((Int8TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newInt8Builder((Int8TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Int16TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newInt16Builder((Int16TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newInt16Builder((Int16TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Int32TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newInt32Builder((Int32TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newInt32Builder((Int32TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Int64TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newInt64Builder((Int64TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newInt64Builder((Int64TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof LeafrefTypeDefinition) {
             return new LeafrefTypeEffectiveStatementImpl(ctx, (LeafrefTypeDefinition) baseType);
         } else if (baseType instanceof StringTypeDefinition) {
             return new StringTypeEffectiveStatementImpl(ctx, (StringTypeDefinition) baseType);
         } else if (baseType instanceof Uint8TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newUint8Builder((Uint8TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newUint8Builder((Uint8TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Uint16TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newUint16Builder((Uint16TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newUint16Builder((Uint16TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Uint32TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newUint32Builder((Uint32TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newUint32Builder((Uint32TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof Uint64TypeDefinition) {
             return new IntegralTypeEffectiveStatementImpl<>(ctx,
-                    RestrictedTypes.newUint64Builder((Uint64TypeDefinition) baseType,
-                        TypeUtils.typeEffectiveSchemaPath(ctx)));
+                    RestrictedTypes.newUint64Builder((Uint64TypeDefinition) baseType, typeEffectiveSchemaPath(ctx)));
         } else if (baseType instanceof UnionTypeDefinition) {
             return new UnionTypeEffectiveStatementImpl(ctx, (UnionTypeDefinition) baseType);
         } else {
@@ -311,4 +305,15 @@ abstract class AbstractTypeStatementSupport
     public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
         return ARGUMENT_SPECIFIC_SUPPORTS.get(argument);
     }
+
+    static final SchemaPath typeEffectiveSchemaPath(final StmtContext<?, ?, ?> stmtCtx) {
+        final SchemaPath path = stmtCtx.getSchemaPath().get();
+        final SchemaPath parent = path.getParent();
+        final QName parentQName = parent.getLastComponent();
+        Preconditions.checkArgument(parentQName != null, "Path %s has an empty parent", path);
+
+        final QName qname = stmtCtx.getFromNamespace(QNameCacheNamespace.class,
+            QName.create(parentQName, path.getLastComponent().getLocalName()));
+        return parent.createChild(qname);
+    }
 }
\ No newline at end of file
index d205c658be6bdaff48b23005b9a9b5e3c9b4f99c..0e63ad7ed54fc8d14a77abaaa0dbe36375aa55dc 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStat
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.length.LengthEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class BinaryTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, TypeStatement>
         implements TypeEffectiveStatement<TypeStatement> {
@@ -32,7 +31,7 @@ final class BinaryTypeEffectiveStatementImpl extends DeclaredEffectiveStatementB
         super(ctx);
 
         final LengthRestrictedTypeBuilder<BinaryTypeDefinition> builder =
-                RestrictedTypes.newBinaryBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
+                RestrictedTypes.newBinaryBuilder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx));
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof LengthEffectiveStatementImpl) {
index 6422f591bfdb829acde7ee557fe8e52c6a032ec9..179dfee7ccc577714576590dba0f20e488d5b8f3 100644 (file)
@@ -12,12 +12,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class BooleanTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement<BooleanTypeDefinition> {
     BooleanTypeEffectiveStatementImpl(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final BooleanTypeDefinition baseType) {
-        super(ctx, RestrictedTypes.newBooleanBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx)));
+        super(ctx, RestrictedTypes.newBooleanBuilder(baseType,
+            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)));
     }
 }
index d592ca7b2cba78a9a1c2b7b29a7c1abc46f3f169..f06db679d5b40a0dcd2a5ee37001b7cab8fbd634 100644 (file)
@@ -21,7 +21,6 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStat
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.range.RangeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class DecimalTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, TypeStatement>
         implements TypeEffectiveStatement<TypeStatement> {
@@ -33,7 +32,7 @@ final class DecimalTypeEffectiveStatementImpl extends DeclaredEffectiveStatement
         super(ctx);
 
         final RangeRestrictedTypeBuilder<DecimalTypeDefinition, BigDecimal> builder =
-                RestrictedTypes.newDecima64Builder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
+                RestrictedTypes.newDecima64Builder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx));
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof RangeEffectiveStatementImpl) {
index 36b8632bb74c549a323a5cd7ff9b8472863cfa26..488b9dc1d689b73deac208f2f6ce2dd0eff6755a 100644 (file)
@@ -12,12 +12,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class EmptyTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement<EmptyTypeDefinition> {
     EmptyTypeEffectiveStatementImpl(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final EmptyTypeDefinition baseType) {
-        super(ctx, RestrictedTypes.newEmptyBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx)));
+        super(ctx, RestrictedTypes.newEmptyBuilder(baseType,
+            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)));
     }
 }
index 9e97ec6f9fd604966d51b7c0cc8e8264dcc7c5da..51015909f7e031661333ac2124b5016dc6386e46 100644 (file)
@@ -12,12 +12,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class IdentityrefTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement<IdentityrefTypeDefinition> {
     IdentityrefTypeEffectiveStatementImpl(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final IdentityrefTypeDefinition baseType) {
-        super(ctx, RestrictedTypes.newIdentityrefBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx)));
+        super(ctx, RestrictedTypes.newIdentityrefBuilder(baseType,
+            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)));
     }
 }
index 3230a876e289a5d5febf8711d6879c318fb6f231..28f4a6db5322cb0d8b0e8b90befae0a1ba26ee76 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBui
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class InstanceIdentifierTypeEffectiveStatementImpl
         extends DeclaredEffectiveStatementBase<String, TypeStatement> implements TypeEffectiveStatement<TypeStatement> {
@@ -30,7 +29,8 @@ final class InstanceIdentifierTypeEffectiveStatementImpl
         super(ctx);
 
         final InstanceIdentifierTypeBuilder builder =
-                RestrictedTypes.newInstanceIdentifierBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
+                RestrictedTypes.newInstanceIdentifierBuilder(baseType,
+                    AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx));
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof RequireInstanceEffectiveStatement) {
index 10b995c879b6de28b8aa514926ed2e0385779feb..44b015b1a37fb2b495d8d19df131c3b1ed520f60 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.yangtools.yang.model.util.type.RequireInstanceRestricted
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class LeafrefTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, TypeStatement>
         implements TypeEffectiveStatement<TypeStatement> {
@@ -31,7 +30,7 @@ final class LeafrefTypeEffectiveStatementImpl extends DeclaredEffectiveStatement
         super(ctx);
 
         final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> builder =
-                RestrictedTypes.newLeafrefBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
+                RestrictedTypes.newLeafrefBuilder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx));
 
         for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof RequireInstanceEffectiveStatement) {
index a16368f590bc2f18278f0a7554935fccc79df44e..5f5cb3b9d6f6f657b42e95b045f91d97034cb577 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStat
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.length.LengthEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +36,7 @@ final class StringTypeEffectiveStatementImpl extends DeclaredEffectiveStatementB
         super(ctx);
 
         final StringTypeBuilder builder = RestrictedTypes.newStringBuilder(baseType,
-            TypeUtils.typeEffectiveSchemaPath(ctx));
+            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx));
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof LengthEffectiveStatementImpl) {
index c8bf5d1b935a977d0f21465bc9d8bce569f35744..d98465b067be99c56834411db43f650dd1300fe6 100644 (file)
@@ -12,12 +12,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 
 final class UnionTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement<UnionTypeDefinition> {
     UnionTypeEffectiveStatementImpl(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final UnionTypeDefinition baseType) {
-        super(ctx, RestrictedTypes.newUnionBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx)));
+        super(ctx, RestrictedTypes.newUnionBuilder(baseType,
+            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)));
     }
 }
index 70859e33a2ffb2333d41b91c4075ec6234bb6d1c..e55b70222230e564b1726080bc70ce20800b5632 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import com.google.common.collect.Iterables;
@@ -20,7 +19,6 @@ import java.util.List;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -31,7 +29,6 @@ import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
@@ -165,17 +162,6 @@ public final class TypeUtils {
         return ranges;
     }
 
-    public static SchemaPath typeEffectiveSchemaPath(final StmtContext<?, ?, ?> stmtCtx) {
-        final SchemaPath path = stmtCtx.getSchemaPath().get();
-        final SchemaPath parent = path.getParent();
-        final QName parentQName = parent.getLastComponent();
-        Preconditions.checkArgument(parentQName != null, "Path %s has an empty parent", path);
-
-        final QName qname = stmtCtx.getFromNamespace(QNameCacheNamespace.class,
-            QName.create(parentQName, path.getLastComponent().getLocalName()));
-        return parent.createChild(qname);
-    }
-
     /**
      * Checks whether supplied type has any of specified default values marked
      * with an if-feature. This method creates mutable copy of supplied set of