Activate checkstyle in yang-data-jaxen 39/58239/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Jun 2017 11:33:59 +0000 (13:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Jun 2017 11:33:59 +0000 (13:33 +0200)
Cleanup the code and enforce checkstyle.

Change-Id: Ieb6087afc1b98065bc2e0c941dd5ff0277c8244b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
15 files changed:
yang/yang-data-jaxen/pom.xml
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/ConverterNamespaceContext.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/ExprListener.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenSchemaContext.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenXPath.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/LeafrefXPathStringParsingPathArgumentBuilder.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/NormalizedNodeContextSupport.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/NormalizedNodeNavigator.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/StepListener.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/YangFunctionContext.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/BitIsSetXPathFunctionTest.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerefXPathFunctionTest.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerivedFromXPathFunctionTest.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java

index 0ad6f26b2d56c888771a696f5d5fa1560526558d..75302e25fd790cee75f08258a1cf660140c66fb7 100644 (file)
         </dependency>
     </dependencies>
 
-  <!--
-      Maven Site Configuration
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
-      The following configuration is necessary for maven-site-plugin to
-      correctly identify the correct deployment path for OpenDaylight Maven
-      sites.
-  -->
-  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+    <!--
+        Maven Site Configuration
 
-  <distributionManagement>
-    <site>
-      <id>opendaylight-site</id>
-      <url>${nexus.site.url}/${project.artifactId}/</url>
-    </site>
-  </distributionManagement>
+        The following configuration is necessary for maven-site-plugin to
+        correctly identify the correct deployment path for OpenDaylight Maven
+        sites.
+    -->
+    <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+    <distributionManagement>
+        <site>
+            <id>opendaylight-site</id>
+            <url>${nexus.site.url}/${project.artifactId}/</url>
+        </site>
+    </distributionManagement>
 </project>
index 078b02f9f30fe00268fe6ef9758648969c355de0..b34011c68434abdef717f41366f15d6b315abfcb 100644 (file)
@@ -22,11 +22,13 @@ final class ConverterNamespaceContext extends Converter<String, QNameModule> imp
     }
 
     @Override
+    @SuppressWarnings("checkstyle:parameterName")
     protected QNameModule doForward(@Nonnull final String a) {
         return delegate.convert(a);
     }
 
     @Override
+    @SuppressWarnings("checkstyle:parameterName")
     protected String doBackward(@Nonnull final QNameModule b) {
         return delegate.reverse().convert(b);
     }
index ab19aac9b0d4b0dab9bcacad0d11e4a0a451f847..d1c31a28f71d0231af374751fc36b4a2a56b3d2f 100644 (file)
@@ -22,6 +22,7 @@ abstract class ExprListener {
     void enterBinaryExpr(final BinaryExpr expr) {
 
     }
+
     void exitBinaryExpr(final BinaryExpr expr) {
 
     }
index b781381799d326e67ca5badc84fb512788613368..29a274e261b4f4604cbcc1d03a76d59c6836682c 100644 (file)
@@ -32,7 +32,8 @@ final class JaxenSchemaContext implements XPathSchemaContext {
     @Nonnull
     @Override
     public XPathExpression compileExpression(@Nonnull final SchemaPath schemaPath,
-            final Converter<String, QNameModule> prefixes, @Nonnull final String xpath) throws XPathExpressionException {
+            final Converter<String, QNameModule> prefixes, @Nonnull final String xpath)
+            throws XPathExpressionException {
         try {
             return JaxenXPath.create(prefixes, schemaPath, xpath);
         } catch (JaxenException e) {
index a5054ef286bcdeec7c2d234f72f9cf889b062287..8f985178d06bddfa7a9e239f01f01f0f56ea174c 100644 (file)
@@ -67,8 +67,8 @@ final class JaxenXPath implements XPathExpression {
     }
 
     @Override
-    public Optional<? extends XPathResult<?>> evaluate(@Nonnull final XPathDocument document, @Nonnull final YangInstanceIdentifier path)
-            throws XPathExpressionException {
+    public Optional<? extends XPathResult<?>> evaluate(@Nonnull final XPathDocument document,
+            @Nonnull final YangInstanceIdentifier path) throws XPathExpressionException {
         Preconditions.checkArgument(document instanceof JaxenDocument);
 
         final NormalizedNodeContextSupport contextSupport = NormalizedNodeContextSupport.create(
@@ -87,7 +87,7 @@ final class JaxenXPath implements XPathExpression {
             return Optional.of((XPathNumberResult) () -> (Number) result);
         } else if (result instanceof Boolean) {
             return Optional.of((XPathBooleanResult) () -> (Boolean) result);
-        } else if (result != null){
+        } else if (result != null) {
             return Optional.of((XPathNodesetResult) () -> {
                 // XXX: Will this really work, or do we need to perform deep transformation?
                 return Lists.transform((List<NormalizedNodeContext>) result, NormalizedNodeContext::getNode);
index 1d839823d6830fe7a68626e5dc4ce9802093b9a9..0f2a6369955771d9dc0c9215d7740274f04e66ca 100644 (file)
@@ -42,26 +42,22 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     private static final String NODE_IDENTIFIER_STR = "([A-Za-z_][A-Za-z0-9_\\.-]*:)?([A-Za-z_][A-Za-z0-9_\\.-]*)";
 
     /**
-     * Pattern matching node-identifier YANG ABNF token
+     * Pattern matching node-identifier YANG ABNF token.
      */
     private static final Pattern NODE_IDENTIFIER_PATTERN = Pattern.compile(NODE_IDENTIFIER_STR);
 
     /**
-     * Matcher matching WSP YANG ABNF token
-     *
+     * Matcher matching WSP YANG ABNF token.
      */
     private static final CharMatcher WSP = CharMatcher.anyOf(" \t");
 
     /**
      * Matcher matching IDENTIFIER first char token.
-     *
      */
     private static final CharMatcher IDENTIFIER_FIRST_CHAR = CharMatcher.inRange('a', 'z')
             .or(CharMatcher.inRange('A', 'Z')).or(CharMatcher.is('_')).precomputed();
     /**
-     *
-     * Matcher matching IDENTIFIER token
-     *
+     * Matcher matching IDENTIFIER token.
      */
     private static final CharMatcher IDENTIFIER = IDENTIFIER_FIRST_CHAR.or(CharMatcher.inRange('0', '9'))
             .or(CharMatcher.anyOf(".-")).precomputed();
@@ -74,7 +70,7 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     private static final char PRECONDITION_START = '[';
     private static final char PRECONDITION_END = ']';
 
-    private final String xPathString;
+    private final String xpathString;
     private final SchemaContext schemaContext;
     private final TypedSchemaNode schemaNode;
     private final NormalizedNodeContext currentNodeCtx;
@@ -82,9 +78,9 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
 
     private int offset = 0;
 
-    LeafrefXPathStringParsingPathArgumentBuilder(final String xPathString, final SchemaContext schemaContext,
+    LeafrefXPathStringParsingPathArgumentBuilder(final String xpathString, final SchemaContext schemaContext,
             final TypedSchemaNode schemaNode, final NormalizedNodeContext currentNodeCtx) {
-        this.xPathString = xPathString;
+        this.xpathString = xpathString;
         this.schemaContext = schemaContext;
         this.schemaNode = schemaNode;
         this.currentNodeCtx = currentNodeCtx;
@@ -106,10 +102,10 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
         final QName name = nextQName();
         if (allCharactersConsumed() || SLASH == currentChar()) {
             return new NodeIdentifier(name);
-        } else {
-            checkValid(PRECONDITION_START == currentChar(), "Last element must be identifier, predicate or '/'");
-            return computeIdentifierWithPredicate(name);
         }
+
+        checkValid(PRECONDITION_START == currentChar(), "Last element must be identifier, predicate or '/'");
+        return computeIdentifierWithPredicate(name);
     }
 
     private PathArgument computeIdentifierWithPredicate(final QName name) {
@@ -134,7 +130,7 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     private Object nextCurrentFunctionPathValue() {
-        final String xPathSubStr = xPathString.substring(offset);
+        final String xPathSubStr = xpathString.substring(offset);
         final String pathKeyExpression = xPathSubStr.substring(0, xPathSubStr.indexOf(PRECONDITION_END));
         final String relPathKeyExpression = pathKeyExpression.substring(CURRENT_FUNCTION_INVOCATION_STR.length());
 
@@ -167,7 +163,7 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
             } else {
                 throw new IllegalArgumentException(String.format(
                         "Could not parse leafref path '%s'. Offset: %s : Reason: Malformed path component: '%s'.",
-                        xPathString, offset, pathComponent));
+                        xpathString, offset, pathComponent));
             }
         }
 
@@ -180,7 +176,6 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     /**
-     *
      * Returns following QName and sets offset to end of QName.
      *
      * @return following QName.
@@ -188,7 +183,8 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     private QName nextQName() {
         // Consume prefix or identifier
         final String maybePrefix = nextIdentifier();
-        final String prefix, localName;
+        final String prefix;
+        final String localName;
         if (!allCharactersConsumed() && COLON == currentChar()) {
             // previous token is prefix;
             prefix = maybePrefix;
@@ -202,14 +198,12 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     /**
-     * Returns true if all characters from input string
-     * were consumed.
+     * Returns true if all characters from input string were consumed.
      *
-     * @return true if all characters from input string
-     * were consumed.
+     * @return true if all characters from input string were consumed.
      */
     private boolean allCharactersConsumed() {
-        return offset == xPathString.length();
+        return offset == xpathString.length();
     }
 
     private QName createQName(final String prefix, final String localName) {
@@ -231,7 +225,6 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     /**
-     *
      * Skips current char if it equals expected otherwise fails parsing.
      *
      * @param expected Expected character
@@ -243,20 +236,19 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
     }
 
     /**
-     *
      * Fails parsing if condition is not met.
      *
-     * In case of error provides pointer to failed leafref,
-     * offset on which failure occured with explanation.
+     * <p>
+     * In case of error provides pointer to failed leafref, offset on which failure occured with explanation.
      *
      * @param condition Fails parsing if {@code condition} is false
      * @param errorMsg Error message which will be provided to user.
-     * @param attributes
+     * @param attributes Message attributes
      */
     private void checkValid(final boolean condition, final String errorMsg, final Object... attributes) {
         if (!condition) {
             throw new IllegalArgumentException(String.format(
-                    "Could not parse leafref path '%s'. Offset: %s : Reason: %s", xPathString, offset,
+                    "Could not parse leafref path '%s'. Offset: %s : Reason: %s", xpathString, offset,
                     String.format(errorMsg, attributes)));
         }
     }
@@ -267,19 +259,18 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
      * @return character at current offset.
      */
     private char currentChar() {
-        return xPathString.charAt(offset);
+        return xpathString.charAt(offset);
     }
 
     /**
-     * Increases processing offset by 1
+     * Increments processing offset by 1.
      */
     private void skipCurrentChar() {
         offset++;
     }
 
     /**
-     * Skip whitespace characters, sets offset to first following
-     * non-whitespace character.
+     * Skip whitespace characters, sets offset to first following non-whitespace character.
      */
     private void skipWhitespaces() {
         nextSequenceEnd(WSP);
@@ -293,14 +284,15 @@ final class LeafrefXPathStringParsingPathArgumentBuilder implements Builder<List
      */
     private String nextIdentifier() {
         int start = offset;
-        checkValid(IDENTIFIER_FIRST_CHAR.matches(currentChar()), "Identifier must start with character from set 'a-zA-Z_'");
+        checkValid(IDENTIFIER_FIRST_CHAR.matches(currentChar()),
+                "Identifier must start with character from set 'a-zA-Z_'");
         nextSequenceEnd(IDENTIFIER);
-        return xPathString.substring(start, offset);
+        return xpathString.substring(start, offset);
     }
 
     private void nextSequenceEnd(final CharMatcher matcher) {
-        while (!allCharactersConsumed() && matcher.matches(xPathString.charAt(offset))) {
+        while (!allCharactersConsumed() && matcher.matches(xpathString.charAt(offset))) {
             offset++;
         }
     }
-}
\ No newline at end of file
+}
index efba94a64cae69cc8fc9a0721cdedfcfa906057c..6ae6c8d5b90b3dc3b8194110ba637147bbd22bdd 100644 (file)
@@ -29,7 +29,8 @@ final class NormalizedNodeContextSupport extends ContextSupport {
         this.root = new NormalizedNodeContext(this, navigator.getRootNode(), null);
     }
 
-    static NormalizedNodeContextSupport create(final JaxenDocument document, final Converter<String, QNameModule> prefixes) {
+    static NormalizedNodeContextSupport create(final JaxenDocument document,
+            final Converter<String, QNameModule> prefixes) {
         final ConverterNamespaceContext context = new ConverterNamespaceContext(prefixes);
         final NormalizedNodeNavigator navigator = new NormalizedNodeNavigator(context, document);
 
index 78e61844d537c6f1355ddb469512fe04631c8c98..cd0c9954903167948c844ebcdbf3d96760ca122c 100644 (file)
@@ -212,6 +212,17 @@ final class NormalizedNodeNavigator extends DefaultNavigator implements NamedAcc
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public Iterator<NormalizedNodeContext> getChildAxisIterator(final Object contextNode) {
+        final NormalizedNodeContext ctx = cast(contextNode);
+        final NormalizedNode<?, ?> node = ctx.getNode();
+        if (node instanceof DataContainerNode) {
+            return Iterators.transform(((DataContainerNode<?>) node).getValue().iterator(), ctx);
+        }
+
+        return null;
+    }
+
     @Override
     public Iterator<NormalizedNodeContext> getChildAxisIterator(final Object contextNode, final String localName,
             final String namespacePrefix, final String namespaceURI) {
@@ -241,8 +252,7 @@ final class NormalizedNodeNavigator extends DefaultNavigator implements NamedAcc
     }
 
     @Override
-    public Iterator<? extends Entry<?, ?>> getAttributeAxisIterator(final Object contextNode, final String localName, final String namespacePrefix,
-            final String namespaceURI) {
+    public Iterator<? extends Entry<?, ?>> getAttributeAxisIterator(final Object contextNode) {
         final NormalizedNode<?, ?> node = contextNode(contextNode);
         if (node instanceof AttributesContainer) {
             final Map<QName, String> attributes = ((AttributesContainer) node).getAttributes();
@@ -250,20 +260,25 @@ final class NormalizedNodeNavigator extends DefaultNavigator implements NamedAcc
                 return null;
             }
 
-            final QName qname = resolveQName(node, namespacePrefix, localName);
-            final String value = attributes.get(qname);
-            return value == null ? null : Iterators.singletonIterator(new SimpleImmutableEntry<>(qname, value));
+            return attributes.entrySet().iterator();
         }
 
         return null;
     }
 
     @Override
-    public Iterator<NormalizedNodeContext> getChildAxisIterator(final Object contextNode) {
-        final NormalizedNodeContext ctx = cast(contextNode);
-        final NormalizedNode<?, ?> node = ctx.getNode();
-        if (node instanceof DataContainerNode) {
-            return Iterators.transform(((DataContainerNode<?>) node).getValue().iterator(), ctx);
+    public Iterator<? extends Entry<?, ?>> getAttributeAxisIterator(final Object contextNode, final String localName,
+            final String namespacePrefix, final String namespaceURI) {
+        final NormalizedNode<?, ?> node = contextNode(contextNode);
+        if (node instanceof AttributesContainer) {
+            final Map<QName, String> attributes = ((AttributesContainer) node).getAttributes();
+            if (attributes.isEmpty()) {
+                return null;
+            }
+
+            final QName qname = resolveQName(node, namespacePrefix, localName);
+            final String value = attributes.get(qname);
+            return value == null ? null : Iterators.singletonIterator(new SimpleImmutableEntry<>(qname, value));
         }
 
         return null;
@@ -276,33 +291,21 @@ final class NormalizedNodeNavigator extends DefaultNavigator implements NamedAcc
     }
 
     @Override
-    public Iterator<NormalizedNodeContext> getAncestorAxisIterator(final Object contextNode) throws UnsupportedAxisException {
+    public Iterator<NormalizedNodeContext> getAncestorAxisIterator(final Object contextNode)
+            throws UnsupportedAxisException {
         final NormalizedNodeContext parent = cast(contextNode).getParent();
         return parent == null ? null : new NormalizedNodeContextIterator(parent);
     }
 
     @Override
-    public Iterator<? extends Entry<?, ?>> getAttributeAxisIterator(final Object contextNode) {
-        final NormalizedNode<?, ?> node = contextNode(contextNode);
-        if (node instanceof AttributesContainer) {
-            final Map<QName, String> attributes = ((AttributesContainer) node).getAttributes();
-            if (attributes.isEmpty()) {
-                return null;
-            }
-
-            return attributes.entrySet().iterator();
-        }
-
-        return null;
-    }
-
-    @Override
-    public Iterator<NormalizedNodeContext> getSelfAxisIterator(final Object contextNode) throws UnsupportedAxisException {
+    public Iterator<NormalizedNodeContext> getSelfAxisIterator(final Object contextNode)
+            throws UnsupportedAxisException {
         return Iterators.singletonIterator(cast(contextNode));
     }
 
     @Override
-    public Iterator<NormalizedNodeContext> getAncestorOrSelfAxisIterator(final Object contextNode) throws UnsupportedAxisException {
+    public Iterator<NormalizedNodeContext> getAncestorOrSelfAxisIterator(final Object contextNode)
+            throws UnsupportedAxisException {
         return new NormalizedNodeContextIterator(cast(contextNode));
     }
 
index ce2f6b2cacfc2c677ceca7b015bca85c3ab0303f..3530b5e0fbdd89c0f3f90cdce638792edd93fa86 100644 (file)
@@ -14,18 +14,23 @@ import org.jaxen.expr.ProcessingInstructionNodeStep;
 import org.jaxen.expr.TextNodeStep;
 
 abstract class StepListener {
+
     void onAll(final AllNodeStep step) {
 
     }
+
     void onComment(final CommentNodeStep step) {
 
     }
+
     void onName(final NameStep step) {
 
     }
+
     void onProcessingInstruction(final ProcessingInstructionNodeStep step) {
 
     }
+
     void onTest(final TextNodeStep step) {
 
     }
index 429697d2f73ebbb718f06979e17404ffebb4b2cf..e7f6cba442ef835d71e4b441fd9e4f789972e8e0 100644 (file)
@@ -68,7 +68,7 @@ final class YangFunctionContext implements FunctionContext {
         }
 
         Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass());
-        return ((NormalizedNodeContext) context);
+        return (NormalizedNodeContext) context;
     };
 
     // re-match(string subject, string pattern) function as per https://tools.ietf.org/html/rfc7950#section-10.2.1
@@ -103,7 +103,8 @@ final class YangFunctionContext implements FunctionContext {
 
         final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context;
         final SchemaContext schemaContext = getSchemaContext(currentNodeContext);
-        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext, currentNodeContext);
+        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext,
+                currentNodeContext);
 
         final Object nodeValue = currentNodeContext.getNode().getValue();
 
@@ -114,8 +115,9 @@ final class YangFunctionContext implements FunctionContext {
 
         if (correspondingSchemaNode.getType() instanceof LeafrefTypeDefinition) {
             final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) correspondingSchemaNode.getType();
-            final RevisionAwareXPath xPath = leafrefType.getPathStatement();
-            return getNodeReferencedByLeafref(xPath, currentNodeContext, schemaContext, correspondingSchemaNode, nodeValue);
+            final RevisionAwareXPath xpath = leafrefType.getPathStatement();
+            return getNodeReferencedByLeafref(xpath, currentNodeContext, schemaContext, correspondingSchemaNode,
+                    nodeValue);
         }
 
         return null;
@@ -137,11 +139,11 @@ final class YangFunctionContext implements FunctionContext {
         return null;
     }
 
-    private static NormalizedNode<?, ?> getNodeReferencedByLeafref(final RevisionAwareXPath xPath,
+    private static NormalizedNode<?, ?> getNodeReferencedByLeafref(final RevisionAwareXPath xpath,
             final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
             final TypedSchemaNode correspondingSchemaNode, final Object nodeValue) {
-        final NormalizedNode<?, ?> referencedNode = xPath.isAbsolute() ? getNodeReferencedByAbsoluteLeafref(xPath,
-                currentNodeContext, schemaContext, correspondingSchemaNode) : getNodeReferencedByRelativeLeafref(xPath,
+        final NormalizedNode<?, ?> referencedNode = xpath.isAbsolute() ? getNodeReferencedByAbsoluteLeafref(xpath,
+                currentNodeContext, schemaContext, correspondingSchemaNode) : getNodeReferencedByRelativeLeafref(xpath,
                 currentNodeContext, schemaContext, correspondingSchemaNode);
 
         if (referencedNode instanceof LeafSetNode) {
@@ -155,11 +157,11 @@ final class YangFunctionContext implements FunctionContext {
         return null;
     }
 
-    private static NormalizedNode<?, ?> getNodeReferencedByAbsoluteLeafref(final RevisionAwareXPath xPath,
+    private static NormalizedNode<?, ?> getNodeReferencedByAbsoluteLeafref(final RevisionAwareXPath xpath,
             final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
             final TypedSchemaNode correspondingSchemaNode) {
         final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder(
-                xPath.toString(), schemaContext, correspondingSchemaNode, currentNodeContext);
+                xpath.toString(), schemaContext, correspondingSchemaNode, currentNodeContext);
         final List<PathArgument> pathArguments = builder.build();
         final NormalizedNodeNavigator navigator = (NormalizedNodeNavigator) currentNodeContext.getNavigator();
         final NormalizedNode<?, ?> rootNode = navigator.getRootNode();
@@ -174,11 +176,11 @@ final class YangFunctionContext implements FunctionContext {
         return null;
     }
 
-    private static NormalizedNode<?, ?> getNodeReferencedByRelativeLeafref(final RevisionAwareXPath xPath,
+    private static NormalizedNode<?, ?> getNodeReferencedByRelativeLeafref(final RevisionAwareXPath xpath,
             final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
             final TypedSchemaNode correspondingSchemaNode) {
         NormalizedNodeContext relativeNodeContext = currentNodeContext;
-        final StringBuilder xPathStringBuilder = new StringBuilder(xPath.toString());
+        final StringBuilder xPathStringBuilder = new StringBuilder(xpath.toString());
         // strip the relative path of all ../ at the beginning
         while (xPathStringBuilder.indexOf("../") == 0) {
             xPathStringBuilder.delete(0, 3);
@@ -226,7 +228,8 @@ final class YangFunctionContext implements FunctionContext {
 
         final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context;
         final SchemaContext schemaContext = getSchemaContext(currentNodeContext);
-        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext, currentNodeContext);
+        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext,
+            currentNodeContext);
 
         if (!(correspondingSchemaNode.getType() instanceof IdentityrefTypeDefinition)) {
             return Boolean.FALSE;
@@ -249,14 +252,17 @@ final class YangFunctionContext implements FunctionContext {
         return Boolean.valueOf(ancestorIdentities.contains(identityArgSchemaNode));
     };
 
-    // derived-from-or-self(node-set nodes, string identity) function as per https://tools.ietf.org/html/rfc7950#section-10.4.2
+    // derived-from-or-self(node-set nodes, string identity) function as per
+    // https://tools.ietf.org/html/rfc7950#section-10.4.2
     private static final Function DERIVED_FROM_OR_SELF_FUNCTION = (context, args) -> {
         if (args == null || args.size() != 1) {
-            throw new FunctionCallException("derived-from-or-self() takes two arguments: node-set nodes, string identity");
+            throw new FunctionCallException(
+                "derived-from-or-self() takes two arguments: node-set nodes, string identity");
         }
 
         if (!(args.get(0) instanceof String)) {
-            throw new FunctionCallException("Argument 'identity' of derived-from-or-self() function should be a String.");
+            throw new FunctionCallException(
+                "Argument 'identity' of derived-from-or-self() function should be a String.");
         }
 
         final String identityArg = (String) args.get(0);
@@ -265,7 +271,8 @@ final class YangFunctionContext implements FunctionContext {
 
         final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context;
         final SchemaContext schemaContext = getSchemaContext(currentNodeContext);
-        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext, currentNodeContext);
+        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext,
+            currentNodeContext);
 
         if (!(correspondingSchemaNode.getType() instanceof IdentityrefTypeDefinition)) {
             return Boolean.FALSE;
@@ -347,8 +354,8 @@ final class YangFunctionContext implements FunctionContext {
             }
         }
 
-        throw new IllegalArgumentException(String.format("Identity %s does not have a corresponding" +
-                " identity schema node in the module %s.", identityQName, module));
+        throw new IllegalArgumentException(String.format("Identity %s does not have a corresponding"
+                    + " identity schema node in the module %s.", identityQName, module));
     }
 
     // enum-value(node-set nodes) function as per https://tools.ietf.org/html/rfc7950#section-10.5.1
@@ -391,7 +398,8 @@ final class YangFunctionContext implements FunctionContext {
                 enumName, enumerationType));
     }
 
-    // bit-is-set(node-set nodes, string bit-name) function as per https://tools.ietf.org/html/rfc7950#section-10.6.1
+    // bit-is-set(node-set nodes, string bit-name) function as per
+    // https://tools.ietf.org/html/rfc7950#section-10.6.1
     private static final Function BIT_IS_SET_FUNCTION = (context, args) -> {
         if (args == null || args.size() != 1) {
             throw new FunctionCallException("bit-is-set() takes two arguments: node-set nodes, string bit-name");
@@ -407,7 +415,8 @@ final class YangFunctionContext implements FunctionContext {
 
         final NormalizedNodeContext currentNodeContext = (NormalizedNodeContext) context;
         final SchemaContext schemaContext = getSchemaContext(currentNodeContext);
-        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext, currentNodeContext);
+        final TypedSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(schemaContext,
+            currentNodeContext);
 
         final TypeDefinition<?> nodeType = correspondingSchemaNode.getType();
         if (!(nodeType instanceof BitsTypeDefinition)) {
@@ -499,6 +508,8 @@ final class YangFunctionContext implements FunctionContext {
                     return ENUM_VALUE_FUNCTION;
                 case "re-match":
                     return REMATCH_FUNCTION;
+                default:
+                    break;
             }
         }
 
index b654b378a243b0162d36e32fc6476c6227d3bbc2..687472518dbf3e3179a2b4f186b2de303a9f3164 100644 (file)
@@ -49,7 +49,7 @@ public class BitIsSetXPathFunctionTest {
     private static JaxenSchemaContextFactory jaxenSchemaContextFactory;
 
     private static QNameModule fooModule;
-    private static QName myContainer; 
+    private static QName myContainer;
     private static QName myList;
     private static QName flags;
     private static QName ordinaryLeaf;
@@ -131,7 +131,8 @@ public class BitIsSetXPathFunctionTest {
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
-        final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(invalidNodeValueType));
+        final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(
+                    invalidNodeValueType));
 
         final BiMap<String, QNameModule> converterBiMap = HashBiMap.create();
         converterBiMap.put("foo-prefix", fooModule);
@@ -231,4 +232,4 @@ public class BitIsSetXPathFunctionTest {
                 .node(new NodeIdentifierWithPredicates(myList, keys)).node(flags);
         return path;
     }
-}
\ No newline at end of file
+}
index 539d9fc803cc8c53ed1c26e838472f908b897c94..507b522b910db6bd1544d899d9f3aee4a7a7355d 100644 (file)
@@ -90,10 +90,11 @@ public class DerefXPathFunctionTest {
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
 
-        final LeafNode<?> referencedLeafNode = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(referencedLeaf))
-                .withValue("referenced-leaf-node-value").build();
+        final LeafNode<?> referencedLeafNode = Builders.leafBuilder().withNodeIdentifier(
+            new NodeIdentifier(referencedLeaf)).withValue("referenced-leaf-node-value").build();
 
-        final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNodeForIIdTest(referencedLeafNode));
+        final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNodeForIIdTest(
+            referencedLeafNode));
 
         final BiMap<String, QNameModule> converterBiMap = HashBiMap.create();
         converterBiMap.put("foo-prefix", fooModule);
index c08dd24dcf25e307b3d214007152a4af0f5b9bac..b53de5aae1ab716717bfd662338ea668d59579f4 100644 (file)
@@ -47,7 +47,7 @@ public class DerivedFromXPathFunctionTest {
     private static JaxenSchemaContextFactory jaxenSchemaContextFactory;
 
     private static QNameModule barModule;
-    private static QName myContainer; 
+    private static QName myContainer;
     private static QName myList;
     private static QName keyLeaf;
     private static QName idrefLeaf;
@@ -181,7 +181,8 @@ public class DerivedFromXPathFunctionTest {
             getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "unknown-prefix:id-a3");
             fail("Function call should have failed on unresolved prefix of the identity argument.");
         } catch (IllegalArgumentException ex) {
-            assertEquals("Cannot resolve prefix 'unknown-prefix' from identity 'unknown-prefix:id-a3'.", ex.getMessage());
+            assertEquals("Cannot resolve prefix 'unknown-prefix' from identity 'unknown-prefix:id-a3'.",
+                ex.getMessage());
         }
     }
 
@@ -242,8 +243,8 @@ public class DerivedFromXPathFunctionTest {
             fail("Function call should have failed on unknown identity argument.");
         } catch (IllegalArgumentException ex) {
             assertTrue(ex.getMessage().startsWith(
-                    "Identity (foo-ns?revision=2017-04-03)id-a333 does not have a corresponding identity schema " +
-                    "node in the module"));
+                    "Identity (foo-ns?revision=2017-04-03)id-a333 does not have a corresponding identity schema "
+                    "node in the module"));
         }
     }
 
@@ -304,4 +305,4 @@ public class DerivedFromXPathFunctionTest {
                 .node(new NodeIdentifierWithPredicates(myList, keys)).node(idrefLeaf);
         return path;
     }
-}
\ No newline at end of file
+}
index b2c5284e1150bcc8e5defd75bd787cbde66c0656..d7c62fdd7baaee87124267350147127bcac33b51 100644 (file)
@@ -77,8 +77,8 @@ public class JaxenTest {
         xpathSchemaContext = new JaxenSchemaContextFactory().createContext(schemaContext);
         assertNotNull(xpathSchemaContext);
 
-        xpathExpression = xpathSchemaContext.compileExpression(createSchemaPath(), createPrefixes(), createXPath
-                (false));
+        xpathExpression = xpathSchemaContext.compileExpression(createSchemaPath(), createPrefixes(), createXPath(
+                    false));
         assertNotNull(xpathExpression);
 
         xpathDocument = xpathSchemaContext.createDocument(createNormalizedNodes());
@@ -91,8 +91,8 @@ public class JaxenTest {
                 .evaluate(xpathDocument, createYangInstanceIdentifier(false));
         assertNotNull(resultExpressionEvaluate);
         assertTrue(resultExpressionEvaluate.isPresent());
-        XPathResult<?> xPathResult = resultExpressionEvaluate.get();
-        Object value = ((XPathNodesetResult) xPathResult).getValue().iterator().next().getValue();
+        XPathResult<?> xpathResult = resultExpressionEvaluate.get();
+        Object value = ((XPathNodesetResult) xpathResult).getValue().iterator().next().getValue();
         assertNotNull(value);
         assertEquals("three", value);
 
@@ -135,14 +135,14 @@ public class JaxenTest {
         Optional<? extends XPathResult<?>> resultExpressionEvaluate = xpathExpressionWithPredicates
                 .evaluate(xpathDocument, createYangInstanceIdentifier(true));
         assertTrue(resultExpressionEvaluate.isPresent());
-        XPathResult<?> xPathResult = resultExpressionEvaluate.get();
-        Object value = ((XPathNodesetResult) xPathResult).getValue().iterator().next().getValue();
+        XPathResult<?> xpathResult = resultExpressionEvaluate.get();
+        Object value = ((XPathNodesetResult) xpathResult).getValue().iterator().next().getValue();
         assertEquals("two", value);
     }
 
     @Test(expected = VerifyException.class)
     public void testIsMethodsInNodeNavigator() {
-        assertNotNull(navigator.isDocument("test"));
+        assertTrue(navigator.isDocument("test"));
     }
 
     @Test(expected = XPathExpressionException.class)
@@ -163,18 +163,19 @@ public class JaxenTest {
             function.call(context, list);
             fail();
         } catch (VerifyException e) {
+            // Expected
         }
 
         yangFun.getFunction("urn:opendaylight.test2", "test2", "root");
     }
 
-    /**
-     * @return container-a -> container-b -> leaf-d
-     *         list-a -> list-b -> leaf-b
+    /*
+     * container-a -> container-b -> leaf-d
+     *           list-a -> list-b -> leaf-b
      */
-    private YangInstanceIdentifier createYangInstanceIdentifier(Boolean withPredicates) {
-        YangInstanceIdentifier testYangInstanceIdentifier = YangInstanceIdentifier.of(containerAQName).node
-                (containerBQName).node(leafDQName);
+    private YangInstanceIdentifier createYangInstanceIdentifier(final boolean withPredicates) {
+        YangInstanceIdentifier testYangInstanceIdentifier = YangInstanceIdentifier.of(containerAQName).node(
+                containerBQName).node(leafDQName);
         if (withPredicates) {
             final Map<QName, Object> keys1 = new HashMap<>();
             keys1.put(leafAQName, "bar");
@@ -194,12 +195,8 @@ public class JaxenTest {
         return testYangInstanceIdentifier;
     }
 
-    private static String createXPath(boolean withPredicates) {
-        String xPath = "/container-a/container-b/leaf-d";
-        if (withPredicates) {
-            xPath = "/list-a[leaf-a='bar']/list-b[leaf-b='two']/leaf-b";
-        }
-        return xPath;
+    private static String createXPath(final boolean withPredicates) {
+        return withPredicates ? "/list-a[leaf-a='bar']/list-b[leaf-b='two']/leaf-b" : "/container-a/container-b/leaf-d";
     }
 
     private Converter<String, QNameModule> createPrefixes() {
@@ -209,14 +206,12 @@ public class JaxenTest {
         return Maps.asConverter(currentConverter);
     }
 
-    /**
-     * @return rootQName -> listAQName -> leafAQName
-     */
+    // rootQName -> listAQName -> leafAQName
     private  SchemaPath createSchemaPath() {
         return SchemaPath.create(true, rootQName, listAQName, leafAQName);
     }
 
-    private SchemaContext createSchemaContext() throws IOException, URISyntaxException, ReactorException {
+    private static SchemaContext createSchemaContext() throws IOException, URISyntaxException, ReactorException {
         return YangParserTestUtils.parseYangSources("/test/documentTest");
     }
 
index 798dbeab42bb3e6dbbbc4faa027f150e72cfb67f..27aa868a72301ca2cd78ad87c272430a10586d32 100644 (file)
@@ -40,7 +40,7 @@ final class TestUtils {
     }
 
     /**
-     * Returns a test document
+     * Returns a test document.
      *
      * <pre>
      * root
@@ -58,7 +58,7 @@ final class TestUtils {
      *                  leaf-d "three"
      * </pre>
      *
-     * @return
+     * @return A test document instance.
      */
     public static NormalizedNode<?, ?> createNormalizedNodes() {
         return ImmutableContainerNodeBuilder
@@ -76,12 +76,11 @@ final class TestUtils {
                         .build())
                 .withChild(ImmutableContainerNodeBuilder.create()
                         .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONTAINER_A_QNAME))
-                        .withChild(ImmutableContainerNodeBuilder.create().
-                                withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier
-                                        (CONTAINER_B_QNAME))
+                        .withChild(ImmutableContainerNodeBuilder.create()
+                            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONTAINER_B_QNAME))
                                 .withChild(ImmutableNodes.leafNode(LEAF_D_QNAME, THREE))
                                 .build())
                         .build())
                 .build();
     }
-}
\ No newline at end of file
+}