Fix code smells in yang-parser-spi 92/71792/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 4 May 2018 11:12:19 +0000 (13:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 4 May 2018 11:34:54 +0000 (13:34 +0200)
These are simple Sonar violations, clear them up.

Change-Id: Ib8e71154ab29e87afff8a3696c8b8749bc2806ce
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java

index 26a5ce002ebc46e28f8f14b9fab324c3a6f3f7a6..5e3d49a4fa70e628790a55dc421d6bf13d6be4cf 100644 (file)
@@ -93,7 +93,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
      * @param <V> namespace value type
      * @param <N> namespace type
      * @param <T> key type
-     * @param <U> key type
+     * @param <U> value type
      * @throws NamespaceNotAvailableException when the namespace is not available.
      */
     public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(
index 0f7e47f962484a0b68629e9e0932f0baff881222..5a318402f081b5d1636ab6c88862740c266983a6 100644 (file)
@@ -12,18 +12,26 @@ import static java.util.Objects.requireNonNull;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 
-@SuppressWarnings("checkstyle:classTypeParameterName")
-public abstract class DerivedNamespaceBehaviour<K, V, DK, N extends IdentifierNamespace<K, V>,
-       DN extends IdentifierNamespace<DK, ?>> extends NamespaceBehaviour<K, V, N> {
+/**
+ * An {@link NamespaceBehaviour} which derives keys from a different namespace.
+ *
+ * @param <K> Key type
+ * @param <V> Value type
+ * @param <N> Namespace type
+ * @param <L> Original key type
+ * @param <O> Original namespace type
+ */
+public abstract class DerivedNamespaceBehaviour<K, V, L, N extends IdentifierNamespace<K, V>,
+       O extends IdentifierNamespace<L, ?>> extends NamespaceBehaviour<K, V, N> {
 
-    private final Class<DN> derivedFrom;
+    private final Class<O> derivedFrom;
 
-    protected DerivedNamespaceBehaviour(final Class<N> identifier, final Class<DN> derivedFrom) {
+    protected DerivedNamespaceBehaviour(final Class<N> identifier, final Class<O> derivedFrom) {
         super(identifier);
         this.derivedFrom = requireNonNull(derivedFrom);
     }
 
-    public Class<DN> getDerivedFrom() {
+    public Class<O> getDerivedFrom() {
         return derivedFrom;
     }
 
@@ -40,5 +48,5 @@ public abstract class DerivedNamespaceBehaviour<K, V, DK, N extends IdentifierNa
         // Intentional noop
     }
 
-    public abstract DK getSignificantKey(K key);
+    public abstract L getSignificantKey(K key);
 }
index 465e7fd4e9ba749752e0aacf7c529370b719bde9..9f59d5ec1b248fee6a0f659724e9c0a916bc0eb6 100644 (file)
@@ -99,11 +99,10 @@ public interface ModelActionBuilder {
          * Invoked once all prerequisites were met and forward references were resolved and inference action should be
          * applied. Implementors may perform necessary changes to mutable objects which were declared.
          *
-         * @throws InferenceException If inference action can not be processed.
-         *      Note that this exception be used for user to debug YANG sources,
-         *      so should provide helpful context to fix issue in sources.
+         * @throws InferenceException If inference action can not be processed. Note that this exception be used for
+         *         user to debug YANG sources, so should provide helpful context to fix issue in sources.
          */
-        void apply(InferenceContext ctx) throws InferenceException;
+        void apply(InferenceContext ctx);
 
         /**
          * Invoked once one of prerequisites was not met, even after all other satisfiable inference actions were
@@ -122,7 +121,7 @@ public interface ModelActionBuilder {
          *                            by user to debug YANG sources, hence it should provide helpful context to fix
          *                            the issue in sources.
          */
-        void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException;
+        void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed);
     }
 
     /**
@@ -167,10 +166,17 @@ public interface ModelActionBuilder {
     @Nonnull <K, E extends EffectiveStatement<?, ?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>>
         Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
 
-    @Nonnull <C extends StmtContext.Mutable<?, ?, ?>, CT extends C> Prerequisite<C> mutatesCtx(CT root,
-            ModelProcessingPhase phase);
+    @Nonnull <C extends Mutable<?, ?, ?>, T extends C> Prerequisite<C> mutatesCtx(T root, ModelProcessingPhase phase);
 
-    void apply(InferenceAction action) throws InferenceException;
+    /**
+     * Apply an {@link InferenceAction} when this action's prerequisites are resolved.
+     *
+     * @param action Inference action to apply
+     * @throws InferenceException if the action fails
+     * @throws NullPointerException if {@code action is null}
+     * @throws IllegalStateException if this action has an inference action already associated.
+     */
+    void apply(InferenceAction action);
 
     /**
      * Create a requirement on specified statement context to be declared.
index 9fcba740e922ea0920e52723921756d0a3841471..50e81b88c1b1f29fc8476fed6de82c4c8431ee44 100644 (file)
@@ -41,6 +41,16 @@ public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K,
     }
 
     public interface Registry {
+        /**
+         * Get a namespace behavior.
+         *
+         * @param type Namespace type class
+         * @param <K> key type
+         * @param <V> value type
+         * @param <N> namespace type
+         * @return Namespace behaviour
+         * @throws NamespaceNotAvailableException when the namespace is not available
+         */
         <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
     }
 
index 9fd94338ef01e8ac230520f338f87ff40c04c7f7..110c5f1c2f5555d2dbb3512f4ef59608e301dc7e 100644 (file)
@@ -101,7 +101,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio
 
     @Override
     public <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
-            final Class<N> namespace) throws NamespaceNotAvailableException {
+            final Class<N> namespace) {
         final NamespaceBehaviour<?, ?, ?> potential = namespaceDefinitions.get(namespace);
         if (potential != null) {
             checkState(namespace.equals(potential.getIdentifier()));
index 939d6f2d2b5c5690f6d3c1a43977ba2525394b1b..29a7cdf9f3bee58792f9f8847031c8e32ce14268 100644 (file)
@@ -68,9 +68,20 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     boolean isEnabledSemanticVersioning();
 
+    /**
+     * Return a value associated with specified key within a namespace.
+     *
+     * @param type Namespace type
+     * @param key Key
+     * @param <K> namespace key type
+     * @param <V> namespace value type
+     * @param <N> namespace type
+     * @param <T> key type
+     * @return Value, or null if there is no element
+     * @throws NamespaceNotAvailableException when the namespace is not available.
+     */
     @Nonnull
-    <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
-            Class<N> type, KT key) throws NamespaceNotAvailableException;
+    <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(Class<N> type, T key) ;
 
     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
             Class<N> type);
@@ -140,8 +151,21 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         @Override
         Mutable<?, ?, ?> getParentContext();
 
-        <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, KT key,
-                VT value) throws NamespaceNotAvailableException;
+        /**
+         * Associate a value with a key within a namespace.
+         *
+         * @param type Namespace type
+         * @param key Key
+         * @param value value
+         * @param <K> namespace key type
+         * @param <V> namespace value type
+         * @param <N> namespace type
+         * @param <T> key type
+         * @param <U> value type
+         * @throws NamespaceNotAvailableException when the namespace is not available.
+         */
+        <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, T key,
+                U value);
 
         @Nonnull
         @Override
index 8a10a96cce2e23e5a5e7368dce9d02873e62fd95..56ebb8cf820b0b99ec920391c5be083ba3f9dfbb 100644 (file)
@@ -103,8 +103,14 @@ public final class SubstatementValidator {
         }
     }
 
-    public void validate(final StmtContext<?, ?, ?> ctx) throws InvalidSubstatementException,
-            MissingSubstatementException {
+    /**
+     * Validate substatements inside a context.
+     *
+     * @param ctx Context to inspect
+     * @throws InvalidSubstatementException when there is a disallowed statement present.
+     * @throws MissingSubstatementException when a mandatory statement is missing.
+     */
+    public void validate(final StmtContext<?, ?, ?> ctx) {
 
         final Map<StatementDefinition, Counter> stmtCounts = new HashMap<>();
         for (StmtContext<?, ?, ?> stmtCtx : ctx.allSubstatements()) {