BUG-865: make EnumPair getQName/getSchemaPath unimplemented 94/41994/7
authorRobert Varga <rovarga@cisco.com>
Mon, 18 Jul 2016 16:32:41 +0000 (18:32 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 26 Jul 2016 11:40:40 +0000 (13:40 +0200)
EnumPairs by definition do not have SchemaPath, which makes
them non-SchemaNodes. As a first step make the methods
unimplemented so we can catch offenders.

Change-Id: I19cb47368ea5b575fa2ce89bb0c4b6a934bdaae3
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumPairImpl.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/TypeTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumSpecificationEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java

index 4ef71ef57f0248650f407327392f9d603b078696..0e2fefde25a78e637af5d36a32c8fb26f377716c 100644 (file)
@@ -45,7 +45,9 @@ public interface EnumTypeDefinition extends TypeDefinition<EnumTypeDefinition> {
          */
         @Deprecated
         @Override
-        SchemaPath getPath();
+        default SchemaPath getPath() {
+            throw new UnsupportedOperationException("Enum pairs do not have SchemaPath");
+        }
 
         /**
          *
@@ -56,7 +58,9 @@ public interface EnumTypeDefinition extends TypeDefinition<EnumTypeDefinition> {
          */
         @Deprecated
         @Override
-        QName getQName();
+        default QName getQName() {
+            throw new UnsupportedOperationException("Enum pairs do not have QName, only name");
+        }
 
         /**
          * The name to specify each assigned name of an enumeration type.
index f93dee2a0ff1d6848fd77d16e1de1102408ea703..e04736f69105ead1c89c522b318c2d788c438dd8 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -24,14 +23,21 @@ public final class EnumPairImpl implements EnumPair, Immutable {
     private final List<UnknownSchemaNode> unknownSchemaNodes;
     private final String description;
     private final String reference;
-    private final SchemaPath path;
     private final Status status;
     private final Integer value;
     private final String name;
 
+    /**
+     * @deprecated Use the constructor without a SchemaPath
+     */
+    @Deprecated
     public EnumPairImpl(final String name, final Integer value, final SchemaPath path, final String description,
             final String reference, final Status status, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
-        this.path = Preconditions.checkNotNull(path);
+        this(name, value, description, reference, status, unknownSchemaNodes);
+    }
+
+    public EnumPairImpl(final String name, final Integer value, final String description, final String reference,
+            final Status status, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
         this.value = Preconditions.checkNotNull(value);
         this.name = Preconditions.checkNotNull(name);
         this.description = description;
@@ -40,16 +46,6 @@ public final class EnumPairImpl implements EnumPair, Immutable {
         this.unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodes);
     }
 
-    @Override
-    public QName getQName() {
-        return path.getLastComponent();
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return path;
-    }
-
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return unknownSchemaNodes;
@@ -84,8 +80,6 @@ public final class EnumPairImpl implements EnumPair, Immutable {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + Objects.hashCode(path.getLastComponent());
-        result = prime * result + Objects.hashCode(path);
         result = prime * result + Objects.hashCode(unknownSchemaNodes);
         result = prime * result + Objects.hashCode(name);
         result = prime * result + Objects.hashCode(value);
@@ -105,7 +99,7 @@ public final class EnumPairImpl implements EnumPair, Immutable {
             return false;
         }
 
-        return Objects.equals(value, other.getValue()) && Objects.equals(getPath(), other.getPath()) &&
+        return Objects.equals(value, other.getValue()) &&
                 Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes());
     }
 
index 5206be2f619008113bef40f487217470892c34c8..7a4cf90ceeb33a582ca4bccab3cec3319f717908 100644 (file)
@@ -439,7 +439,7 @@ public class TypeTest {
         final UnknownSchemaNode UNKNOWN_SCHEMA_NODE= mock(UnknownSchemaNode.class);
         final Collection<UnknownSchemaNode> collection = new ArrayList<>(1);
         collection.add(UNKNOWN_SCHEMA_NODE);
-        final EnumPairImpl enumPair = new EnumPairImpl("enum1", 1, SCHEMA_PATH, "description", "reference",
+        final EnumPairImpl enumPair = new EnumPairImpl("enum1", 1, "description", "reference",
                 Status.CURRENT, collection);
 
         final InvalidLengthConstraintException invalidLengthConstraintException = new InvalidLengthConstraintException(
@@ -480,9 +480,9 @@ public class TypeTest {
         final UnknownSchemaNode UNKNOWN_SCHEMA_NODE= mock(UnknownSchemaNode.class);
         final Collection<UnknownSchemaNode> collection = new ArrayList<>(1);
         collection.add(UNKNOWN_SCHEMA_NODE);
-        final EnumPairImpl enumPair1 = new EnumPairImpl("enum1", 1, SCHEMA_PATH, "description", "reference",
+        final EnumPairImpl enumPair1 = new EnumPairImpl("enum1", 1, "description", "reference",
                 Status.CURRENT, collection);
-        final EnumPairImpl enumPair2 = new EnumPairImpl("enum", 1, SCHEMA_PATH, "description", "reference",
+        final EnumPairImpl enumPair2 = new EnumPairImpl("enum", 1, "description", "reference",
                 Status.CURRENT, collection);
         final EnumerationTypeBuilder enumerationTypeBuilder = BaseTypes.enumerationTypeBuilder(SCHEMA_PATH);
         enumerationTypeBuilder.addEnum(enumPair1);
index c7b79533486570ed48d0fd8727f11e97ee856283..8ec49205c64bb9396afb5b8699bf375fa2f2cdb8 100644 (file)
@@ -9,52 +9,29 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class EnumEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, EnumStatement> implements EnumPair {
-
-    private static final Logger LOG = LoggerFactory.getLogger(EnumEffectiveStatementImpl.class);
-
     private final String name;
-    private final SchemaPath path;
     private String description;
     private String reference;
     private Status status = Status.CURRENT;
     private Integer value;
-    private final QName maybeQNameArgument;
 
     public EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
         super(ctx);
 
         name = ctx.rawStatementArgument();
-        SchemaPath parentPath = ctx.getParentContext().getSchemaPath().get();
-        QNameModule moduleQName = parentPath.getLastComponent().getModule();
-        QName maybeQNameArgumentInit = null;
-        try {
-            maybeQNameArgumentInit = QName.create(moduleQName, argument());
-        } catch (IllegalArgumentException e) {
-            String localName = Utils.replaceIllegalCharsForQName(argument());
-            LOG.warn("{}. Enum argument '{}' has been replaced by '{}'.", e.getMessage(), argument(), localName, e);
-            maybeQNameArgumentInit = QName.create(moduleQName, localName);
-        }
-        this.maybeQNameArgument = maybeQNameArgumentInit;
-        this.path = parentPath.createChild(this.maybeQNameArgument);
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
@@ -82,16 +59,6 @@ public class EnumEffectiveStatementImpl extends DeclaredEffectiveStatementBase<S
         return value;
     }
 
-    @Override
-    public QName getQName() {
-        return maybeQNameArgument;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return path;
-    }
-
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return Collections.emptyList();
index 96dae96a9bbd3c2f39cba09e3c520a8cce9b060c..29ba56af99285ac8fe7e568b41d8a67a5c9974c1 100644 (file)
@@ -46,8 +46,8 @@ public final class EnumSpecificationEffectiveStatementImpl extends
                             "Enum '%s' must have a value statement", p);
                     }
 
-                    p = new EnumPairImpl(p.getName(), newValue, p.getPath(), p.getDescription(), p.getReference(),
-                        p.getStatus(), p.getUnknownSchemaNodes());
+                    p = new EnumPairImpl(p.getName(), newValue, p.getDescription(), p.getReference(), p.getStatus(),
+                        p.getUnknownSchemaNodes());
                 }
 
                 if (highestValue == null || highestValue < p.getValue()) {
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java
deleted file mode 100644 (file)
index 82dfcc2..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.stmt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.List;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
-public class Bug4459Test {
-
-    @Test
-    public void test() throws IOException, URISyntaxException, SourceException, ReactorException {
-        SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4459");
-        assertNotNull(schema);
-
-        DataSchemaNode dataChildByName = schema.getDataChildByName("my-leaf");
-        assertTrue(dataChildByName instanceof LeafSchemaNode);
-        LeafSchemaNode myLeaf = (LeafSchemaNode) dataChildByName;
-
-        TypeDefinition<?> type = myLeaf.getType();
-        assertTrue(type instanceof EnumTypeDefinition);
-        EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
-
-        QName expectedEnumQName = QName.create("foo", "1970-01-01", "QuestionMark-Ampersand-LeftParenthesis-RightParenthesis-QuestionMark-QuestionMark-Ampersand");
-        List<EnumPair> values = myEnum.getValues();
-        for (EnumPair enumPair : values) {
-            if (enumPair.getName().equals("?-&-(-)-?-?-&")) {
-                assertEquals(expectedEnumQName, enumPair.getQName());
-            }
-        }
-    }
-}
index c819f8d8a5c9b24b65d526fe33036b010a57ed16..529d2a99269ab5195cf55604d5c6daae3150e2cc 100644 (file)
@@ -224,9 +224,7 @@ public class EffectiveStatementTypeTest {
         assertFalse(enumSpecEff.equals("test"));
         assertTrue(enumSpecEff.equals(enumSpecEff));
 
-        assertEquals("zero", enumEff.getQName().getLocalName());
         assertEquals("zero", enumEff.getName());
-        assertNotNull(enumEff.getPath());
         assertNotNull(enumEff.getUnknownSchemaNodes());
         assertEquals("test enum", enumEff.getDescription());
         assertEquals("test enum ref", enumEff.getReference());