Skip to content

Commit

Permalink
Merge pull request #346 from Ladicek/empty-stacked-index
Browse files Browse the repository at this point in the history
Add empty and stacked indexes
  • Loading branch information
Ladicek authored May 13, 2024
2 parents ab584f3 + 772a528 commit 5a892b0
Show file tree
Hide file tree
Showing 8 changed files with 1,002 additions and 24 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jboss/jandex/CompositeIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ public Collection<ClassInfo> getAllKnownSubinterfaces(DotName interfaceName) {
* {@inheritDoc}
*/
@Override
public Collection<ClassInfo> getKnownDirectImplementors(final DotName className) {
public Collection<ClassInfo> getKnownDirectImplementors(final DotName interfaceName) {
final Set<ClassInfo> allKnown = new HashSet<ClassInfo>();
for (IndexView index : indexes) {
final Collection<ClassInfo> list = index.getKnownDirectImplementors(className);
final Collection<ClassInfo> list = index.getKnownDirectImplementors(interfaceName);
if (list != null) {
allKnown.addAll(list);
}
Expand Down
93 changes: 93 additions & 0 deletions core/src/main/java/org/jboss/jandex/EmptyIndex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.jboss.jandex;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
* Immutable empty index; that is, an index that doesn't contain any class. All methods return either
* an empty collection, or {@code null}.
*
* @since 3.2.0
*/
public final class EmptyIndex implements IndexView {
public static final EmptyIndex INSTANCE = new EmptyIndex();

private EmptyIndex() {
}

@Override
public Collection<ClassInfo> getKnownClasses() {
return Collections.emptySet();
}

@Override
public ClassInfo getClassByName(DotName className) {
return null;
}

@Override
public Collection<ClassInfo> getKnownDirectSubclasses(DotName className) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getAllKnownSubclasses(DotName className) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getKnownDirectSubinterfaces(DotName interfaceName) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getAllKnownSubinterfaces(DotName interfaceName) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getKnownDirectImplementors(DotName interfaceName) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getAllKnownImplementors(DotName interfaceName) {
return Collections.emptySet();
}

@Override
public Collection<AnnotationInstance> getAnnotations(DotName annotationName) {
return Collections.emptySet();
}

@Override
public Collection<AnnotationInstance> getAnnotationsWithRepeatable(DotName annotationName, IndexView index) {
return Collections.emptySet();
}

@Override
public Collection<ModuleInfo> getKnownModules() {
return Collections.emptySet();
}

@Override
public ModuleInfo getModuleByName(DotName moduleName) {
return null;
}

@Override
public Collection<ClassInfo> getKnownUsers(DotName className) {
return Collections.emptySet();
}

@Override
public Collection<ClassInfo> getClassesInPackage(DotName packageName) {
return Collections.emptySet();
}

@Override
public Set<DotName> getSubpackages(DotName packageName) {
return Collections.emptySet();
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jboss/jandex/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ public Collection<ClassInfo> getAllKnownSubinterfaces(DotName interfaceName) {
* {@inheritDoc}
*/
@Override
public List<ClassInfo> getKnownDirectImplementors(DotName className) {
ClassInfo[] list = implementors.get(className);
public List<ClassInfo> getKnownDirectImplementors(DotName interfaceName) {
ClassInfo[] list = implementors.get(interfaceName);
return list == null ? EMPTY_CLASSINFO_LIST : new ImmutableArrayList<>(list);
}

Expand Down
55 changes: 35 additions & 20 deletions core/src/main/java/org/jboss/jandex/IndexView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
* @author Steve Ebersole
*/
public interface IndexView {
/**
* Returns an immutable empty index; that is, an index that doesn't contain any class.
* All methods return either an empty collection, or {@code null}.
*
* @since 3.2.0
*/
static IndexView empty() {
return EmptyIndex.INSTANCE;
}

/**
* Gets all known classes by this index (those which were scanned).
Expand Down Expand Up @@ -77,6 +86,8 @@ default ClassInfo getClassByName(Class<?> clazz) {
* <p>
* Note that this will only pick up direct subclasses of the class. It will not
* pick up subclasses of subclasses.
* <p>
* Also note that interfaces are considered direct subclasses of {@code java.lang.Object}.
*
* @param className the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
Expand All @@ -93,6 +104,8 @@ default ClassInfo getClassByName(Class<?> clazz) {
* <p>
* Note that this will only pick up direct subclasses of the class. It will not
* pick up subclasses of subclasses.
* <p>
* Also note that interfaces are considered direct subclasses of {@code java.lang.Object}.
*
* @param className the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
Expand All @@ -111,6 +124,8 @@ default Collection<ClassInfo> getKnownDirectSubclasses(String className) {
* <p>
* Note that this will only pick up direct subclasses of the class. It will not
* pick up subclasses of subclasses.
* <p>
* Also note that interfaces are considered direct subclasses of {@code java.lang.Object}.
*
* @param clazz the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
Expand Down Expand Up @@ -200,19 +215,19 @@ default Collection<ClassInfo> getKnownDirectSubinterfaces(String interfaceName)
* Note that this will only pick up direct subinterfaces of the interface. It will not
* pick up subinterfaces of subinterfaces.
*
* @param iface the super interface of the desired subinterfaces
* @return a non-null list of all known subinterfaces of iface
* @param interfaceClass the super interface of the desired subinterfaces
* @return a non-null list of all known subinterfaces of interfaceClass
* @since 3.0
*/
default Collection<ClassInfo> getKnownDirectSubinterfaces(Class<?> iface) {
return getKnownDirectSubinterfaces(DotName.createSimple(iface.getName()));
default Collection<ClassInfo> getKnownDirectSubinterfaces(Class<?> interfaceClass) {
return getKnownDirectSubinterfaces(DotName.createSimple(interfaceClass.getName()));
}

/**
* Returns all known interfaces that extend the given interface, directly and indirectly.
* I.e., returns every interface in the index that is assignable to the given interface.
*
* @param interfaceName The interace
* @param interfaceName The interface
* @return all known subinterfaces
* @since 3.0
*/
Expand All @@ -222,7 +237,7 @@ default Collection<ClassInfo> getKnownDirectSubinterfaces(Class<?> iface) {
* Returns all known interfaces that extend the given interface, directly and indirectly.
* I.e., returns every interface in the index that is assignable to the given interface.
*
* @param interfaceName The interace
* @param interfaceName The interface
* @return all known subinterfaces
* @since 3.0
*/
Expand All @@ -234,12 +249,12 @@ default Collection<ClassInfo> getAllKnownSubinterfaces(String interfaceName) {
* Returns all known interfaces that extend the given interface, directly and indirectly.
* I.e., returns every interface in the index that is assignable to the given interface.
*
* @param iface The interace
* @param interfaceClass The interface
* @return all known subinterfaces
* @since 3.0
*/
default Collection<ClassInfo> getAllKnownSubinterfaces(Class<?> iface) {
return getAllKnownSubinterfaces(DotName.createSimple(iface.getName()));
default Collection<ClassInfo> getAllKnownSubinterfaces(Class<?> interfaceClass) {
return getAllKnownSubinterfaces(DotName.createSimple(interfaceClass.getName()));
}

/**
Expand All @@ -256,10 +271,10 @@ default Collection<ClassInfo> getAllKnownSubinterfaces(Class<?> iface) {
* Note that this will only pick up classes that directly implement given interface.
* It will not pick up classes implementing subinterfaces.
*
* @param className the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
* @param interfaceName The interface
* @return All known direct implementors of the interface
*/
Collection<ClassInfo> getKnownDirectImplementors(DotName className);
Collection<ClassInfo> getKnownDirectImplementors(DotName interfaceName);

/**
* Gets all known direct implementors of the specified interface name. A known
Expand All @@ -275,11 +290,11 @@ default Collection<ClassInfo> getAllKnownSubinterfaces(Class<?> iface) {
* Note that this will only pick up classes that directly implement given interface.
* It will not pick up classes implementing subinterfaces.
*
* @param className the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
* @param interfaceName The interface
* @return All known direct implementors of the interface
*/
default Collection<ClassInfo> getKnownDirectImplementors(String className) {
return getKnownDirectImplementors(DotName.createSimple(className));
default Collection<ClassInfo> getKnownDirectImplementors(String interfaceName) {
return getKnownDirectImplementors(DotName.createSimple(interfaceName));
}

/**
Expand All @@ -296,11 +311,11 @@ default Collection<ClassInfo> getKnownDirectImplementors(String className) {
* Note that this will only pick up classes that directly implement given interface.
* It will not pick up classes implementing subinterfaces.
*
* @param clazz the super class of the desired subclasses
* @return a non-null list of all known subclasses of className
* @param interfaceClass The interface
* @return All known direct implementors of the interface
*/
default Collection<ClassInfo> getKnownDirectImplementors(Class<?> clazz) {
return getKnownDirectImplementors(DotName.createSimple(clazz.getName()));
default Collection<ClassInfo> getKnownDirectImplementors(Class<?> interfaceClass) {
return getKnownDirectImplementors(DotName.createSimple(interfaceClass.getName()));
}

/**
Expand Down
Loading

0 comments on commit 5a892b0

Please sign in to comment.