All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.agent.debug.ScopeNodeTree Maven / Gradle / Ivy

package org.snapscript.agent.debug;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.snapscript.core.Scope;
import org.snapscript.core.State;
import org.snapscript.core.Value;

public class ScopeNodeTree implements ScopeNode {
   
   private final ScopeNodeBuilder builder;
   private final List nodes;
   private final Scope scope;
   
   public ScopeNodeTree(ScopeNodeBuilder builder, Scope scope) {
      this.nodes = new ArrayList();
      this.builder = builder;
      this.scope = scope;
   }
   
   @Override
   public int getDepth() {
      return 0;
   }
   
   @Override
   public String getName() {
      return "";
   }
   
   @Override
   public String getPath() {
      return "";
   }
   
   @Override
   public List getNodes() {
      if(nodes.isEmpty()) {
         State state = scope.getState();
         Iterator names = state.iterator();
         
         if(names.hasNext()) {
            while(names.hasNext()) {
               String name = names.next();
               Value value = state.get(name);
               
               if(value != null) {
                  Object object = value.getValue();
                  int modifiers = value.getModifiers();
                  ScopeNode node = builder.createNode(name, name, object, modifiers, 0);
                  
                  if(node != null) {
                     nodes.add(node);
                  }
               }
            }
         }
      }
      return nodes;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy