From bdb66dd5754f8a7211a20714b73acbdca7354bd4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 4 May 2018 13:12:19 +0200 Subject: [PATCH] Fix code smells in yang-parser-spi These are simple Sonar violations, clear them up. Change-Id: Ib8e71154ab29e87afff8a3696c8b8749bc2806ce Signed-off-by: Robert Varga --- .../stmt/reactor/NamespaceStorageSupport.java | 2 +- .../spi/meta/DerivedNamespaceBehaviour.java | 22 +++++++++---- .../parser/spi/meta/ModelActionBuilder.java | 22 ++++++++----- .../parser/spi/meta/NamespaceBehaviour.java | 10 ++++++ .../spi/meta/StatementSupportBundle.java | 2 +- .../yang/parser/spi/meta/StmtContext.java | 32 ++++++++++++++++--- .../spi/meta/SubstatementValidator.java | 10 ++++-- 7 files changed, 77 insertions(+), 23 deletions(-) diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java index 26a5ce002e..5e3d49a4fa 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java @@ -93,7 +93,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { * @param namespace value type * @param namespace type * @param key type - * @param key type + * @param value type * @throws NamespaceNotAvailableException when the namespace is not available. */ public final > void addToNs( diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java index 0f7e47f962..5a318402f0 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java @@ -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, - DN extends IdentifierNamespace> extends NamespaceBehaviour { +/** + * An {@link NamespaceBehaviour} which derives keys from a different namespace. + * + * @param Key type + * @param Value type + * @param Namespace type + * @param Original key type + * @param Original namespace type + */ +public abstract class DerivedNamespaceBehaviour, + O extends IdentifierNamespace> extends NamespaceBehaviour { - private final Class derivedFrom; + private final Class derivedFrom; - protected DerivedNamespaceBehaviour(final Class identifier, final Class derivedFrom) { + protected DerivedNamespaceBehaviour(final Class identifier, final Class derivedFrom) { super(identifier); this.derivedFrom = requireNonNull(derivedFrom); } - public Class getDerivedFrom() { + public Class getDerivedFrom() { return derivedFrom; } @@ -40,5 +48,5 @@ public abstract class DerivedNamespaceBehaviour> failed) throws InferenceException; + void prerequisiteFailed(Collection> failed); } /** @@ -167,10 +166,17 @@ public interface ModelActionBuilder { @Nonnull , N extends IdentifierNamespace>> Prerequisite> mutatesEffectiveCtx(StmtContext context, Class namespace, K key); - @Nonnull , CT extends C> Prerequisite mutatesCtx(CT root, - ModelProcessingPhase phase); + @Nonnull , T extends C> Prerequisite 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. diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java index 9fcba740e9..50e81b88c1 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java @@ -41,6 +41,16 @@ public abstract class NamespaceBehaviour key type + * @param value type + * @param namespace type + * @return Namespace behaviour + * @throws NamespaceNotAvailableException when the namespace is not available + */ > NamespaceBehaviour getNamespaceBehaviour(Class type); } diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java index 9fd94338ef..110c5f1c2f 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupportBundle.java @@ -101,7 +101,7 @@ public final class StatementSupportBundle implements Immutable, NamespaceBehavio @Override public > NamespaceBehaviour getNamespaceBehaviour( - final Class namespace) throws NamespaceNotAvailableException { + final Class namespace) { final NamespaceBehaviour potential = namespaceDefinitions.get(namespace); if (potential != null) { checkState(namespace.equals(potential.getIdentifier())); diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 939d6f2d2b..29a7cdf9f3 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -68,9 +68,20 @@ public interface StmtContext, E extends Effect boolean isEnabledSemanticVersioning(); + /** + * Return a value associated with specified key within a namespace. + * + * @param type Namespace type + * @param key Key + * @param namespace key type + * @param namespace value type + * @param namespace type + * @param key type + * @return Value, or null if there is no element + * @throws NamespaceNotAvailableException when the namespace is not available. + */ @Nonnull - > V getFromNamespace( - Class type, KT key) throws NamespaceNotAvailableException; + > V getFromNamespace(Class type, T key) ; > Map getAllFromNamespace( Class type); @@ -140,8 +151,21 @@ public interface StmtContext, E extends Effect @Override Mutable getParentContext(); - > void addToNs(Class 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 namespace key type + * @param namespace value type + * @param namespace type + * @param key type + * @param value type + * @throws NamespaceNotAvailableException when the namespace is not available. + */ + > void addToNs(Class type, T key, + U value); @Nonnull @Override diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java index 8a10a96cce..56ebb8cf82 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SubstatementValidator.java @@ -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 stmtCounts = new HashMap<>(); for (StmtContext stmtCtx : ctx.allSubstatements()) { -- 2.36.6