![JAR search and dependency download from the Maven repository](/logo.png)
org.snapscript.agent.debug.ScopeExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.agent.debug;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.snapscript.core.Context;
import org.snapscript.core.Scope;
public class ScopeExtractor implements ScopeBrowser {
private final AtomicReference evaluate;
private final ScopeNodeEvaluator evaluator;
private final ScopeNodeTraverser traverser;
private final AtomicBoolean execute;
private final AtomicInteger counter;
private final Set watch;
private final Set local;
public ScopeExtractor(Context context, Scope scope) {
this.traverser = new ScopeNodeTraverser(context, scope);
this.evaluator = new ScopeNodeEvaluator(context, scope);
this.evaluate = new AtomicReference();
this.watch = new CopyOnWriteArraySet();
this.local = new CopyOnWriteArraySet();
this.execute = new AtomicBoolean();
this.counter = new AtomicInteger();
}
public ScopeVariableTree build() {
boolean refresh = execute.getAndSet(false);
String expression = evaluate.get();
Map> variables = traverser.expand(local);
Map> evaluation = evaluator.expand(watch, expression, refresh);
int change = counter.get();
return new ScopeVariableTree.Builder(change)
.withLocal(variables)
.withEvaluation(evaluation)
.build();
}
@Override
public void browse(Set expand) {
local.clear();
local.addAll(expand);
counter.getAndIncrement();
}
@Override
public void evaluate(Set expand, String expression) {
evaluate(expand, expression, false);
}
@Override
public void evaluate(Set expand, String expression, boolean refresh) {
watch.clear();
watch.addAll(expand);
evaluate.set(expression);
execute.set(refresh); // should we execute same expression again
counter.getAndIncrement();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy