diff --git a/core/src/main/java/org/jboss/jandex/EmptyIndex.java b/core/src/main/java/org/jboss/jandex/EmptyIndex.java new file mode 100644 index 00000000..55fa0b22 --- /dev/null +++ b/core/src/main/java/org/jboss/jandex/EmptyIndex.java @@ -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 { + static final EmptyIndex INSTANCE = new EmptyIndex(); + + private EmptyIndex() { + } + + @Override + public Collection getKnownClasses() { + return Collections.emptySet(); + } + + @Override + public ClassInfo getClassByName(DotName className) { + return null; + } + + @Override + public Collection getKnownDirectSubclasses(DotName className) { + return Collections.emptySet(); + } + + @Override + public Collection getAllKnownSubclasses(DotName className) { + return Collections.emptySet(); + } + + @Override + public Collection getKnownDirectSubinterfaces(DotName interfaceName) { + return Collections.emptySet(); + } + + @Override + public Collection getAllKnownSubinterfaces(DotName interfaceName) { + return Collections.emptySet(); + } + + @Override + public Collection getKnownDirectImplementors(DotName interfaceName) { + return Collections.emptySet(); + } + + @Override + public Collection getAllKnownImplementors(DotName interfaceName) { + return Collections.emptySet(); + } + + @Override + public Collection getAnnotations(DotName annotationName) { + return Collections.emptySet(); + } + + @Override + public Collection getAnnotationsWithRepeatable(DotName annotationName, IndexView index) { + return Collections.emptySet(); + } + + @Override + public Collection getKnownModules() { + return Collections.emptySet(); + } + + @Override + public ModuleInfo getModuleByName(DotName moduleName) { + return null; + } + + @Override + public Collection getKnownUsers(DotName className) { + return Collections.emptySet(); + } + + @Override + public Collection getClassesInPackage(DotName packageName) { + return Collections.emptySet(); + } + + @Override + public Set getSubpackages(DotName packageName) { + return Collections.emptySet(); + } +} diff --git a/core/src/main/java/org/jboss/jandex/IndexView.java b/core/src/main/java/org/jboss/jandex/IndexView.java index 80ac9e0f..3144cc6e 100644 --- a/core/src/main/java/org/jboss/jandex/IndexView.java +++ b/core/src/main/java/org/jboss/jandex/IndexView.java @@ -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).