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

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

package org.snapscript.agent.debug;

import java.util.Collections;
import java.util.List;

public class ExpressionScopeNode implements ScopeNode {
   
   private final ExpressionProcessor processor;
   private final VariableNameEncoder encoder;
   private final ScopeNodeBuilder builder;
   private final String expression;
   private final boolean refresh;
   
   public ExpressionScopeNode(ScopeNodeBuilder builder, ExpressionProcessor processor, VariableNameEncoder encoder, String expression, boolean refresh) {
      this.expression = expression;
      this.processor = processor;
      this.refresh = refresh;
      this.encoder = encoder;
      this.builder = builder;
   }
   
   @Override
   public int getDepth() {
      return 0;
   }
   
   @Override
   public String getName() {
      return "";
   }
   
   @Override
   public String getPath() {
      return "";
   }

   @Override
   public List getNodes() {
      Object object = processor.evaluate(expression, refresh);
      
      if(expression != null) {
         String token = expression.trim();
         int length = token.length();
         
         if(length > 0) { // make sure something is evaluated
            String path = encoder.encode(expression);
            ScopeNode node = builder.createNode(path, expression, object, 0, 0);
         
            if(node != null) {
               return Collections.singletonList(node);
            }
         }
      }
      return Collections.emptyList();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy