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

org.snapscript.tree.reference.GenericArgumentList Maven / Gradle / Ivy

package org.snapscript.tree.reference;

import java.util.ArrayList;
import java.util.List;

import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.error.InternalStateException;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.type.Type;
import org.snapscript.tree.constraint.GenericList;

public class GenericArgumentList implements GenericList {

   private final GenericArgument[] arguments;

   public GenericArgumentList(GenericArgument... arguments) {
      this.arguments = arguments;
   }
   
   public List getImports(Scope scope) throws Exception {
      List result = new ArrayList();
      
      for(GenericArgument argument : arguments) {
         Constraint constraint = argument.getConstraint();
         List imports = constraint.getImports(scope);
         
         result.addAll(imports);
      }
      return result;
   }
   
   @Override
   public List getGenerics(Scope scope) throws Exception {
      List result = new ArrayList();
      
      for(GenericArgument argument : arguments) {
         Constraint constraint = argument.getConstraint();
         Type type = constraint.getType(scope);
         
         if(type == null) {
            throw new InternalStateException("Could not find constraint");
         }
         result.add(constraint);
      }
      return result;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy