[jboss-cvs] JBossAS SVN: r104605 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/hierarchy/spi and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 10 07:38:48 EDT 2010


Author: alesj
Date: 2010-05-10 07:38:47 -0400 (Mon, 10 May 2010)
New Revision: 104605

Modified:
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeHierarchyTestCase.java
Log:
Add new convinience hierarchy method.

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -109,7 +109,7 @@
       }
    }
 
-   public Set<TypeInfo> getInheritedClasses(URL url, TypeInfo superTypeToLookFor)
+   public Set<TypeInfo> getSubTypesOf(URL url, TypeInfo superTypeToLookFor)
    {
       if (url == null)
          throw new IllegalArgumentException("Null url");
@@ -123,14 +123,27 @@
       return result == null || result.isEmpty() ? Collections.<TypeInfo>emptySet() : Collections.unmodifiableSet(result);
    }
 
-   public Set<TypeInfo> getInheritedClasses(URL url, Class<?> superTypeToLookFor)
+   public Set<TypeInfo> getSubTypesOf(URL url, Class<?> superTypeToLookFor)
    {
       if (tif == null) // we haven't cached anything yet
          return Collections.emptySet();
 
-      return getInheritedClasses(url, tif.getTypeInfo(superTypeToLookFor));
+      return getSubTypesOf(url, tif.getTypeInfo(superTypeToLookFor));
    }
 
+   @SuppressWarnings({"unchecked", "deprecation"})
+   public <T> Set<Class<? extends T>> getSubClassesOf(URL url, Class<T> superTypeToLookFor)
+   {
+      Set<TypeInfo> classes = getSubTypesOf(url, superTypeToLookFor);
+      Set<Class<? extends T>> result = new HashSet<Class<? extends T>>();
+      for (TypeInfo ti : classes)
+      {
+         Class<?> clazz = ti.getType();
+         result.add((Class<T>)clazz);
+      }
+      return result;
+   }
+
    static String fixPath(String path)
    {
       if (path.endsWith("/") == false)

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -36,20 +36,29 @@
 public interface HierarchyIndex
 {
    /**
-    * Get inherited classes.
+    * Get inherited types.
     *
     * @param url the classpath entry path
     * @param superTypeToLookFor the super type to inherit
     * @return set of matching inherited classes
     */
-   Set<TypeInfo> getInheritedClasses(URL url, TypeInfo superTypeToLookFor);
+   Set<TypeInfo> getSubTypesOf(URL url, TypeInfo superTypeToLookFor);
 
    /**
-    * Get inherited classes.
+    * Get inherited types.
     *
     * @param url the classpath entry path
     * @param superTypeToLookFor the super type to inherit
     * @return set of matching inherited classes
     */
-   Set<TypeInfo> getInheritedClasses(URL url, Class<?> superTypeToLookFor);
+   Set<TypeInfo> getSubTypesOf(URL url, Class<?> superTypeToLookFor);
+
+   /**
+    * Get sub classes.
+    *
+    * @param url the classpath entry path
+    * @param superTypeToLookFor the super type
+    * @return set of sub types
+    */
+   <T> Set<Class<? extends T>> getSubClassesOf(URL url, Class<T> superTypeToLookFor);
 }

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -28,7 +28,6 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import org.jboss.reflect.spi.TypeInfo;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
 import org.jboss.scanning.annotations.spi.Element;
 import org.jboss.scanning.hierarchy.spi.HierarchyIndex;
@@ -73,17 +72,14 @@
    }
 
    @SuppressWarnings("deprecation")
-   public Set<Class<?>> getInheritedClasses(VirtualFile cpEntry, Class<?> superTypeToLookFor)
+   public <T> Set<Class<? extends T>> getInheritedClasses(VirtualFile cpEntry, Class<T> superTypeToLookFor)
    {
       if (cpEntry == null)
          throw new IllegalArgumentException("Null cp entry");
       if (superTypeToLookFor == null)
          throw new IllegalArgumentException("Null super type");
 
-      Set<Class<?>> result = new HashSet<Class<?>>();
-      for (TypeInfo ti : hierarchy.getInheritedClasses(toURL(cpEntry), superTypeToLookFor))
-         result.add(ti.getType());
-      return result;
+      return hierarchy.getSubClassesOf(toURL(cpEntry), superTypeToLookFor);
    }
 
    protected static URL toURL(VirtualFile file)

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -50,5 +50,5 @@
     * @param superTypeToLookFor the super type to inherit
     * @return set of matching inherited classes
     */
-   Set<Class<?>> getInheritedClasses(VirtualFile cpEntry, Class<?> superTypeToLookFor);
+   <T> Set<Class<? extends T>> getInheritedClasses(VirtualFile cpEntry, Class<T> superTypeToLookFor);
 }

Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -140,7 +140,7 @@
    {
       HierarchyIndex index = getIndex(unit);
       Class<?> superType = unit.getClassLoader().loadClass(ref.getName());
-      return index.getInheritedClasses(cpEntry.toURL(), superType);
+      return index.getSubTypesOf(cpEntry.toURL(), superType);
    }
 
    protected VirtualFile createTopLevelWithUtil() throws Exception

Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeHierarchyTestCase.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeHierarchyTestCase.java	2010-05-10 10:03:15 UTC (rev 104604)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/indexer/test/IndexerRuntimeHierarchyTestCase.java	2010-05-10 11:38:47 UTC (rev 104605)
@@ -87,7 +87,7 @@
       {
          HierarchyIndex index = unit.getAttachment(HierarchyIndex.class);
          Class<?> clazz = unit.getClassLoader().loadClass("com.alesj.foobar.FooBar");
-         Set<TypeInfo> classes = index.getInheritedClasses(url, clazz);
+         Set<TypeInfo> classes = index.getSubTypesOf(url, clazz);
          assertNotNull(classes);
          assertEquals(2, classes.size());
       }




More information about the jboss-cvs-commits mailing list