lkishalmi commented on code in PR #7097:
URL: https://github.com/apache/netbeans/pull/7097#discussion_r1518721260


##########
ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLTreeWalker.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.hcl.ast;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.function.Predicate;
+
+/**
+ *
+ * @author lkishalmi
+ */
+public final class HCLTreeWalker {
+    public record Step(HCLElement<HCLElement> parent, HCLElement<HCLElement> 
node, int depth) {}
+
+    private HCLTreeWalker() {}
+
+    public static Iterator<Step> depthFirst(HCLElement<HCLElement> root) {
+        var process = new LinkedList<Step>();
+        process.push(new Step(null, root, 0));
+        return new Iterator<>() {
+
+            @Override
+            public boolean hasNext() {
+                return !process.isEmpty();
+            }
+
+            @Override
+            public Step next() {
+                Step current = process.pop();
+                current.node.elements().forEach((HCLElement e) -> 
process.push(new Step(current.node, e, current.depth + 1)));
+                return current;
+            }
+        };
+    }
+
+    public static Iterator<Step> breadthFirst(HCLElement<HCLElement> root) {
+        var process = new LinkedList<Step>();
+        process.push(new Step(null, root, 0));
+        return new Iterator<>() {
+
+            @Override
+            public boolean hasNext() {
+                return !process.isEmpty();
+            }
+
+            @Override
+            public Step next() {
+                Step current = process.pop();
+                current.node.elements().forEach((HCLElement e) -> 
process.add(new Step(current.node, e, current.depth + 1)));
+                return current;
+            }
+        };
+    }

Review Comment:
   Good catch! In progress versions of the Semantic analyzers used these 
iterator. Removed them in the recent commit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to