
org.snapscript.studio.agent.debug.ScopeNodeTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-agent Show documentation
Show all versions of snap-agent Show documentation
Dynamic scripting for the JVM
The newest version!
package org.snapscript.studio.agent.debug;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.scope.ScopeState;
import org.snapscript.core.scope.index.ScopeTable;
import org.snapscript.core.variable.Value;
public class ScopeNodeTree implements ScopeNode {
private final PropertyNameParser parser;
private final ScopeNodeBuilder builder;
private final List nodes;
private final Scope scope;
public ScopeNodeTree(ScopeNodeBuilder builder, Scope scope) {
this.nodes = new ArrayList();
this.parser = new PropertyNameParser();
this.builder = builder;
this.scope = scope;
}
@Override
public int getDepth() {
return 0;
}
@Override
public String getName() {
return "";
}
@Override
public String getAlias() {
return "";
}
@Override
public String getPath() {
return "";
}
@Override
public List getNodes() {
if(nodes.isEmpty()) {
ScopeState state = scope.getState();
ScopeTable table = scope.getTable();
Iterator names = state.iterator();
Iterator locals = table.iterator();
if(names.hasNext() || locals.hasNext()) {
Set done = new HashSet();
while(locals.hasNext()) {
Value local = locals.next();
if(local != null) {
String name = local.getName();
Object object = local.getValue();
if(done.add(name)) {
int modifiers = local.getModifiers();
ScopeNode node = builder.createNode(name, name, name, object, modifiers, 0);
if(node != null) {
nodes.add(node);
}
}
}
}
while(names.hasNext()) {
String name = names.next();
Value value = state.getValue(name);
if(value != null) { // don't override stack locals
String actual = parser.parse(name);
if(done.add(name)){
Object object = value.getValue();
int modifiers = value.getModifiers();
ScopeNode node = builder.createNode(name, actual, name, object, modifiers, 0);
if(node != null) {
nodes.add(node);
}
}
}
}
}
}
return nodes;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy