
org.snapscript.tree.variable.ConstantResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.variable;
import org.snapscript.core.Context;
import org.snapscript.core.Module;
import org.snapscript.core.ModuleScopeBinder;
import org.snapscript.core.Scope;
import org.snapscript.core.Type;
import org.snapscript.core.TypeExtractor;
public class ConstantResolver {
private final ModuleScopeBinder binder;
public ConstantResolver() {
this.binder = new ModuleScopeBinder();
}
public Object resolve(Scope scope, String name) {
Scope current = binder.bind(scope); // this could be slow
Module module = current.getModule();
Type type = module.getType(name); // this is super slow if a variable is referenced
Type parent = current.getType();
if(type == null) {
Object result = module.getModule(name);
if(result == null && parent != null) {
Context context = module.getContext();
TypeExtractor extractor = context.getExtractor();
return extractor.getType(parent, name);
}
return result;
}
return type;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy