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

org.snapscript.tree.variable.ConstantResolver Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy