Remove LeafRefYangSyntaxErrorException 50/105350/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 11 Apr 2023 00:03:54 +0000 (02:03 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 11 Apr 2023 07:11:12 +0000 (09:11 +0200)
This exception is not used anywhere, remove it. Also update
LeafRefContextTreeBuilder to use ArrayList.

Change-Id: I89dd0f33c6418b0ce66dd7ecbf9dd7c6c6bcc16c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefContext.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefContextTreeBuilder.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefYangSyntaxErrorException.java [deleted file]

index 4a147bcd308a22137ff365daae864cc8ef1106e3..00efedf3485f433e0a60d2ca51109dd474b8d251 100644 (file)
@@ -61,11 +61,7 @@ public final class LeafRefContext extends AbstractEffectiveModelContextProvider
     }
 
     public static LeafRefContext create(final EffectiveModelContext ctx) {
-        try {
-            return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
-        } catch (LeafRefYangSyntaxErrorException e) {
-            throw new IllegalArgumentException(e);
-        }
+        return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
     }
 
     public boolean hasLeafRefContextChild() {
index 9b563c10b1f28888311e36f6988521d8b2380b71..57f63194f5f80af3a8dfafd04667bd49f86ebb94 100644 (file)
@@ -8,11 +8,9 @@
 package org.opendaylight.yangtools.yang.data.tree.leafref;
 
 import com.google.common.collect.ImmutableList;
-import java.util.Collection;
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -20,42 +18,38 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.PathExpression;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 
 final class LeafRefContextTreeBuilder {
-    private final List<LeafRefContext> leafRefs = new LinkedList<>();
+    private final List<LeafRefContext> leafRefs = new ArrayList<>();
     private final EffectiveModelContext schemaContext;
 
     LeafRefContextTreeBuilder(final EffectiveModelContext schemaContext) {
         this.schemaContext = schemaContext;
     }
 
-    LeafRefContext buildLeafRefContextTree() throws LeafRefYangSyntaxErrorException {
-        final SchemaInferenceStack stack = SchemaInferenceStack.of(schemaContext);
-        final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(SchemaContext.NAME, ImmutableList.of(),
-            schemaContext);
+    LeafRefContext buildLeafRefContextTree() {
+        final var stack = SchemaInferenceStack.of(schemaContext);
+        final var rootBuilder = new LeafRefContextBuilder(SchemaContext.NAME, ImmutableList.of(), schemaContext);
 
-        final Collection<? extends Module> modules = schemaContext.getModules();
-        for (final Module module : modules) {
-            for (final DataSchemaNode childNode : module.getChildNodes()) {
+        final var modules = schemaContext.getModules();
+        for (final var module : modules) {
+            for (var childNode : module.getChildNodes()) {
                 stack.enterSchemaTree(childNode.getQName());
-                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(childNode, stack);
+                final var childLeafRefContext = buildLeafRefContextReferencingTree(childNode, stack);
                 stack.exit();
                 if (childLeafRefContext.hasReferencingChild() || childLeafRefContext.isReferencing()) {
                     rootBuilder.addReferencingChild(childLeafRefContext, childLeafRefContext.getNodeName());
                 }
             }
         }
-        for (final Module module : modules) {
-            for (final DataSchemaNode childNode : module.getChildNodes()) {
+        for (final var module : modules) {
+            for (var childNode : module.getChildNodes()) {
                 stack.enterSchemaTree(childNode.getQName());
-                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(childNode, module,
-                        stack);
+                final var childLeafRefContext = buildLeafRefContextReferencedByTree(childNode, module, stack);
                 stack.exit();
                 if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
                     rootBuilder.addReferencedByChild(childLeafRefContext, childLeafRefContext.getNodeName());
@@ -75,7 +69,7 @@ final class LeafRefContextTreeBuilder {
             extractPath(stack), schemaContext);
 
         if (node instanceof DataNodeContainer container) {
-            for (final DataSchemaNode childNode : container.getChildNodes()) {
+            for (var childNode : container.getChildNodes()) {
                 stack.enterSchemaTree(childNode.getQName());
                 final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(childNode, stack);
                 stack.exit();
@@ -86,7 +80,7 @@ final class LeafRefContextTreeBuilder {
             }
         } else if (node instanceof ChoiceSchemaNode choice) {
             // :FIXME choice without case
-            for (final CaseSchemaNode caseNode : choice.getCases()) {
+            for (var caseNode : choice.getCases()) {
                 stack.enterSchemaTree(caseNode.getQName());
                 final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(caseNode, stack);
                 stack.exit();
@@ -97,19 +91,19 @@ final class LeafRefContextTreeBuilder {
             }
 
         } else if (node instanceof TypedDataSchemaNode typedNode) {
-            final TypeDefinition<?> type = typedNode.getType();
+            final var type = typedNode.getType();
 
             // FIXME: fix case when type is e.g. typedef -> typedef -> leafref
             if (type instanceof LeafrefTypeDefinition leafrefType) {
-                final PathExpression path = leafrefType.getPathStatement();
-                final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
-                final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(path);
+                final var path = leafrefType.getPathStatement();
+                final var leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
+                final var  leafRefPath = leafRefPathParser.parseLeafRefPath(path);
 
                 currentLeafRefContextBuilder.setLeafRefTargetPathString(path.getOriginalString());
                 currentLeafRefContextBuilder.setReferencing(true);
                 currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
 
-                final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
+                final var currentLeafRefContext = currentLeafRefContextBuilder.build();
                 leafRefs.add(currentLeafRefContext);
                 return currentLeafRefContext;
             }
@@ -120,13 +114,12 @@ final class LeafRefContextTreeBuilder {
 
     private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule,
             final SchemaInferenceStack stack) {
-        final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
-                extractPath(stack), schemaContext);
+        final var currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(), extractPath(stack),
+            schemaContext);
         if (node instanceof DataNodeContainer container) {
-            for (final DataSchemaNode childNode : container.getChildNodes()) {
+            for (var childNode : container.getChildNodes()) {
                 stack.enterSchemaTree(childNode.getQName());
-                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(childNode,
-                        currentModule, stack);
+                final var childLeafRefContext = buildLeafRefContextReferencedByTree(childNode, currentModule, stack);
                 stack.exit();
                 if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
                     currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext,
@@ -134,10 +127,9 @@ final class LeafRefContextTreeBuilder {
                 }
             }
         } else if (node instanceof ChoiceSchemaNode choice) {
-            for (final CaseSchemaNode caseNode : choice.getCases()) {
+            for (var caseNode : choice.getCases()) {
                 stack.enterSchemaTree(caseNode.getQName());
-                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(caseNode, currentModule,
-                        stack);
+                final var childLeafRefContext = buildLeafRefContextReferencedByTree(caseNode, currentModule, stack);
                 stack.exit();
                 if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
                     currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext,
@@ -145,10 +137,10 @@ final class LeafRefContextTreeBuilder {
                 }
             }
         } else if (node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode) {
-            final List<LeafRefContext> foundLeafRefs = getLeafRefsFor(currentModule, stack);
+            final var foundLeafRefs = getLeafRefsFor(currentModule, stack);
             if (!foundLeafRefs.isEmpty()) {
                 currentLeafRefContextBuilder.setReferencedBy(true);
-                for (final LeafRefContext leafRef : foundLeafRefs) {
+                for (var leafRef : foundLeafRefs) {
                     currentLeafRefContextBuilder.addReferencedByLeafRefCtx(leafRef.getNodeName(), leafRef);
                 }
             }
@@ -158,10 +150,10 @@ final class LeafRefContextTreeBuilder {
     }
 
     private List<LeafRefContext> getLeafRefsFor(final Module module, final SchemaInferenceStack stack) {
-        final LeafRefPath nodeXPath = LeafRefUtils.schemaPathToLeafRefPath(extractPath(stack), module);
-        final List<LeafRefContext> foundLeafRefs = new LinkedList<>();
-        for (final LeafRefContext leafref : leafRefs) {
-            final LeafRefPath leafRefTargetPath = leafref.getAbsoluteLeafRefTargetPath();
+        final var nodeXPath = LeafRefUtils.schemaPathToLeafRefPath(extractPath(stack), module);
+        final var foundLeafRefs = new ArrayList<LeafRefContext>();
+        for (var leafref: leafRefs) {
+            final var leafRefTargetPath = leafref.getAbsoluteLeafRefTargetPath();
             if (leafRefTargetPath.equals(nodeXPath)) {
                 foundLeafRefs.add(leafref);
             }
diff --git a/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefYangSyntaxErrorException.java b/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/leafref/LeafRefYangSyntaxErrorException.java
deleted file mode 100644 (file)
index d0f305e..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2013 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.data.tree.leafref;
-
-import static java.util.Objects.requireNonNull;
-
-public class LeafRefYangSyntaxErrorException extends Exception {
-    private static final long serialVersionUID = 1L;
-    private final String module;
-    private final int line;
-    private final int charPositionInLine;
-
-    public LeafRefYangSyntaxErrorException(final String module, final int line, final int charPositionInLine,
-            final String message) {
-        this(module, line, charPositionInLine, message, null);
-    }
-
-    public LeafRefYangSyntaxErrorException(final String module, final int line, final int charPositionInLine,
-            final String message, final Throwable cause) {
-        super(requireNonNull(message), cause);
-        this.module = module;
-        this.line = line;
-        this.charPositionInLine = charPositionInLine;
-    }
-
-    public String getModule() {
-        return module;
-    }
-
-    public int getLine() {
-        return line;
-    }
-
-    public int getCharPositionInLine() {
-        return charPositionInLine;
-    }
-
-    public String getFormattedMessage() {
-        final StringBuilder sb = new StringBuilder(getMessage());
-        if (module != null) {
-            sb.append(" in module ");
-            sb.append(module);
-        }
-        if (line != 0) {
-            sb.append(" on line ");
-            sb.append(line);
-            if (charPositionInLine != 0) {
-                sb.append(" character ");
-                sb.append(charPositionInLine);
-            }
-        }
-        return sb.toString();
-    }
-
-    @Override
-    public String toString() {
-        return this.getClass().getName() + ": " + getFormattedMessage();
-    }
-}