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

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

package org.snapscript.core.type.index;

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

import org.snapscript.core.constraint.AnyConstraint;
import org.snapscript.core.constraint.Constraint;

public class ClassHierarchyIndexer {

   private final GenericConstraintResolver resolver;
   private final Constraint any;
   
   public ClassHierarchyIndexer() {
      this.resolver = new GenericConstraintResolver();
      this.any = new AnyConstraint();
   }
   
   public List index(Class source) throws Exception {
      List hierarchy = new ArrayList();
      
      if(source == Object.class) {
         hierarchy.add(any);
      } else {
         Type[] interfaces = source.getGenericInterfaces();
         Type base = source.getGenericSuperclass(); // the super class
         
         if(base != null) {
            Constraint constraint = resolver.resolve(base);            
            hierarchy.add(constraint);
         }
         for (Type entry : interfaces) {
            Constraint constraint = resolver.resolve(entry);    
            hierarchy.add(constraint);
         }
      }
      return hierarchy;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy