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


##########
ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLContainer.java:
##########
@@ -18,33 +18,42 @@
  */
 package org.netbeans.modules.languages.hcl.ast;
 
-import java.util.Collection;
+import java.util.List;
 
 /**
  *
  * @author Laszlo Kishalmi
  */
-public sealed interface HCLContainer extends HCLAddressableElement permits 
HCLBlock, HCLDocument {
+public sealed abstract class HCLContainer implements HCLElement permits 
HCLBlock, HCLDocument {
 
-    public default Collection<? extends HCLBlock> blocks() {
-        return elements().stream()
-                .filter(HCLBlock.class::isInstance)
-                .map(HCLBlock.class::cast)
-                .toList();
+    protected final List<HCLElement> elements;
+    private final List<HCLBlock> blocks;
+    private final List<HCLAttribute> attributes;
+
+    protected HCLContainer(List<HCLElement> elements) {
+        this.elements = List.copyOf(elements);
+        this.blocks = 
elements.stream().filter(HCLBlock.class::isInstance).map(HCLBlock.class::cast).toList();
+        this.attributes = 
elements.stream().filter(HCLAttribute.class::isInstance).map(HCLAttribute.class::cast).toList();
+    }
+
+    public boolean hasBlock() {
+        return !blocks.isEmpty();
     }
 
-    public default Collection<? extends HCLAttribute> attributes() {
-        return elements().stream()
-                .filter(HCLAttribute.class::isInstance)
-                .map(HCLAttribute.class::cast)
-                .toList();
+    public boolean hasAttribute() {
+        return !attributes.isEmpty();
     }
 
-    public default boolean hasBlock() {
-        return elements().stream().anyMatch(HCLBlock.class::isInstance);
+    public List<HCLBlock> blocks() {
+        return blocks;
     }
 
-    public default boolean hasAttribute() {
-        return elements().stream().anyMatch(HCLAttribute.class::isInstance);
+    public List<HCLAttribute> attributes() {
+        return attributes;
+    }
+    
+    @Override
+    public List<? extends HCLElement> elements() {
+        return List.copyOf(elements);

Review Comment:
   nitpick `copyOf` already used in the constructor.



-- 
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