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

org.snapscript.core.link.ImportPathSource Maven / Gradle / Ivy

package org.snapscript.core.link;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

public class ImportPathSource {
   
   private volatile DefaultImportReader reader;
   private volatile ImportPath path;
   
   public ImportPathSource(String file) {
      this.reader = new DefaultImportReader(file);
   }
   
   public ImportPath getPath() {
      if(path == null) {
         DefaultPath local = new DefaultPath();
         
         for(DefaultImport entry : reader) {
            Set imports = entry.getImports();
            Set modules = entry.getModules();
            String name = entry.getAlias();
            
            if(entry.isInclude()) {
               local.defaults.addAll(modules);
            }
            for(String type : imports) {
               local.types.put(type, modules);
            }
            local.aliases.put(name, modules);
         }
         path = local;
      }
      return path;
   }
   
   private static class DefaultPath implements ImportPath {

      private final Map> aliases;
      private final Map> types;
      private final Set defaults;
      
      public DefaultPath() {
         this.aliases = new LinkedHashMap>();
         this.types = new LinkedHashMap>();
         this.defaults = new LinkedHashSet();
      }
      
      @Override
      public Map> getAliases() {
         return aliases;
      }

      @Override
      public Map> getTypes() {
         return types;
      }

      @Override
      public Set getDefaults() {
         return defaults;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy