Promote AbstractModelStatement to model-spi 75/95075/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Feb 2021 19:53:03 +0000 (20:53 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Feb 2021 20:01:04 +0000 (21:01 +0100)
This is a useful common implementation class, make it more widely
accessible.

JIRA: YANGTOOLS-1225
Change-Id: I4f04df2063545e7f20fa0d4a0795c4bf5d2a2ebd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-spi/src/main/java/module-info.java
yang/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractModelStatement.java [moved from yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractModelStatement.java with 67% similarity]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractDeclaredStatement.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveStatement.java

index feeac3653f19d8ba240c15751f4e65ebfeed66d4..d60aa86f14ed9df62fece4a33783cfb23162d4e6 100644 (file)
@@ -6,15 +6,12 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 module org.opendaylight.yangtools.yang.model.spi {
+    exports org.opendaylight.yangtools.yang.model.spi.meta;
     exports org.opendaylight.yangtools.yang.model.spi.type;
 
     requires transitive org.opendaylight.yangtools.yang.model.api;
     requires org.opendaylight.yangtools.yang.common;
 
-//    requires org.opendaylight.yangtools.util;
-//    requires org.slf4j;
-
     // Annotations
     requires static transitive org.eclipse.jdt.annotation;
-//    requires static com.github.spotbugs.annotations;
 }
@@ -5,15 +5,24 @@
  * 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.parser.rfc7950.stmt;
+package org.opendaylight.yangtools.yang.model.spi.meta;
 
+import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.model.api.meta.ModelStatement;
 
-abstract class AbstractModelStatement<A> implements ModelStatement<A> {
-
+/**
+ * Abstract base class for {@link ModelStatement} implementations. It mostly provides static methods for efficiently
+ * storing lists.
+ *
+ * @param <A> Argument type ({@link Empty} if statement does not have argument.)
+ */
+// FIXME: 7.0.0: hide this class if possible
+@Beta
+public abstract class AbstractModelStatement<A> implements ModelStatement<A> {
     /**
      * Utility method for squashing singleton lists into single objects. This is a CPU/mem trade-off, which we are
      * usually willing to make: for the cost of an instanceof check we can save one object and re-create it when needed.
@@ -40,9 +49,9 @@ abstract class AbstractModelStatement<A> implements ModelStatement<A> {
     protected static final <T> @NonNull ImmutableList<T> unmaskList(final @NonNull Object masked,
             final @NonNull Class<T> type) {
         return masked instanceof ImmutableList ? (ImmutableList<T>) masked
-                // Yes, this is ugly code, which could use an explicit verify, that would just change the what sort
-                // of exception we throw. ClassCastException is as good as VerifyException.
-                : ImmutableList.of(type.cast(masked));
+            // Yes, this is ugly code, which could use an explicit verify, that would just change the what sort
+            // of exception we throw. ClassCastException is as good as VerifyException.
+            : ImmutableList.of(type.cast(masked));
     }
 
     protected static final @NonNull Object maskSet(final ImmutableSet<?> set) {
@@ -52,9 +61,8 @@ abstract class AbstractModelStatement<A> implements ModelStatement<A> {
     protected static final <T> @NonNull ImmutableSet<? extends T> unmaskSet(final @NonNull Object masked,
             final @NonNull Class<T> type) {
         return masked instanceof ImmutableSet ? (ImmutableSet<T>) masked
-                // Yes, this is ugly code, which could use an explicit verify, that would just change the what sort
-                // of exception we throw. ClassCastException is as good as VerifyException.
-                : ImmutableSet.of(type.cast(masked));
+            // Yes, this is ugly code, which could use an explicit verify, that would just change the what sort
+            // of exception we throw. ClassCastException is as good as VerifyException.
+            : ImmutableSet.of(type.cast(masked));
     }
-
 }
index b9fc1ce5c159c35ac68b28380eba39ca5eada988..ef07d2dab37e188436845fe9e8d9a0dee47320e3 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.spi.meta.AbstractModelStatement;
 
 /**
  * An abstract base class for {@link DeclaredStatement} implementations. This is a direct competition to
@@ -27,9 +28,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
 @Beta
 // FIXME: 7.0.0: we should be able to promote this to model.spi.meta package.
 public abstract class AbstractDeclaredStatement<A> extends AbstractModelStatement<A> implements DeclaredStatement<A> {
-    protected AbstractDeclaredStatement() {
-    }
-
     @Override
     public StatementSource getStatementSource() {
         return StatementSource.DECLARATION;
index 15609997cc19f1a0887f610b2054da2e233b666e..4545b53cf02027d1f47fe2c75c0a7768c7cd5dc4 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.spi.meta.AbstractModelStatement;
 
 /**
  * Baseline stateless implementation of an EffectiveStatement. This class adds a few default implementations and