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

org.snapscript.studio.agent.debug.ScopeNodeTraverser Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.studio.agent.debug;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.snapscript.core.Context;
import org.snapscript.core.scope.Scope;
import org.snapscript.studio.agent.debug.ScopeNode;
import org.snapscript.studio.agent.debug.ScopeNodeBuilder;
import org.snapscript.studio.agent.debug.ScopeNodeTree;

public class ScopeNodeTraverser {
   
   private final Context context;
   private final Scope scope;
   
   public ScopeNodeTraverser(Context context, Scope scope) {
      this.context = context;
      this.scope = scope;
   }
   
   public Map> expand(Set expand) {
      Map> variables = new HashMap>();
      ScopeNodeBuilder builder = new ScopeNodeBuilder(variables, context);
      ScopeNode node = new ScopeNodeTree(builder, scope);
      
      if(!expand.isEmpty()) {
         for(String path : expand) {
            String[] parts = path.split("\\.");
            expand(node, parts, 0);
         }
      } else {
         node.getNodes(); // expand root
      }
      return variables;
   }

   private void expand(ScopeNode node, String[] parts, int index) {
      List children = node.getNodes();
      String match = parts[index];
      
      for(ScopeNode child : children) {
         String name = child.getName();
         
         if(name.equals(match)) {
            expand(child, parts, index+1);
            break;
         }
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy