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

org.snapscript.core.type.index.GenericIndexer Maven / Gradle / Ivy

package org.snapscript.core.type.index;

import static java.util.Collections.EMPTY_LIST;

import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.List;

import org.snapscript.core.constraint.Constraint;

public class GenericIndexer {
   
   private final GenericConstraintResolver resolver;
   
   public GenericIndexer(TypeIndexer indexer){
      this.resolver = new GenericConstraintResolver();
   }
   
   public List index(Class type) {
      TypeVariable[] variables = type.getTypeParameters();
      
      if(variables.length > 0) {
         List constraints = new ArrayList();
         
         for(int i = 0; i < variables.length; i++) {
            TypeVariable variable = variables[i];            
            Constraint constraint = resolver.resolve(variable);
            
            constraints.add(constraint);
         }
         return constraints;
      }
      return EMPTY_LIST;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy